Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server customization issue #10

Open
tynrol opened this issue Jun 4, 2021 · 2 comments
Open

Server customization issue #10

tynrol opened this issue Jun 4, 2021 · 2 comments

Comments

@tynrol
Copy link

tynrol commented Jun 4, 2021

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.

@incase
Copy link

incase commented Jul 12, 2022

frame.registerAddressAndNumber() is an unexported function of the mbserver package. As such, the customization section of the docs is wrong - you can't use that function outside the mbserver package.

It gets worse: The Framer interface (which you'd receive as frame in your func) doesn't contain that function.

@tynrol
Copy link
Author

tynrol commented Jul 14, 2022

I think its pretty clear by now that the project is no longer supported. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants