Jump to content

Help with multiple Modbus writes.


Recommended Posts

I'm fairly new to Unlogic and Ladder Logic/PLC programming in general.  I am using a PLC to control a stepper driver via Modbus and this is more of a general "best practice" question than really anything specific I suppose.

I have successfully been using aperiodic register reads & writes from the PLC.  However, what is the best way to handle multiple actions/operations?  Ie.  When you need to do several register writes in sequence to perform a certain action.  I have used the "Aperiodic Indirect Group Trigger" to execute a series of register writes successfully, but this only seems to work when the order of the writes do not matter (ie.  setting parameters).  When using this feature, there doesn't appear to be a way to specify which operation happens in what order?  Does it just use the ID number of the operation within the group and execute the operation based on that?    I have not had any luck with this feature when I need to perform operations in a specific order,  for example: stop the motor, change direction, maybe change speed, and restart motion.  In a case such as this, I have been unsuccessful.   I'm getting a Status code -11 (not even sure what that status means - timeout probably?)

Is there a better way to do this?  Should I just be using single operations instead of groups and use timers or something to control the execution?  When I just stack multiple "Aperiodic Indirect Triggers" inline, it seems that only the first one works.  I assume because the 2nd, 3rd, etc. operations try to send their command before the first is finished (strangely enough though - no errors are generated).  Should I be using timers to control the operation execution?  Is there a better way?  if so, can someone provide an example maybe?

Thank so much for any help.

Link to comment
Share on other sites

In my opinion, like the sequenc to "stop the motor and reverse the direction with another speed", you have to check this in accordance with the machine you want to control.

first you have to stop the engine,

then , when checked the motor is topped, sending the new speed and afterwards, setting the run command.

If you want to take full control of the modbus communication, you have to create your own routines to make the modbus com.

In fact, it's really simple.....

modbus tcp/ip communication goes with a TCP connection and sending following data :

image.png.79ab44b1d9f4980be2e5f14e57fd5f53.png

transaction ID and protocol are 00 00 00 00

message :

first byte is function code (like 03 for read holding register)

second word (2 bytes) is startadres

last word (2 bytes) number of words to read...

check this manual  https://www.fernhillsoftware.com/help/drivers/modbus/modbus-protocol.html

If you want to be sure, maybe packetsender(external free software found on the internet) can help you to send the commands to your machine and see how it reacts....

Link to comment
Share on other sites

Thanks pascal.

I am using Modbus RTU over a RS485 link.  I understand (generally) the modbus protocol and how the addressing is handled.  I can successfully send modbus messages to slave and receive responses, etc.  My issue comes when trying to send multiple messages back-to-back, to perform register writes, which is required for my motor control.  For single modbus messages it seems to work just fine.

When testing with a terminal connected to the PLC instead of an actual slave, it seems I have to wait 3.5+seconds between modbus messages to get them to transmit (500ms Response Time setting + 3 sec Slave Message Suspension.  The strange part is the Slave message Suspension should be only enforced when a transaction gets a -2 error code which I am not seeing.  They are just -11 error for a timeout (since no slave connected to respond).

It appears that the UniLogic Modbus Master is enforcing this 3 second suspension when it probably should not be??

 

I have another post whcih goes into this in more detail:  

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.