This is a Node-Red example of reading Temperature from a Temco T3-8o Expansion i/o using Raspberry Pi Compute Module 3+.
In order to create or use this flow node-red-contrib-modbus must be installed.
The flow looks like this;
In order to change the values for any of the Nodes just double-click on the node.
The Inject node can be configured to retrieve the Temperature on an interval by setting the Repeat Value to ‘Interval’ and setting the duration between checks. To enable it to retrieve the value only when the Inject button (on the left) is selected - set interval to none and select either Timestamp, String or Number and leave the value empty.
The code for the first Function node is as follows;
msg.payload = {
‘fc’: 3,
‘unitid’: 254,
‘address’: 116 ,
‘quantity’: 2
};
return msg;
The first value is for the ModBus Flex Getter Function Code - currently supported Codes are;
- FC 1: Read Coil Status
- FC 2: Read Input Status
- FC 3: Read Holding Registers
- FC 4: Read Input Registers
The ‘unitid’ is the Address ID of the Expansion I/O - this can currently only be changed using T3000 software.
The ‘address’ is the ‘RegAddress’ of the Register that you want to retrieve. In order to view the list of Register Addresses for your device use T3000 software Tools>Register Viewer.
The ‘quantity’ is the number of values to retrieve - Also seen in the Register Viewer ‘Reg_Length’.
The next Node is the ‘Modbus Flex Getter’ - this is where the connection to the device is configured.
In order to configure the connection for your device Click on the edit icon to the right of the Server name.
- Name is optional
- Type can be set to TCP or Serial (I will do another tutorial on Serial)
- Host is IP address of device
- Port - must be set to same value as Device - can be viewed/set using T3000>Configuration
- TCP Type - in this example Default works fine
- Unit-ID - should be left to 1, the actually value used is set in the Function Node code
- Timeout - default setting is 1000 (ms) - I changed this to 2000ms and deselected 'Reconnect on timeout which worked better.
The rest of the values are set to their defaults.
Next is another Function Node - the value retrieved from the device is the temperature in a 4 digit string, in order to convert it to the value with decimal point the Function simply takes that value and divides by 100.
msg.payload = (msg.values[1] / 100)
return msg;
The msg.values[1] - selects the second value in the array retrieves, this particular register has 2 values so we need to select the second value (first value would be msg.values[0].
Then finally the final debug node outputs the temperature value to the debug window of the Node-red GUI.
This flow can be downloaded from the included attachment.
modbus_read_temp.json (1.7 KB)