kain5266
I am using modbus master RTU configuration on raspberry pi to control arduino I/O and possibly other devices over rs485.
I use USB-485 adapter on raspberry.
The problem is that I get an error in OpenPLC log:

Connected to MB device arduinouno
Modbus Read Discrete Input Registers failed on MB device arduinouno: Bad file descriptor 

I am able to read and write to arduino using modbus master simulator on PC.
Is the any way to solve this?
Help would be much appreciated!
Great project!
Quote 1 0
thiagoralves
Have you tried to connect the Arduino board directly to the USB port of the Pi without the 485 adapter? What is your modbus.cfg file?
Quote 0 0
kain5266
Num_Devices = "1"

# ------------
#
DEVICE 0
# ------------
device0.name = "arduinouno"

device0.protocol = "RTU"

device0.slave_id = "1"

device0.address = "/dev/ttyUSB0"

device0.IP_Port = ""

device0.RTU_Baud_Rate = "9600
"
device0.RTU_Parity = "N"

device0.RTU_Data_Bits = "8"

device0.RTU_Stop_Bits = "1"

device0.Discrete_Inputs_Start = "0"

device0.Discrete_Inputs_Size = "8"

device0.Coils_Start = "0"

device0.Coils_Size = "8"

device0.Input_Registers_Start = "0"

device0.Input_Registers_Size = "2"

device0.Holding_Registers_Start = "0"

device0.Holding_Registers_Size = "2"

This is the cfg file.
I managed to get it connect with a different library for arduino, but Openplc software still doesn't read I/O from arduino.
Connecting arduino directly to USB port of rpi works with arduino driver for openplc, but i want to control it using modbus rtu.
Quote 0 0
thiagoralves
Connect it directly to the USB port but use the modbus driver. Just make sure that your Arduino board is really at /dev/ttyUSB0. If it is not, change your modbus.cfg file accordingly. This will make OpenPLC talk to the Arduino board using the Modbus RTU driver. Obviously you will have to load the Modbus slave sketch on the arduino before.

Also, you may try to decrease the number of registers that you are reading from the arduino. Start with only one discrete input to test.
Quote 0 0
dreizys
Just the same problem...
config: (arduino Uno)
//____________________________________
Num_Devices = "1"
Polling_Period = "10000"
Timeout = "1000000"
# ------------
# DEVICE 0
# ------------
device0.name = "1"
device0.slave_id = "1"
device0.protocol = "RTU"
device0.address = "/dev/ttyUSB1"
device0.IP_Port = ""
device0.RTU_Baud_Rate = "115200"
device0.RTU_Parity = "None"
device0.RTU_Data_Bits = "8"
device0.RTU_Stop_Bits = "1"

device0.Discrete_Inputs_Start = "0"
device0.Discrete_Inputs_Size = "1"
device0.Coils_Start = "0"
device0.Coils_Size = "1"
device0.Input_Registers_Start = "0"
device0.Input_Registers_Size = "0"
device0.Holding_Registers_Read_Start = "0"
device0.Holding_Registers_Read_Size = "0"
device0.Holding_Registers_Start = "0"
device0.Holding_Registers_Size = "0"  
______________________________________//_

while PLC starting i v`e got 

//_______________________________________________
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Modbus Read Discrete Input Registers failed on MB device 1: Bad file descriptor
Modbus Write Coils failed on MB device 1: Bad file descriptor
Warning: Persistent Storage file not found
Issued start_modbus() command to start on port: 502
Server: Listening on port 502
Server: waiting for new client...
Issued stop_dnp3() command
Issued stop_enip() command
Issued stop_pstorage() command

________________________________//


All my attempts to get something to run  were disappointing
Can anybody give me  a kick?
Quote 0 0
thiagoralves
It will be less disappointing when you stick to the instructions:  https://www.openplcproject.com/runtime/arduino/
😉
Quote 0 0
dreizys
Especially pleased by your reply. But what could be done wrong? I do not think it's something difficult to fulfill the instructions.
 i tested with the tcp modbus simulator (diagslave). It`s running. I received only one error message:
________________________________________________________________________________
Quote:

OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Modbus Read Discrete Input Registers failed on MB device mytcpDevice: Bad file descriptor
Modbus Write Coils failed on MB device mytcpDevice: Bad file descriptor
Modbus Read Input Registers failed on MB device mytcpDevice: Bad file descriptor
Modbus Read Holding Registers failed on MB device mytcpDevice: Bad file descriptor
Modbus Write Holding Registers failed on MB device mytcpDevice: Bad file descriptor
Warning: Persistent Storage file not found
Device mytcpDevice is disconnected. Attempting to reconnect...
Connected to MB device mytcpDevice
Issued stop_modbus() command
Issued stop_dnp3() command
Issued stop_enip() command
Issued stop_pstorage() command
_________________________________________
_____________
otherwise i can observe on the other side:
stant@stant-VPCSA2Z9R:~/source/diagslave/linux_x86-64$ sudo ./diagslave -m tcp
[sudo] password for stant:
diagslave 3.2 - FieldTalk(tm) Modbus(R) Diagnostic Slave Simulator
Copyright (c) 2002-2019 proconX Pty Ltd
Visit https://www.modbusdriver.com for Modbus libraries and tools.

