Jump to content

EASY Advanced Modbus Reads


mdituro

Recommended Posts

Hey guys,

I'm often needing to use advanced modbus features because ill need to have dynamically adddressed slave ID's, or changing registers etc, etc and i cant use the built in configuration to do so.  Also - the Advanced modbus still require a good bit of logic to be built in order to achieve a good Tx and Rx.

I built this UDFB to be used as a single operation which accepts 4 Function In parameters, and one Function out.

Example Ladder Note how the function is called, Param 'D' must be reset immediately after the function call:

Ladder Image

Input A is a struct with 4 members (Note that only one Arr at a time will be filled with the result data, based on your input to parameter 'B')

resultBits[0-50]

resultInts[0-50]

resultUInts[0-50]

resultRaw[0-99]

The results of your query are stored here, depending on what value you use for input 'B'

1 = result store in resultsBits

2= result stored in resultInts

3= result stored in resultUints

4= result stored in raw buffer( for parsing floating point values etc, etc)

Input 'C' is your input parameters for the MB request - Don't worry about the Modbus request, and request descriptor - these are handled inside the function 

Input 'C' is a struct with the following members

slaveId

functionCode = Standard codes...holding register = 3, etc

startReg = starting register in slave

length = how many registers(Keep in mind length of buffers etc, you can always change this)

Retries = how many times to retry read request

Timeout = how long to wait for response(5000 = 5 seconds -- 3 retries at 5sec each would be 15 secs for a failed attempt)

Input 'D' is the Enable bit for the function to run - make sure to reset this immediately after the function call.(See image above)

Output 'A' is a number with the following values

1 = read successful

5 = timeout (timeout * retries)

255 = ladder Error

Let me know if i made a glaring mistake, or if you have any improvements!  I'm sure i didnt do this as effeciently as possible - but, it does work for my purposes.  I may add some more error checking and things later.  Let me know what you think!

Thanks,

Matt

MBR.ulle

Link to comment
Share on other sites

Matt,

I found myself in a quandary trying to use the periodic MODBUS as a master (Unistream 15.6) polling four V430 slaves. The biggest part of the issue was the default timeout value. I am using Kenwood VHF 25 watt transceivers with integral data modems; they have incredible range but their max baud rate is 9600 and the latency can exceed 500 mS. I see you have user defined a timeout value and retries count  (features integral in Visilogic). I will follow this post and will keep hoping to see Unilogic evolve to a place where: function in progress, retries, and user definable timeout for MODBUS are made available. I get the concept of simplifying MODBUS deployment in Unilogic; HOWEVER taking away the user definable parameters found in Visilogic can cause significant problems in some applications. I'm not educated enough in Unilogic yet to reinvent the features that were prepackaged in Visilogic. I am more of a ladder programmer and not at all a program developer (like C+) and find myself in an awkward place with Unilogic. It's great that's it's more object oriented (depending on your programming knowledge genre). I'm excited to see others building structs and sharing. Thanks!!

  • Upvote 1
Link to comment
Share on other sites

Hi,

First of all I want to point that for the next version of UniLogic we will add the option to the determine timeout for the MODBUS Panel..

Can you explain in  more details why do you need to change the Slave ID and addresses?

The Slave ID can be changed via UniApps --> Network --> MODBUS Mater serial . Then you can touch the area of the Slave ID and change it.

Please make sure to use the latest version of UniLogic and UniStream firmware.

  • Upvote 1
Link to comment
Share on other sites

Hello Ofir,

The addition of Timout and Retries in the default MODBUS operations will be a large help.

I Often need the ability to Auto-Detect Slaves in a network - which is why I need the ability to change slave ID's.  The Addresses could be from 1-255, and I don't want to have to set up 255 different combinations of possible reads(Last I knew, you could only even set up 32 slaves as a time anyway).  I also need to often read multiple different register locations/lengths while switching between slaves - so i am really limited on this by the simple mode, and must use the Advanced Modbus functions.

Thanks again for a great software and hardware.  I'm sure these abilities will be introduced again eventually.

-Matt

  • Upvote 2
Link to comment
Share on other sites

  • 1 month later...

Hi all,

I read this interesting topic and would like to bring my experience.

I find that periodic MODBUS is true verry simple and friendly.  Yet I would like to point on two other issues with that:

1. Many times WRITE command must be sent only once to the slave (like setpoints)  and periodic modbus function keep sending the data as long as the active bit is true.  in addition It is not possible to mix periodic and aperiodic configuration for read/write functions and not even for different slaves on the same port. My solution is to build  UDFB that compares data from READ and WRITE commands of the same address and reset the write active bit once the data is successfully sent, and with timeout for unsuccessful writes. I will be happy to share if anybody will find this helpful.

2. It is very important to have IMPORT/EXPORT option for the configuration lists, because they  might be quite long. This feature can save a lot of time and errors by sharing between projects and with the ability to use excel for editing.

Ofer

  • Upvote 1
Link to comment
Share on other sites

Hi,

1. In the next version of UniLogic you will be able set Periodic or Aperiodic per MODBUS command! This way you will be able to configure all the commands that you wish to send periodically and for example as you mentioned write commands to be triggered by ladder element.

2. I will add this request to  our list.

Link to comment
Share on other sites

Is there any chance of the periodic modbus seeing a retry parameter? In water treatment SCADA the data exchange is (in my region of the US) via RF data transcievers where outside RF interference can occasionally impede a successful MODBUS data handshake. In the Vision line the "retries" were an available parameter in the MODBUS config block. I will also take the opportunity to (again) petition for the development team to offer the MODBUS mixed R/W data feature (available in the enhanced vision series). That is an awesome feature that sets Unitronics apart from it's competitors!

Edited by hotwires
Link to comment
Share on other sites

i'd be happy with Uni to Vision. My last project used Vision slaves and a Unistream master. Uni to Uni would be a given. I don't expect Uni to third party. the vision R/W mixed was Vision only (no third party) feature. I can't emphasize enough how incredibly valauble the MODBUS R/W mixed I/O is! Cuts airtime in half on RF data modems.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...