Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel W. Crompton committed Oct 18, 2018
1 parent ab0079a commit 2270005
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7
1.9
11 changes: 7 additions & 4 deletions modbusserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2270005

Please sign in to comment.