We want Modbus TCP Request and Response in stream Mode.
The sample code https://labjack.com/support/software/examples/modbus/c is sending the streamed data periodically.
We want the steps for Modbus TCP Request and Response in stream Mode or please provide sampple code.
Regards,
Siva Prasad Munnaluri
It is recommended to use our LJM library to use stream mode, which is installed by our software installers. It will handle the Modbus command and response packets, and make things easier. In our code examples for various languages, there is a Examples\More\Stream directory with stream examples:
https://labjack.com/support/software/examples/ljm
General stream mode documentation is here:
https://labjack.com/support/datasheets/t-series/communication/stream-mode
If you cannot use the LJM library and need to stream, we have the low-level Modbus TCP example you linked to. That is the only example demonstrating low-level Modbus TCP command and response usage. It uses spontaneous mode streaming which is how to achieve the fastest sample rates. You can configure, start, and stop stream mode with standard Modbus functions, but to read spontaneous stream data you read the Modbus Feedback Spontaneous packet responses only with no command. Low-level stream mode documentation can be found here:
https://labjack.com/support/datasheets/t-series/communication/stream-mod...
Thanks for your quick response. We can not use LJM library as we are using our embeded device to connect to Labjack via Modbus TCP.
In the article https://labjack.com/support/datasheets/t-series/communication/stream-mod... the following points are mentioned, see orange color
1.STREAM_AUTO_TARGET
- Address: 4016
Controls where data will be sent. Value is a bitmask. bit 0: 1 = Send to Ethernet 702 sockets, bit 1: 1 = Send to USB, bit 4: 1 = Command-Response mode. All other bits are reserved.
2.Data Collection
Command-Response Stream: When collecting data using command-response stream mode, data must be read from STREAM_DATA_CR (address 4500). Data is automatically discarded as it is read.
Modbus Feedback Command-Response Packet Protocol:
Bytes 0-1: Transaction ID
Bytes 2-3: Protocol ID
Bytes 4-5: Length, MSB-LSB ...
Based on the above, we understood that if we write bit 4:1 at 4016, the device will be in Command Response Stream mode. Once we send request to read data at 4500, it will respond back the entire data. This is the behaviour we want as our embedded device can not read modbus feedback spontaneous packet with out sending command. Hope our understading is correct?
We are looking for the exact steps or sample code to achive this functionality.
It sounds like you are on the right track. When you read from the 4500 register you need to use the readMultiple Modbus function (0x04). A minimum of eight registers are needed to get all the header information each register beyond that will return one 16-bit binary sample. So reading 12 registers will return the header and four data points.
Thanks for your response. Please provide details steps or sample code for Modbus TCP Request and Response in stream Mode similar to the example provided for streamed data periodically( https://labjack.com/support/software/examples/modbus/c)
Thanks for your response.
We did the below steps and getting following error.
1. Wrote value 16 at 4016 register
2. Read the values from 4500 and getting error 163
163
Illegal Data Value exception response
Signals that a Illegal Value exception response was (code 03) received. This exception response is sent by a slave device instead of a normal response message if a master sent a data value, which is not an allowable value for the slave device.
We are looking for the exact steps or sample code to achive this functionality.
Try setting the STREAM_BUFFER_SIZE_BYTES (address 4012) to 4096 before starting stream.
Thanks for your response. Now the values are coming but unable to corelate the values. Please provide a working example for Modbus TCP Request and Response in stream Mode similar to the example provided for streamed data periodically( https://labjack.com/support/software/examples/modbus/c)
We will be finalizing the Labjack device once we are able to corelate the values.
There will be some time before we can look into updating the example for this.
I will point out the current example demonstrates parsing out data and converting it to analog inputs. It displays the readings and what scan they are. Command-response and spontaneous stream mode have the same response in regards to data (bytes 8 and 9 differ), so most of the code is the current example's stream read loop will be the same for both stream modes. I say most as the spontaneousStreamRead function call will need to be a command-response version.
Samples are in interleaved. For example from the first data response, raw samples, if you were streaming two channels:
bytes 16 and 17: Scan 0, channel 0 sample
bytes 18 and 19: Scan 0, channel 1 sample
bytes 20 and 21: Scan 1, channel 0 sample
bytes 22 and 23: Scan 1, channel 1 sample
bytes 24 and 25: Scan 2, channel 0 sample
bytes 26 and 27: Scan 2, channel 1 sample
etc.