From 76be5bcd2c782c643347889b8660cbe92c793571 Mon Sep 17 00:00:00 2001 From: Javier Peletier Date: Wed, 16 Dec 2020 00:53:13 +0100 Subject: [PATCH] complete modbus mock --- modbus/mock.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modbus/mock.go b/modbus/mock.go index 5d516b6..21c38c5 100644 --- a/modbus/mock.go +++ b/modbus/mock.go @@ -12,8 +12,8 @@ type Mock struct { func NewMock() Modbus { return &Mock{ State: map[byte][]uint16{ - 49: {3, 68, 41, 41, 3, 68, 41, 41, 3, 68, 41, 45, 3, 68, 41, 45, 3, 68, 41, 42, 3, 52, 41, 40, 3, 52, 41, 44, 3, 68, 41, 41, 3, 68, 41, 40, 3, 68, 41, 41, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0}, - 50: {3, 68, 41, 41, 3, 68, 41, 41, 3, 68, 41, 45, 3, 68, 41, 45, 3, 68, 41, 42, 3, 52, 41, 40, 3, 52, 41, 44, 3, 68, 41, 41, 3, 68, 41, 40, 3, 68, 41, 41, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0}, + 49: {3, 68, 41, 41, 3, 68, 41, 41, 3, 68, 41, 45, 3, 68, 41, 45, 3, 68, 41, 42, 3, 52, 41, 40, 3, 52, 41, 44, 3, 68, 41, 41, 3, 68, 41, 40, 3, 68, 41, 41, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 3, 4, 2, 49, 3, 7, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + 50: {3, 68, 41, 41, 3, 68, 41, 41, 3, 68, 41, 45, 3, 68, 41, 45, 3, 68, 41, 42, 3, 52, 41, 40, 3, 52, 41, 44, 3, 68, 41, 41, 3, 68, 41, 40, 3, 68, 41, 41, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 3, 4, 2, 49, 3, 7, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }, } } @@ -23,6 +23,7 @@ func (ms *Mock) ReadRegister(slaveID byte, address uint16, quantity uint16) (res if !ok { return nil, errors.New("Unknown slave") } + address-- for a := address; a < address+quantity; a++ { b := make([]byte, 2) binary.BigEndian.PutUint16(b, state[a]) @@ -35,7 +36,7 @@ func (ms *Mock) WriteRegister(slaveID byte, address uint16, value uint16) (resul if !ok { return nil, errors.New("Unknown slave") } - state[address] = value + state[address-1] = value results = make([]byte, 2) binary.BigEndian.PutUint16(results, value) return results, nil