I have an industrial sensor which is connected to a Interface Module that provides information to the end user via telnet
.
Port: 10001
Data Format: Little-Endian
Preamble - 32 bit
Article number - 32 bit
Serial number - 32 bit
Channels - 64 bit
Status - 32 bit
Frame number M / - 16 bit/ 16 bit
bytes per frame
Measuring value counter - 32 bit
Measuring value frame 1 - N * 32 bit
..
..
This should be available after the TCP headers (if I understand correctly) i.e. Payload.
I am trying to learn golang with more practical examples and I am thinking in the following direction:
preamble
, article number
etc. as a beginners taskI have gone through some blog-posts about TCP server/client creations but they only address string
in their payload. How can I extract such a byte orientated custom payload as mentioned above?
I can understand that this can be achieved in python probably via struct.pack
and struct.unpack
hence some correlation as understanding would be appreciated
In section 6.2 of your linked pdf document above there is a table listing the data you seem to list in the question
I would convert that table into a struct and then read into it with the encoding/binary module. See https://golang.org/pkg/encoding/binary/#example_Read for a relevant example
"All measuring values are transmitted as Int32, Uint32 or Float depending on the connected sensor" probably easiest to get them as uint32 and then convert them later