Protocol configuration: MODBUS/TCP
Slave configuration: address = -1, master activity t/o = 3.00s
IP configuration: port = 502, connection t/o = 60.00s

Server started up successfully.
Listening to network (Ctrl-C to stop)

validateMasterIpAddr: accepting connection from 127.0.0.1
Slave 0: readInputDiscretes from 1, 8 references
Slave 0: writeCoils from 1, 8 references
Slave 0: readInputRegisters from 1, 8 references
Slave 0: readHoldingRegisters from 1, 8 references
Slave 0: writeHoldingRegisters from 1, 8 references
Slave 0: readInputDiscretes from 1, 8 references
Slave 0: writeCoils from 1, 8 references
Slave 0: readInputRegisters from 1, 8 references
Slave 0: readHoldingRegisters from 1, 8 references
Slave 0: writeHoldingRegisters from 1, 8 references
Slave 0: readInputDiscretes from 1, 8 references
Slave 0: writeCoils from 1, 8 references
Slave 0: readInputRegisters from 1, 8 references
Slave 0: readHoldingRegisters from 1, 8 references
Slave 0: writeHoldingRegisters from 1, 8 references
Slave 0: readInputDiscretes from 1, 8 references
Slave 0: writeCoils from 1, 8 references
Slave 0: readInputRegisters from 1, 8 references
Slave 0: readHoldingRegisters from 1, 8 references
Slave 0: writeHoldingRegisters from 1, 8 references
Slave 0: readInputDiscretes from 1, 8 references
______________________________________________
On the other hand i can test the arduino with the modbus master utility (modpoll)
and it is also successfull.
Is it possible that   the openplc runtime  have problems with  the serial port( in linux) permissions?


Quote 0 0
dreizys
it's charming : when i use two devices- tcp and rtu simultaneously --- it's everything oK
Really 
i tested it several times. And the tcp device should be the first!
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
OpenPLC Runtime starting...
Interactive Server: Listening on port 43628
Modbus Read Discrete Input Registers failed on MB device mytcpDevice: Bad file descriptor
Modbus Write Coils failed on MB device mytcpDevice: Bad file descriptor
Modbus Read Input Registers failed on MB device mytcpDevice: Bad file descriptor
Modbus Write Holding Registers failed on MB device mytcpDevice: Bad file descriptor
Device testUno is disconnected. Attempting to reconnect...
Warning: Persistent Storage file not found
Connected to MB device testUno
Device mytcpDevice is disconnected. Attempting to reconnect...
Connected to MB device mytcpDevice
Issued start_modbus() command to start on port: 504
Server: Listening on port 504
Server: waiting for new client...
Issued stop_dnp3() command
Issued stop_enip() command
Issued stop_pstorage() command
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Thank you for help
Quote 0 0
thiagoralves
I'm still trying to understand what you are struggling with. Are you using any custom firmware on the Arduino? If you use the firmware from the instructions I sent you, plus the pre-made Arduino configuration on the slave as mentioned on the instructions (no messing around with mbconfig.cfg, that's an old game) there is no way to go wrong. Now, if you're trying something custom, then there are many things that can go wrong.
Quote 0 0
dreizys
everything is done as described in the instruction. The fact is that   standalone arduino board with  RTU modbus connection is not working. If i  add it  to existing  line i.e. tcp device (custom) https://drive.google.com/file/d/1LdHtf5uhwHUEtexdLuaMGKsV90wgthB8/view?usp=sharing
then it starts to run. 
But never mind. I do not insist on finding out the reason, cause i`m satisfied with this result. Only wanted to help to the project development.
Quote 0 0
thiagoralves
This is weird because I have tested this a million times and it always worked. What is your host system running OpenPLC?
Quote 0 0
dreizys
DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"
04.08.2020, 15:10, "OpenPLC Forum" <noresponse@discussion.community>:
Quote 0 0
air
Hi. I have problem Modbus RTU OpenPLC with RS-485.
  1. All work with direct USB connect between RPi OpenPLC and Uno OpenPLC, but not work with different RS-485 converters.
  2. QModBus normally read and write with and without RS-485 converters.
Infotmation attached on Google Drive folder.
Thank you in advance!
Quote 0 0
air
mbconfig.cfg
Num_Devices = "1"
Polling_Period = "500"
Timeout = "5000"
# ------------
#   DEVICE 0
# ------------
device0.name = "uno2"
device0.slave_id = "1"
device0.protocol = "RTU"
device0.address = "/dev/ttyUSB0"
device0.IP_Port = ""
device0.RTU_Baud_Rate = "1200"
device0.RTU_Parity = "None"
device0.RTU_Data_Bits = "8"
device0.RTU_Stop_Bits = "1"
device0.Discrete_Inputs_Start = "1"
device0.Discrete_Inputs_Size = "1"
device0.Coils_Start = "3"
device0.Coils_Size = "1"
device0.Input_Registers_Start = "0"
device0.Input_Registers_Size = "0"
device0.Holding_Registers_Read_Start = "0"
device0.Holding_Registers_Read_Size = "0"
device0.Holding_Registers_Start = "0"
device0.Holding_Registers_Size = "0"
Quote 0 0
air
If the problem was in the circuitry or hardware, QModBus would not write or read data?
Quote 0 0