LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus RTU Communication Error Code: 538182

Hi there,

I got an USB to RS485 adapter that is connected to a 185nm UV sensor. I should use modbus RTU communication type.
I've read this article of modbus, thus i've created my own vi.:
modbus RTU.jpg
I get Error Code: 538182 when i run the vi. I have the following modbus libraries installed: ni_lib_modbus_library-1.1.5.39.vip, ni_lib_modbus_library-1.0.10.23.vip

Note: Sensor is physically connected. If i use the application of the manufacturer then it communicates.

Could someone please tell me what is wrong with my code? 

Kind regards,
Balázs

0 Kudos
Message 1 of 9
(4,803 Views)

If you do an "explain error" on that error code, you'll see it says "illegal data address".  So address 0 is not on that device.

 

Unfortunately the manuals you attached don't really detail the modbus addresses.  But it seems unlikely that address 0 would not exist.

 

But when I opened your VI, I see you used Read Input Registers.  That is command code 4 with addresses starting with a 3.  So address 0 would be 30001.  Input registers seem to be much less common in Modbus devices when compared to Holding Registers.

 

I would try changing that to Read Holding Registers.  Internally, that would use command code 3, and those registers start with a 4.  (I never understood why those numbers are reversed!)  So address 0 would be register 40001.

Message 2 of 9
(4,761 Views)

Well, i got the datasheet of the modbus addresses, please have a look at the attachement. It reads 'Request by ReadHoldingRegister and ReadInputRegister are mapped to the same physical registers'.
test1.jpg
1) How do you know how many inputs should be set? (Number of inputs are set to 2. If I set it to 1, then i read nothing in UVValueRegister1 (High word))
2) I frequently get error code 56 at startup, then i have to restart my VI many times to get my code running without trouble. Note: changed the current 5m long USB cable to 3m long. Error still occurs
3) What should i do with both registers? (Registers UVValueRegister_1 (high word) and UVValueRegister_2 (low word)) It is confusing that they seem to store the same UV value. 

Looking forward to seing your reply,

Kind regards,
Balázs

0 Kudos
Message 3 of 9
(4,710 Views)

It's odd that it allows you to use either Read Input or Read Holding Registers.  But it says it does, so that is probably not the problem.

 

The new PDF you sent shows that the ReadUVValue is at registers 1000 and 1001.  Since they don't have a 3 or 4 in front of them in the documentation, (and wouldn't since they can be interpreted as either input or holding registers), then I'm going to assume they are the register addresses in the 0-based numbering system.

 

Your code shows you reading with a start address of 0.  Try wiring in 1000 there.  Start with a # of registers of 1 just to see if you get something.  Then if you put in a 2,  you should get an array of 2 U16 elements. Those two registers do not store the same value.  Registers are only 16 bit, but the device wants to give you a 32 bit number.  So it splits the number up into two parts, one into each register.  The high word is the most significant part of the integer, the low word is the least significant part.  A "word" in this case means a 16 bit value.  You will then take the 2 elements and numerical convert them.  That might be as simple as using typecast to a U32 integer.  Or you may have to use the Swap Words function in the numeric palette.  Or take the two elements and combine with Join Numbers.

 

Error 56 seems odd to me in that it is the type of code usually relating to TCP/IP communications, not serial.

 

 

See if the modified VI works.

0 Kudos
Message 4 of 9
(4,705 Views)

Hi, I thank you for you help.

I have to 'Run' the VI three times, else i get error code 56. Then If i stop running VI by pushing 'Stop' button then i will have to run VI literally three times again else i get error code 56.  End so on..
For the 4th times i always can have communication.

I do not clrearly see what can cause error code 56, but i'll give it a try to change the USB to RS485 converter next time.

Download All
0 Kudos
Message 5 of 9
(4,693 Views)

I would say don't put a shift register on the error wire.

 

Once you get an error, you won't be able to do anything until you stop and restart.  I would probably not stop the loop on an error either.

 

What you could do is handle the error.  Put the code that converts the data and displays it into a case structure where error wire is wired to the selector terminal.  Put it in the No Error Case.

 

Unfortunately, that won't keep you from getting the error 56, but it will allow it to try again, continue running, and not present you with default data when there is an error.

 

To debug the error further, open up the Modbus VI's and put probes on the error wires.  See if you find the source.  The message says it occurs at Read ADU packet.  But some of those subVI's are locked and you may not be able to dig down deep enough to see them.

 

You could also consider using another Modbus library.  It is older, but I've used this for years prior to the purple and yellow banner ones coming out.  http://www.ni.com/example/29756/en/

0 Kudos
Message 6 of 9
(4,687 Views)

Hi there,

I tested the following library of modbus: http://www.ni.com/example/29756/en/
The result lead me to the same error just like before.: I get connection lost after couple of minutes. When it occurs i have to restart or logout my PC. (I tried closing of VISA session, but it did not work)

"Error -1073807194 occurred at VISA Write in MB Serial Transmit.vi:630002->MB Serial Master Query.vi:1850001->MB Serial Master Query Read Input Registers (poly).vi
Possible reason(s):
VISA: (Hex 0xBFFF00A6) The connection for the given session has been lost."

I then created a new project that appears to work. Please see the attachement VI.

Note: my entire project in which i always get error of "Connection lost" is complex. In this project I communicate with 4pcs of instruments via USB (TESTO, Keithley 2700,...) and  I create a .txt file and also graph of 9 parameters with polling. It seems to me some timing issue. Although my complex project that works without modbus.

Have you got any ideas if it is because of polling?


0 Kudos
Message 7 of 9
(4,655 Views)

I don't see anything obviously wrong with your VI.  I don't think the polling would cause a problem.

 

What brand of serial port are you using?  Is it a USB to RS-232  or RS-485 converter?  There are some brands of serial port adapters out there that have some flaky drivers and chips for them.  Perhaps it is one of those.  Try with a different brand of serial port adapter and see if anything works better.

 

What you could possibly do is that if there is a failure after your retries, try closing the the serial port and opening a new one.  Put a shift register on the VISA reference wire so it maintains the reference of the newly opening serial connection.

0 Kudos
Message 8 of 9
(4,644 Views)

Hi,

I am using the ZED Ziegler Electronic Devices USB to RS485 adapter.
In the attached VI i try to do the following error handlings: retry reading from input register 20 times and/or reinitialize modbus communication in main loop.

I attached a simplified VI with indicator for UVC data. My original VI uses graph for UVC data:

uvc signal.jpg

Reinitialization of modbus in runtime leads me to have a very noisy signal. I'll try to filter this signal. 

Kind regards,

Balázs

0 Kudos
Message 9 of 9
(4,595 Views)