mdituro Posted January 18, 2017 Report Share Posted January 18, 2017 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 More sharing options...
hotwires Posted January 19, 2017 Report Share Posted January 19, 2017 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!! 1 Link to comment Share on other sites More sharing options...
mdituro Posted January 19, 2017 Author Report Share Posted January 19, 2017 Yes, I miss alot of the MODBUS functionality that we had in the vision series - that was kind of my reason for making this udfb. I need the ability to modify slave Id, start register etc etc on the fly. Thanks for having a look! -Matt Link to comment Share on other sites More sharing options...
Ofir Posted January 22, 2017 Report Share Posted January 22, 2017 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. 1 Link to comment Share on other sites More sharing options...
mdituro Posted January 23, 2017 Author Report Share Posted January 23, 2017 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 2 Link to comment Share on other sites More sharing options...
ofer.yishai Posted February 23, 2017 Report Share Posted February 23, 2017 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 1 Link to comment Share on other sites More sharing options...
Ofir Posted February 26, 2017 Report Share Posted February 26, 2017 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 More sharing options...
hotwires Posted February 26, 2017 Report Share Posted February 26, 2017 (edited) 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 January 28, 2018 by hotwires Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted February 27, 2017 MVP 2023 Report Share Posted February 27, 2017 +1 on the MODBUS Mixed R/W feature in the Enhance Vision products. I use this function constantly and it is one of the best features that Unitronics offers that is unavailable elsewhere. I would love to see it implemented in the UniStream product. 1 Link to comment Share on other sites More sharing options...
Cara Bereck Levy Posted February 28, 2017 Report Share Posted February 28, 2017 Hi guys! In which cases do you want to use the R/W mixed? Uni to Uni, Uni to Visi, Uni to other? Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted February 28, 2017 MVP 2023 Report Share Posted February 28, 2017 We want everything, Cara. You know that. As far as priority, I think it should be tackled in this order: 1) Uni to Uni 2) Uni to Visi (and the reverse) 3) Uni to other (though I suspect this would be quite a bit more difficult) 1 Link to comment Share on other sites More sharing options...
hotwires Posted February 28, 2017 Report Share Posted February 28, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now