Could not Read data from 2 slave Modbus RTU

Hi there,

I have a situation here. I am using PLC Edge Controller and I want to read data from my slaves Autonics ARIO-C-MR through Modbus RTU. I have managed to read the data when I write a code just to read just 1 slave. But when I try to read 2 slaves at one time, the first slave seems to be no problem but there seems error for the second slave “The addressed SI/TTY does not exist or is already attached” as shown in the picture I’ve attached below.

Hope somebody could give me suggestion on how to solve this problem. Thank you!

Best regards,
Umair Yamin

Hi Umair,
I think that you have to handle modbus transaction status.
Do not send anything to second slave until the first one is completed or time out.
By the way…why don’t use Modbus master functionalities on device tree?

BR
Anssi

hi Anssi,

thank you for your suggestion. How do I not send anything to second slave until the first one is completed ? got any example? Would really appreciate your help.

Modbus master functionalities on device tree is using Modbus_COM is it? I tried using that but it cant even read 1 slave. But im still troubleshooting it.

BR,
Umair

You need to utilize the “xTrigger” and “xError”. When xTrigger is reset by the MbMaster and xError is false, the query to the first slave is successfull, then you can move on to the next slave.

Hi Umair,
I’ve got a problem when replying your message.
I can send some tips directly if needed.
I’ve used serial modbus master a lot in Wago.

BR
Anssi

umairyamin via WAGO Open Source Community kirjoitti 2024-01-02 09:10:

Hi Anssi,

Yes. I would love to get your tips. It would be helpful.

BR
Umair

Hi bjorn,

how do I “utilize” the xTrigger and xError? I am so sorry, I am really a beginner to this thing.

image

Am I not utilizing it right now according to the code?

As you can only initialize the Modbus Master block/ RS-485 port once, you need a sequence to switch between the two slaves.

  1. SET xTrigger
  2. Wait for xTrigger to be FALSE
    2.1 No Error
  3. Change slave
  4. SET xTrigger
1 Like

You might want to try the built-in Modbus master, here is an example.

Hi,
as posted by Kurt and Bjorn, timing is very important when playing with RS485 serial port.
You can find xtrigger when defining Codesys modbus master “channels”.
xtrigger is extremely usefull because typically Modbus write register transactions are event triggered (sometimes once per month) and read register transactions are more or less cyclic.
By the way. Did you find modbus serial master in project tree?
It is strongly recommended to use it.
https://help.codesys.com/webapp/_mod_f_master;product=core_modbus_configuration_editor;version=3.5.16.0

I tried this way. But when I used this way, I cannot even read data from 1 slave. I am also not sure why.
I already put the communication parameter that I used when I successfully read 1 slave using function block such as baud rate, parity, read register, etc.

Hi,
I tried this way. But when I used this way, I cannot even read data from 1 slave. I am also not sure why.
I already put the communication parameter that I used when I successfully read 1 slave using function block such as baud rate, parity, read register, etc.

Hmm… The bus is not running. Why ?
Try to connect your Modbus IW1 to an other word type variable in PLC_PRG.

wVariable1 := %IW1 ;
wVariable2 := %IW2 ;
wVariable3 := %IW3 ;

Do you mean change these type variable ? The one that I circled.

And btw, what is wVariable1 ? Is it your variable name for %IW1?

Negative,
definition in PLC_PRG

VAR
wVariable1 : WORD ; // Only for testing Modbus register update
wVariable2 : WORD ;
wVariable3 : WORD ;
END_VAR

Unused variables are not updated.

I actually applied the same thing using Modbus TCP and it successfully worked. But for Modbus RTU, it doesnt work. I am not sure why.

I have checked the paramater communication settings, I have followed the one that I used in function block where I can read the data. But in the end, Modbus RTU using configurator doesnt show any result even for 1 slave.

If I want to say theres a wiring problem, there should not be since I can get data when I read 1 slave using function block.

I’m agree that TCP case.
What is your communication parameter setup exactly ?
9600,N,8,1 two wire half duplex ??
Be sure that RS485 A and B are okay.

Second slave looks strange…

Hello,
Can you post your Modbus mapping configuration? I am wondering what the Function Code is, and whether the device supports it. Also, FC 23 is not possible with half duplex RS485.

Hello,
this is my Modbus mapping configuration where i cant even read 1 slave.

This is my modbus using function block, where i can read slave 1 perfectly.

This is my communication parameter setup when im using function block, where i can get data from slave 1 successfully.
image

This my communication parameter setup when im using Modbus tree, where i couldnt even read data from 1 slave.

This is the error that appeared when I run the modbus tree, and the data isnt showing.

I wonder why its happening.