Jump to content

Recommended Posts

Posted

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!

IMG_3232.jpg

IMG_3231.jpg

IMG_3230.jpg

Posted

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.

Posted
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.

RS485.png

Posted

ROG,

very simple :

make a variable, type buffer, length 4

image.png.012359ad1a54a2bc5a90653a3f44ca67.png

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 -> image.png.4b90fc3d1d3760476d6e02a1c00c112c.png

just copy buffer to tag..... that's it....

Posted

image.thumb.png.1b66442dc3ba23b733280a99d5c522a5.png

 

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 ?)

 

Posted
3 hours ago, pascal said:

image.thumb.png.1b66442dc3ba23b733280a99d5c522a5.png

 

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. 

  • MVP 2023
Posted

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.

Posted

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....

Posted
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. 

Posted

rs485unistream.thumb.png.39394d9fbf3be282228d8078522dc710.pngrs485setup.thumb.png.4bf38c080349a8b76175aa5795b7b454.pngcasmodscan.thumb.png.d75e58ddd57140c8b97e8151dcf067bf.png

Still not having luck. My usb rs485 finds the device. But unistream is still not making the connection. Kinda lost at this point.rs485nocon.thumb.png.e84b3dd56fe93ebc7d1d9af3c02861ae.png

Posted

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.

Posted
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
Posted
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.

 

Posted

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.

Posted

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?

image.png

  • MVP 2023
Posted
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
Posted

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

Posted
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
Posted

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.

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.