pjuzeliunas / nilan

Nilan (R) CTS700 Modbus controller
MIT License
3 stars 3 forks source link

Cannot read register value #1

Open wernerfred opened 2 years ago

wernerfred commented 2 years ago

Hey, 👋🏻

i got the following error, can you help me what what might be wrong?

2021/07/29 17:00:29 Processing readings GET request from 172.17.0.1:60214
2021/07/29 17:00:29 http: panic serving 172.17.0.1:60214: Cannot read register value
goroutine 24 [running]:
net/http.(*conn).serve.func1(0xc00017e140)
        /usr/local/go/src/net/http/server.go:1795 +0x139
panic(0x6e31a0, 0x7c2cb0)
        /usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/wernerfred/nilan.(*Controller).FetchValue(0xc0000cda48, 0xc0554fe604, 0xc0001b0000)
        /go/src/github.com/wernerfred/nilan/controller.go:41 +0x1f4
github.com/wernerfred/nilan.(*Controller).t18ReadingRegister(0xc0000cda48, 0x4f270001)
        /go/src/github.com/wernerfred/nilan/controller.go:304 +0x3b
github.com/wernerfred/nilan.(*Controller).FetchReadings(0xc0000cda48, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /go/src/github.com/wernerfred/nilan/controller.go:316 +0x95
main.readings(0x7cec40, 0xc0001ae0e0, 0xc000182400)
        /app/app/app.go:16 +0x10d
net/http.HandlerFunc.ServeHTTP(0x775a10, 0x7cec40, 0xc0001ae0e0, 0xc000182400)
        /usr/local/go/src/net/http/server.go:2036 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0000d4000, 0x7cec40, 0xc0001ae0e0, 0xc0001c4100)
        /go/src/github.com/gorilla/mux/mux.go:210 +0xe2
net/http.serverHandler.ServeHTTP(0xc0000d8000, 0x7cec40, 0xc0001ae0e0, 0xc0001c4100)
        /usr/local/go/src/net/http/server.go:2831 +0xa4
net/http.(*conn).serve(0xc00017e140, 0x7cf2c0, 0xc000184040)
        /usr/local/go/src/net/http/server.go:1919 +0x875
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2957 +0x384
pjuzeliunas commented 2 years ago

Hi @wernerfred

Thanks for the issue report and sorry for the delay.

It seems that you are getting the error due to failure in modbus TCP layer. Unfortunately, modbus errors are quite common in CTS700. You should ignore the error and retry. This is quite hard to do in version 1.0.0, because it lacks error handling in general.

I have introduced error handling in the new version of nilan (v. 1.1.0). The interface is slightly different, as FetchValue (and other functions) now returns a tuple consisting of a result and an error, if it occurs.

Sample usage:

value, err := controller.FetchValue(slaveID, register)
if err != nil {
    // handle error
}

So, the controller should return you an error if something goes wrong in modbus TCP layer.

pju-dawn commented 2 years ago

One more thing... If you are trying out nilan-rest-api: please provide NILAN_ADDRESS environment variable.

E.g.

NILAN_ADDRESS=192.168.1.31:502 ./nilanapp

Or if you are running in Docker:

docker run -e NILAN_ADDRESS=<IP and port of Nilan> -it --rm -p 8080:8080 nilan