mldavies
I have a Raspberry Pi running OpenPLC.
I have 2 ESP8266 Slaves
1. Two momentary switches (on and off) and an LED
2. A relay
I have a separate reaspberry pi running Node Red

My OpenPLC ST code is

PROGRAM My_First_Program
VAR
Relay1 AT %QX101.0 : BOOL;
PB1 AT %IX100.1 : BOOL;
PB2 AT %IX100.2 : BOOL;
LED AT %QX100.0 : BOOL;
END_VAR

LED := NOT(PB2) AND (PB1 OR Relay1);
Relay1 := NOT(PB2) AND (PB1 OR Relay1);
END_PROGRAM


CONFIGURATION Config0

RESOURCE Res0 ON PLC
TASK My_First_task(INTERVAL := T#50ms,PRIORITY := 0);
PROGRAM My_First_Instance WITH My_First_task : My_First_Program;
END_RESOURCE
END_CONFIGURATION

When I tap the 'on' momentary switch, the LED on slave 1 lights up and the relay on slave switches to 'on'.
When I tap the 'off' momentary switch, the LED on slave 1 goes off and the relay on slave 2 switches to 'off'

This is the expected behaviour

I have an OpenPLC instance created in Node-Red (on a separate Raspberry Pi) which is attempting to read the status of the LED. This does not work. The following is the OpenPLC log which shows a successful connection from Node-Red (Client ID 13) but also several errors.

I would be most grateful if anyone could offer assistance in helping me to understand this problem.

OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Device LED is disconnected. Attempting to reconnect...
Connected to MB device LED
Device Slave 2 is disconnected. Attempting to reconnect...
Connected to MB device Slave 2
Issued start_modbus() command to start on port: 502
Modbus Server: Listening on port 502
Modbus Server: waiting for new client...
Issued stop_dnp3() command
Modbus Server: Client accepted! Creating thread for the new client ID: 13...
Modbus Server: waiting for new client...
Modbus Server: Thread created for client ID: 13
Modbus Server: client ID: 13 has closed the connection
Terminating Modbus connections thread
Modbus Server: Client accepted! Creating thread for the new client ID: 13...
Modbus Server: waiting for new client...
Modbus Server: Thread created for client ID: 13
Modbus Write Coils failed on MB device LED: Connection timed out
Modbus Read Input Registers failed on MB device LED: Bad file descriptor
Modbus Write Holding Registers failed on MB device LED: Bad file descriptor
Device LED is disconnected. Attempting to reconnect...
Connected to MB device LED
Modbus Write Coils failed on MB device LED: Connection timed out
Modbus Read Input Registers failed on MB device LED: Bad file descriptor
Modbus Write Holding Registers failed on MB device LED: Bad file descriptor
Device LED is disconnected. Attempting to reconnect...
Connected to MB device LED
Reply 0 0
thiagoralves
It is more likely that that everything is working as expected, but you’re using the wrong address on your node-red application. What coil address are you using on node-red?
Reply 0 0
mldavies
Thanks for your help Thiago

Node red details are:
FC 1 Read Coil Status
Address 100
Size 8
Poll rate 50ms

Server details for node red
Type: TCP (Other options are serial and serial expert)
TCP Type: DEFAULT (Although I'm not sure what default is. The other optiosn are: RTU buffered, Telnet and C701)
Timeout: 1000ms (Is this long enough?)
Reconnect timeout: 2000ms
Reply 0 0
thiagoralves
Address should be 800 for coil at %QX100.0. If you look at the Modbus table in openplcproject.com/scada you would notice that coils grow from %QX0.0 to %QX0.7, and then %QX1.0, %QX1.1, etc, which means that Modbus addresses are multiplied by 8 to match the %QX addresses.
Reply 0 0
mldavies
Ah. I hadn't picked that up. Yes, it works fine now. Thank you again for your help.
Reply 0 0
Reply