Jump to content

Flex727

MVP 2023
  • Posts

    3,325
  • Joined

  • Last visited

  • Days Won

    241

Posts posted by Flex727

  1. It's no different than connecting a single master to the slave. You have 4 sockets available for MODBUS TCP. Just initialize up to 4 sockets to TCP, each with a different port number and do a MODBUS TCP configuration for each. Then have a separate SCAN_EX FB for each. There are example projects that came with your VisiLogic installation that will show you the best way to set up MODBUS TCP for both master and slave.

  2. 2 hours ago, Milosh said:

    What if we need read/write from different locations addresses which is not in seqence? Can we call more RHR whit different addresses in one requst?

    Each interaction would be a different conversation. As Joe Tauser said, only one can be active at a time. Just as I said you would have to separate reads and writes, if you want multiple reads or writes, they are each separate conversations. Every MODBUS TCP interaction through a single socket must be dealt with independently.

  3. Unless you're using a V700, the most devices you can communicate with by MODBUS TCP is 4 (without socket sharing, which I won't get into here). Yes, if your data exchange ladder rungs are set up properly you can communicate with up to 4 devices simultaneously.

    image.thumb.png.9f0697b84d57b2833cde9da8a6d9288b.png

    I'm just showing 2 of the 4 here. Just make sure your timer is long enough to make it through all 4 devices you're communicating with. If you're both reading AND writing to non-Unitronics devices, I would do it a bit differently. Instead of the timer Setting the comm requests, I would have the timer toggle another bit and use a positive transition of the bit to initiate all the reads and a negative transition to initiate all the writes.

    If you're communicating with other Unitronics PLCs, there is a handy Read/Write Mixed Data FB that will do both the reads and writes in one operation.

  4. Not sure I understand your question. You must use a socket initialization FB anytime you wish to assign a different configuration to the socket than the default assignment. Many programmers initialize all the sockets anyway just to have visibility into each socket's assignment and to help make sure there is no duplication of port numbers.

    Any socket that will be used for MODBUS communications (whether master or slave) must also have a MODBUS configuration FB. All the initializations, configurations, etc, should be activated by SB 2.

  5. 9 hours ago, Arberhaziri said:

    Also I want to ask about "Choose "On unload" Subroutine" , how can we use it ?

    I neglected to answer this question. This option does create a conditional subroutine which is why I never use it. There may be a specific need for it that I haven't encountered which is the reason Unitronics included it. I rarely use any of the "display controls" and prefer to create all my HMI calls in ladder. The only exception to that would be PLCs with physical buttons that need to be associated with different screens in different ways.

    I just now see Joe's response, which I totally agree with. With his single subroutine for Outputs (and Inputs, perhaps in a different subroutine) he is creating I/O "buffering. This is excellent programming practice which allows for easy code revision, easier testing, and reduced confusion at a later date.

  6. 12 minutes ago, Arberhaziri said:

    Also is it better to create a subroutine and to call that bunch of code only when needed (in this case the code to be read only when I turn AUTOMATIC MODE  ON) , or the code to be read all the time ? , is it better not to let microcontroller read unnecessarily?

    The PLC doesn't care whether the code runs or not. The poor programming practice is due to the fact that conditional subroutines can often execute in ways you don't expect (for instance, coils being left in limbo). There is no reason to do it that way.

    Ladder logic is not the same as regular computer programming and should not be treated that way. Except for very unusual circumstances, the only purpose for subroutines (in ladder logic) is to break your code up into manageable chunks. Every line (ladder rung) in the entire program should be executed on every scan. This avoids unexpected behavior and ensures that you don't trigger the Watchdog Timer.

    Bear in mind, I am giving my opinion on best programming practice. Other experienced programmers may have a slightly different opinion and there is no absolute right or wrong here. I am providing the benefit of my experience and skill which you may accept or ignore.

    • Like 2
×
×
  • Create New...

Important Information

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