Skip to content

Modbus IO's from CSV Exports

Klaus Landsdorf edited this page Aug 1, 2022 · 26 revisions

Basics

Overview Loom video

Modbus IO works with CSV converts from Codesys CSV exports:

By addressing the registers and using the names IO helps with large Modbus registers to check the register's place and name.
Modebus-response-filter node:

image

In our example here, variable "bOperationActive" is expected to be in register 37. If the register number of "bOperationActive" changes after a new convert of CSV your export to JSON, then it may not be in that register anymore. The node will fail and inform you about that mistake.

image

IO CSV convert to JSON

Before you can make use of this feature you need to create a JSON file from the CSV file you got from CODESYS:

image

You can find this flow in the Node-red flow examples. It takes an input CSV file and converts it to a JSON representation.

We want to get the variable name as name and the register name as valueAddress.

image

Maybe you have to make a small change to the "Filter named Register" node to make it work for you CSV output:

if(msg.payload.col2 !== undefined && msg.payload.col2.indexOf('//') === -1) {
    var varName = msg.payload.col2;
    var varAddress = msg.payload.col3;
    msg.payload = { 'name': varName, 'valueAddress': varAddress };
    return msg;
}

This basically converts this:

Outputs;Modbus Input Registers;%QD30001;SDM 630 v2
Outputs[30001];fPhaseLine1NeutralVolts;%QD30001;SDM 630 v2
Outputs[30003];fPhaseLine2NeutralVolts;%QD30003;SDM 630 v2
Outputs[30005];fPhaseLine3NeutralVolts;%QD30005;SDM 630 v2
Outputs[30007];fPhase1Current;%QD30007;SDM 630 v2
Outputs[30009];fPhase2Current;%QD30009;SDM 630 v2
Outputs[30011];fPhase3Current;%QD30011;SDM 630 v2

to this:

{"name":"fPhaseLine1NeutralVolts","valueAddress":"%QD30001"}
{"name":"fPhaseLine2NeutralVolts","valueAddress":"%QD30003"}
{"name":"fPhaseLine3NeutralVolts","valueAddress":"%QD30005"}
{"name":"fPhase1Current","valueAddress":"%QD30007"}
{"name":"fPhase2Current","valueAddress":"%QD30009"}
{"name":"fPhase3Current","valueAddress":"%QD30011"}

IO Registers from CSV/JSON

image

IO Config

image

The file location is based on a Windows system. When running Node-red in a docker image you might want to put the sdm630.CSV and JSON files in a folder like /usr/src/node-red ore something.

The IO-Config calcualtes the offsets from the variable prefixes like this:

{"payload":[
{"register":"MB-OUTPUTS","name":"fPhaseLine1NeutralVolts","addressStart":30001,"addressOffset":2,"addressOffsetIO":0,"addressStartIO":30001,"registerAddress":30001,"coilStart":0,"bitAddress":null,"Bit":0,"bits":32,"dataType":"Float","type":"output"},
{"register":"MB-OUTPUTS","name":"fPhaseLine2NeutralVolts","addressStart":30003,"addressOffset":2,"addressOffsetIO":0,"addressStartIO":30003,"registerAddress":30003,"coilStart":0,"bitAddress":null,"Bit":0,"bits":32,"dataType":"Float","type":"output"},
{"register":"MB-OUTPUTS","name":"fPhaseLine3NeutralVolts","addressStart":30005,"addressOffset":2,"addressOffsetIO":0,"addressStartIO":30005,"registerAddress":30005,"coilStart":0,"bitAddress":null,"Bit":0,"bits":32,"dataType":"Float","type":"output"},
{"register":"MB-OUTPUTS","name":"fPhase1Current","addressStart":30007,"addressOffset":2,"addressOffsetIO":0,"addressStartIO":30007,"registerAddress":30007,"coilStart":0,"bitAddress":null,"Bit":0,"bits":32,"dataType":"Float","type":"output...
]

Flow example

image
You can find this flow in the Node-red flow examples, but I'm afraid it's not working anymore.