LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus communication with sensor

Greetings everyone. I'm trying to communicate with an HY-OPTIMA 5846 via Serial Modbus. I'm using an NI USB-485 as the communication interface. So far, here's what I've done:

 

  • Following the instructions for the USB-485, I shorted terminals 4-8 and 9-5 on the connector
  • Connected the GND pin (1) to sensor GND
  • On NI-MAX, configured the serial port as 2 wire auto, disabling the bias resistors
  • I have used roughly 5 different Modbus libraries, to no avail
  • Found this rather helpful and interesting VI (attached snippet, excuse the mess), closed the thread and cannot find it again, but at least it is giving me something to go by

Right now I am using the manufacturer supplied defaults, i.e. no parity, no flow control, no termination char, 19,200 rate, 2 stop bits. I get either a generic I/O error or a framing error, but at the very least I am getting something from the sensor. If I either shut it off or disconnect it, response goes to zero.

 

If I mess with the baudrate and go beyond 19,500 or under 19,100 communication breaks completely. No other common speed (9,600; 14,400 etc.) works, so it might not entirely be settings.

 

Has anyone encountered a similar issue before? What could I be missing? I have tried both the regular Modbus commands as well as the raw data from the snippet, with read registers and loopback 

 

  • Modbus test.pngModbus test.png

 

0 Kudos
Message 1 of 8
(389 Views)

Self update: 

 

It APPEARS to be working without disabling the bias resistors, on 2-wire auto

Daikaz_0-1786745003775.pngDaikaz_0-1786745003775.png

 

Which I'm certain was very much not the case before, and goes against what the NI guide for the USB-485 says, but at least now I'm able to at least, establish communication with no errors, and even get some results via the more high level Modbus libraries.

 

I will continue testing functionality for the rest of the day and again on next Monday and update as to whether or not this was an actual solution or a red herring.

0 Kudos
Message 2 of 8
(347 Views)

Did you try a Web (Google) search for "USB to RS-485 Modbus"?  Several examples of the device, LabVIEW code to use it, etc.  [I've never used ModBus, so I "looked it up" ...].

 

Bob Schor

0 Kudos
Message 3 of 8
(225 Views)

Yes, several in fact; like I mentioned, must've tried no less than 5 different Modbus libraries and examples, that's how I ended up finding the VI I posted. Trust me, I don't post a thread unless I'm absolutely stumped and out of ideas.

 

I ended up using the open source Plasmionique Modbus library, after the change in settings that seemingly solved the problem.

0 Kudos
Message 4 of 8
(213 Views)

Did you add the 120 Ohm termination resistors to both ends? You may think that the bias resistor setting is this but that is not correct. These interfaces have AFAIK no internal termination resistor that can be enabled or disabled but require physical termination resistors on both ends of the bus.

 

The bias resistors that can be enabled or disabled in software are actually biasing the + and - side of the bus to +5V and GND respectively to guarantee a proper offset of the data lines in idle state. It also forms an AC signal termination of some kind through the power supply but far from the correct 120 Ohm line termination.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 8
(175 Views)

Indeed I did. The sensor, according to the user manual, has an internal 120 ohm resistor, and I added one to the other end of the communication, right on the part where I short the Tx Rx lines.

 

Right now, the settings that are working for me are 19,200 baudrate, no parity, no flow control, 2 stop bits, bias resistors enabled on the USB-485 in 2 wire auto mode. The 120 ohm resistor seems to make no difference at all; have tried with and without, no difference.

 

Plasmionique Modbus library has been so far, the best one I've tried, and their example VI is the most robust I have seen. Highly recommend it.

0 Kudos
Message 6 of 8
(157 Views)

I've heard other reports where some of the Modbus libraries didn't seem to work with specific devices but never had these devices myself to verify why that would be. It seems illogical since the Modbus protocol is quite trivial to implement and there are not many possibilities to vary on that.

 

As to needing a termination resistor on both ends of an RS-485 cable, that depends a lot on the cable length. For short cables 1 termination on either end is usually enough. It allows that a real current can flow in the current loop and that is already enough. The missing termination on the other end will cause reflections of the signal in at least one direction but for short cables that will be relatively limited. If you go towards the maximum cable length and/or the maximum nodes on the bus of what the RS-485 specification allows, proper termination is very important however.

 

The bias resistors are often needed to provide a defined idle state of the bus when none of the nodes is sending. Otherwise the lines are floating because of the typical very high input impedance of the receivers on the bus and when one of the nodes then starts to send, there is a lot of ringing and overshoot before the bus stabilizes.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 7 of 8
(125 Views)

That is some quite valuable information, as this is part of a whole system and will share space with several other sensors and equipment, which will certainly add electrical noise and complexity.

 

I will incorporate the 120 ohm resistor at the final design with the terminal blocks, which should cover for the added length on the sensor's final position. Thanks!

0 Kudos
Message 8 of 8
(55 Views)