Rog Posted August 7, 2023 Report Posted August 7, 2023 New to using RS485 modbus. I am wanting to set up a new pH sensor using modbus. Not sure where to begin with this. I know i set-up unistream hmi as master. I want to read pH and then calibrate the sensor. I have attached the paper work from sensor. Can't make heads or tails out of it. A simple program would make difference to understand what going on with the addresses and such. Thanks for the help!
ORSO2001 Posted August 7, 2023 Report Posted August 7, 2023 hi Rog, post what you did (may will be enough some picture about how you set the modbus)...and in my opinion the "problem" is understand how the floats variables works...you need to transfer the two INT16 registers (2*2 = 4 bytes) in a BUFFER of 4 bytes then transfer this BUFFER in a REAL variable; let me say that in my test the 4 bytes 41-DB-72-37 give a temperature of 27.430770.
Rog Posted August 7, 2023 Author Report Posted August 7, 2023 55 minutes ago, ORSO2001 said: hi Rog, post what you did (may will be enough some picture about how you set the modbus)...and in my opinion the "problem" is understand how the floats variables works...you need to transfer the two INT16 registers (2*2 = 4 bytes) in a BUFFER of 4 bytes then transfer this BUFFER in a REAL variable; let me say that in my test the 4 bytes 41-DB-72-37 give a temperature of 27.430770. I haven't really done anything really. This is about as far as I got.
pascal Posted August 8, 2023 Report Posted August 8, 2023 ROG, very simple : make a variable, type buffer, length 4 address -> depending on the data sheet of your PH meter depending on the modbus type, you need to change float type -> if the ph meter sends first the MSB or the LSB ??? a float is made of 4 bytes -> how it is build check this url : https://www.h-schmidt.net/FloatConverter/IEEE754.html after knowing how your meter is transmitting the bytes, then you can chose the correct type of float type and in your ladder -> just copy buffer to tag..... that's it....
pascal Posted August 8, 2023 Report Posted August 8, 2023 about the type of operation -> just read holding register (type 3 of modbus) I read my weather station every 10 seconds my float type is here NONE, but this is made with a previous version of unilogic, where I had to make my own swap "thing" So no program is needed, only configuration... that's all you need to do.... If you have a incorrect status of your modbus slave, try to change the address you want to read.... sometimes the manual say's it starts at adres 1, but in modbus language it could be address 0 (or 2 ?)
Rog Posted August 8, 2023 Author Report Posted August 8, 2023 3 hours ago, pascal said: about the type of operation -> just read holding register (type 3 of modbus) I read my weather station every 10 seconds my float type is here NONE, but this is made with a previous version of unilogic, where I had to make my own swap "thing" So no program is needed, only configuration... that's all you need to do.... If you have a incorrect status of your modbus slave, try to change the address you want to read.... sometimes the manual say's it starts at adres 1, but in modbus language it could be address 0 (or 2 ?) Yeah still not having any luck with this. I am thinking I am trouble understanding the address location of my device.
ORSO2001 Posted August 8, 2023 Report Posted August 8, 2023 what do you mean about "still not having any luck..."? what error code the modbus struct return?
MVP 2023 Ausman Posted August 8, 2023 MVP 2023 Report Posted August 8, 2023 Any time you are working with a new device, always do an initial trial of comms using your PC as the basis, with one of the freely available modbus comms programs. It is far easier to find what works correctly doing it this way, and then you can transfer the known results into your plc work.
pascal Posted August 9, 2023 Report Posted August 9, 2023 things to check -> wiring -> already changed the D+ and D- ??? in modbus general -> active period is Timer 1.out -> try general.on, then you are sure it's always working....
Rog Posted August 9, 2023 Author Report Posted August 9, 2023 12 hours ago, Ausman said: Any time you are working with a new device, always do an initial trial of comms using your PC as the basis, with one of the freely available modbus comms programs. It is far easier to find what works correctly doing it this way, and then you can transfer the known results into your plc work. Thanks. For the advice.
Rog Posted August 10, 2023 Author Report Posted August 10, 2023 Still not having luck. My usb rs485 finds the device. But unistream is still not making the connection. Kinda lost at this point.
Gabriel Franco Posted August 10, 2023 Report Posted August 10, 2023 Try 4 instead of 40004 (and so on) in address.
sgull Posted August 10, 2023 Report Posted August 10, 2023 Hi Rog Status 3 indicates that communication has been made but there is a problem with the modbus command. On the PC communication you are using read holding registers On the PLC communication you are looking for "read input registers (4)" change this to "read holding registers (3)" The addressing should be ok as it worked on the PC program.
Rog Posted August 10, 2023 Author Report Posted August 10, 2023 6 hours ago, Gabriel Franco said: Try 4 instead of 40004 (and so on) in address. Tried that as well. 4 hours ago, sgull said: Hi Rog Status 3 indicates that communication has been made but there is a problem with the modbus command. On the PC communication you are using read holding registers On the PLC communication you are looking for "read input registers (4)" change this to "read holding registers (3)" The addressing should be ok as it worked on the PC program. Tried this as well. Do I need to create some ladder logic to make connect and read?
MVP 2023 Joe Tauser Posted August 10, 2023 MVP 2023 Report Posted August 10, 2023 Upload your program so we can have a look. Joe T.
Daniel_EWW Posted August 11, 2023 Report Posted August 11, 2023 You can try it as shown in the picture... Poll: 01 04 00 00 00 19 31 CD 01 -> Slave adress 1 04 -> Function code Read Input Registers 00 00 -> Start Address 00 19 -> Read 25(dec) Registers 31 CD -> CRC https://simplymodbus.ca/FC04.htm
MVP 2023 kratmel Posted August 11, 2023 MVP 2023 Report Posted August 11, 2023 1 hour ago, Daniel_EWW said: You can try it as shown in the picture... Poll: 01 04 00 00 00 19 31 CD I think it is not correct. sensor do not answer for this request via Modbus software. Better to use message with time stamp 08:47:56 Poll: 01 03 00 00 00 19 84 00 Operation in PLC must be "read holding registers (3)" Daniel_EWW post good idea to use Array, but topic starter must play with Type of elements and Length of this Array for correct reading from sensor.
Daniel_EWW Posted August 11, 2023 Report Posted August 11, 2023 kartmel, you are right. I was not looking carefully enouth to the timestamps. (3) is correct. we mostly read the data to arrays. than we convert the data to a buffer and parse everything to the struct (and datatypes) of the modbus device. for a start it is certainly easier to use the unistream modbus configuration table without an array.
Rog Posted August 11, 2023 Author Report Posted August 11, 2023 It just a blank program . Just trying to a reading through being online, looking at global tags. Thanks for the help. test1.ulpr
sgull Posted August 11, 2023 Report Posted August 11, 2023 Hi Rog In your program you are still using "read input registers (4)" instead of "read holding registers (3)". This is what worked on your PC program. What modbus status do you get when change this?
MVP 2023 Ausman Posted August 11, 2023 MVP 2023 Report Posted August 11, 2023 On 8/8/2023 at 3:18 AM, Rog said: New to using RS485 modbus. When I first starting using modbus, which was not THAT long ago and I needed to finally jump right in, I found there was a lot to get your head around. One of the best things I did was get a simple, cheap I/O device that I played with for some time on the PC system, learnt a whole lot in doing this, and then gradually shifted the knowledge into the more complex programs I was being asked to do. I used Modbus Poll at the time, but there are plenty of other PC programs out there doing similar stuff. And admittedly I was using Visilogic which I was very familiar with, anyway. The standout thing was that the learning curve was mostly enjoyable, it was very pleasing to spend a few (??) hours finding methods of communication that worked or failed, learn the quirks of the device and work out how to get around issues. Then eventually see the magic reactions or inputs arrive correctly from various register types at/from the PLC using a host of trial methods, whilst deciding on the best one. I think it would be well worth your time to perhaps spend a little money and do such a thing. These days you are looking at really cheap prices, as well. Make notes along the way and keep them. cheers, Aus
MVP 2023 Joe Tauser Posted August 12, 2023 MVP 2023 Report Posted August 12, 2023 Thanks for uploading your program. The difference between Input Registers (function 4) and Holding Registers (function 3) can be very confusing indeed. It goes back to the days of Modicon PLCs where Input Registers were assigned to I/O modules in the rack and were type 3xxxx. Almost all device manufacturers use Holding Registers these days (type 4xxxx). When specifying the address, you don't include the leading "4". Unitronics specifies the address in decimal - if you want to go above 9 you'll need to convert the hex addresses in your document to decimal. If you want to really understand the Modbus protocol get yourself a large cup of coffee and look at the original protocol - https://www.modbus.org/docs/PI_MBUS_300.pdf Anyway, in addition to changing your operation to Read Holding Registers I noticed you are trying to read a float value into an integer tag, which won't work. If you go back and look at the document in your first post you'll see that the "Hosting Number" or Modbus address increments by 2. This is because floating point numbers are 32 bit values, and Modbus addresses are 16 bit words. When this protocol was defined there were no floating point numbers in PLCs so it wasn't addressed. I re-defined your "ph reading 1" array to type REAL, which is what Unitronics calls a floating point number. I also modified your slave table. Load this into your PLC and let us know what happens. Joe T. test1 JT.ulpr
Rog Posted August 14, 2023 Author Report Posted August 14, 2023 On 8/12/2023 at 1:21 AM, Joe Tauser said: Thanks for uploading your program. The difference between Input Registers (function 4) and Holding Registers (function 3) can be very confusing indeed. It goes back to the days of Modicon PLCs where Input Registers were assigned to I/O modules in the rack and were type 3xxxx. Almost all device manufacturers use Holding Registers these days (type 4xxxx). When specifying the address, you don't include the leading "4". Unitronics specifies the address in decimal - if you want to go above 9 you'll need to convert the hex addresses in your document to decimal. If you want to really understand the Modbus protocol get yourself a large cup of coffee and look at the original protocol - https://www.modbus.org/docs/PI_MBUS_300.pdf Anyway, in addition to changing your operation to Read Holding Registers I noticed you are trying to read a float value into an integer tag, which won't work. If you go back and look at the document in your first post you'll see that the "Hosting Number" or Modbus address increments by 2. This is because floating point numbers are 32 bit values, and Modbus addresses are 16 bit words. When this protocol was defined there were no floating point numbers in PLCs so it wasn't addressed. I re-defined your "ph reading 1" array to type REAL, which is what Unitronics calls a floating point number. I also modified your slave table. Load this into your PLC and let us know what happens. Joe T. test1 JT.ulpr 2.18 MB · 0 downloads This working, it connecting to sensor. Also the sensor wire A and B hook up to probe was backwards. But the unistream manual says D+ = B and D- = A. Switched this and it connected.
MVP 2023 Joe Tauser Posted August 14, 2023 MVP 2023 Report Posted August 14, 2023 You're welcome. The UniStream manual is correct. According to the official RS485 standard B is supposed to be + and A is supposed to be -. The problem lies in many of the manufacturers that didn't bother to look that up. It makes more sense for A to be +, so that happens a lot. RS485 really is kind of the Wild West of serial communications. Joe T.
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