-
Notifications
You must be signed in to change notification settings - Fork 146
Description
I am willing to put a handler on my Modbus connection and everything was going fine until the moment I tried to implement server customization as it's written in the documentation.
import (
"errors"
"fmt"
"time"
"github.com/goburrow/serial"
. "github.com/tbrandon/mbserver"
)
var server *Server
func ModbusInit() {
server = NewServer()
server.RegisterFunctionHandler(2,
func(s *Server, frame Framer) ([]byte, *Exception) {
register, numRegs, endRegister := frame.registerAddressAndNumber()
// Check the request is within the allocated memory
if endRegister > 65535 {
return []byte{}, &IllegalDataAddress
}
dataSize := numRegs / 8
if (numRegs % 8) != 0 {
dataSize++
}
data := make([]byte, 1+dataSize)
data[0] = byte(dataSize)
for i := range s.DiscreteInputs[register:endRegister] {
// Return all 1s, regardless of the value in the DiscreteInputs array.
shift := uint(i) % 8
data[1+i/8] |= byte(1 << shift)
}
return data, &Success
})
}
And when I'm trying to build it with my script:
#!/bin/bash
export GOPATH=pwd
go get github.com/tbrandon/mbserver
go get github.com/goburrow/serial
go build modbus.go
It appears with a message(the one and the only):
frame.registerAddressAndNumber undefined (type mbserver.Framer has no field or method registerAddressAndNumber)
This comes from the fact that registerAddressAndNumber(frame Framer) is a private function and we can't call it from outside of the package. And how do we deal with that if by documentation we are meant to call it from another package? Was it actually meant to be a private function? Do we need to override all structures and functions from that package to make it work as it was meant to work?
Hope there is a way of correctly implementing a customized server without changing function privacy status by ourselves something like this.