From 2270005543a7e7d1c7e6d4dbe7e5b12b34e9be06 Mon Sep 17 00:00:00 2001 From: "Daniel W. Crompton" Date: Thu, 18 Oct 2018 13:14:54 +0000 Subject: [PATCH] Bug fix --- Makefile | 2 ++ VERSION | 2 +- modbusserver.go | 11 +++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 939791b..7bb9753 100644 --- a/Makefile +++ b/Makefile @@ -24,3 +24,5 @@ bump: upload: scp ${PROGNAME}-`cat VERSION`.tar.bz2 oplerno:/var/lib/lxd/containers/ateps-updates/rootfs/var/www/portage/distfiles/ +windows: + GOOS=windows GOARCH=386 go build diff --git a/VERSION b/VERSION index d3bdbdf..2e0e38c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7 +1.9 diff --git a/modbusserver.go b/modbusserver.go index 68a7fa7..80d7e31 100644 --- a/modbusserver.go +++ b/modbusserver.go @@ -62,12 +62,15 @@ func ReadRegisters(s *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver if (numRegs % 8) != 0 { dataSize++ } + dataSize = dataSize*2 data := make([]byte, 1+dataSize) data[0] = byte(dataSize) - for i := range s.DiscreteInputs[register:endRegister] { + fmt.Println(len(data)) + for i, value := range s.HoldingRegisters[register:endRegister] { // Return all 1s, regardless of the value in the DiscreteInputs array. - shift := uint(i) % 8 - data[1+i/8] |= byte(1 << shift) + fmt.Println(i) + data[i+1] = byte(int(value / 256)) + data[i+2] = byte(value % 256) } fmt.Println("READ: ", data) return data, &mbserver.Success @@ -85,7 +88,7 @@ func WriteRegisters(s *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserve data[1] = byte(register % 256) data[2] = byte(int(value / 256)) data[3] = byte(value % 256) - + s.HoldingRegisters[register] = value fmt.Println("WRITE: ", data) return data, &mbserver.Success