From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error 1073807339 modbus

Hi

 

I am doing a VISA write and read to a RS485 serial device that has a modbus protocol. The program works great and reads the data I want. Howver, there seems to be something intermittenly interrupting the data flow, and sometimes the highest registers I am reading get cut off and it will just return a 0 for one iteration of the program. This happens mostly on for the 'power' which is register 4042H~4043H, or a[71:74] from the array I read. It never has any trouble reading the lower registers like frequency, which is 4000H and is the first register I read.

 

This is livable, however sometimes the entire LabVIEW crashes with a 1073807339 error. This isn't good because then the program stops collecting data. What could be causing this interupt? Or is there a way for LabVIEW to automatically continue the program, even if this error ocurrs?

 

I am using a USB to RS485 converter. The device is a Acuvim II-D-60. Settings are 19200 buad rate, no parity, stop bit of 1, no flow control (although I have tried with flow control). Please see screen shot and VI program attached.

 

Thank you!

Download All
0 Kudos
Message 1 of 4
(2,745 Views)

Why do you have the VISA close inside the while loop?  That should be outside the while loop after the loop ends.

 

Since you don't have any error handling on that wire, when you get an error LabVIEW is stopping and throwing up a dialog box.  Don't leave any error wires disconnected on functions that could generate errors.  Wire the error to an indicator, or at least to the border of the while loop.

 

I don't know why that particular register would have incomplete messages.  You are reading 74 bytes.  Do you expect the response to every message to have exactly 74 bytes?  Any chance a response could come up shorter?  How complete is the string when it does time out?  Do you get 0 bytes, or some of the 74 bytes?

 

Instead of manually building your modbus message and parsing the response, have you tried using the NI MODBUS Library for LabVIEW?

Message 2 of 4
(2,740 Views)

RavensFan. Thank you very much for the reply!

 

I have tried putting the close VISA vi outside the while loop, but then the data the query returned are radom speradic numbers. If I had to guess, it looks like the registers are being continously offset (ie 4000H becomes 4008H on the next iteration). With the close VISA inside, it returns the correct data. I don't understand why this is.

 

The way the data structure is for the acuvim, every register has 16bits, and from the VISA write vi I make a query to read 72 of the registers. But the modbus only returns 8bits at a time, so there are 144bytes. But power is contained on bytes 71 to 74, so I only need to read these from the serial buffer, even though the acuvim is returning all of the registers. I have tried to read fewer registers from the query, but it only works if I read all the registers from the acuvim.

 

When there is an interupt the number of bytes returns varies drastically, but it always returns the lowest ones, and the higher bits get cut off. For example, instead of getting all 74, I might get 1 through 64, or maybe just 1 through 8. Always a multiple of 8. And then if nothing gets returned at all, I feel this is when I get the error message.

 

I have downloaded and tried using the modbus library, but I couldn't get it to work. The way I have written it I have a better understanding of what is going on, as opposed to using a black box vi.

 

Honestly, the application can make do with a few data points missing. The biggest problem was having the program stop due to the error messages. Thank you for the advice on error handling, that will solve the problem for now.

0 Kudos
Message 3 of 4
(2,715 Views)

Overall, I think you are querying the wrong registers, the wrong number of registers, and looking at the wrong bytes that are returned.  You may be getting data, but are you sure it is the correct data?

 

I think the number of bytes you are reading is just wrong for the response being returned.  If the response sends back 80 bytes, and you are reading 74, then there are 6 bytes being left behind in the serial buffer, and those become the first 6 bytes of your next read, thus offsetting everything.  By putting in the VISA close, you are "solving" this problem because the VISA close causes leftover bytes to be discarded.

 

I'm almost certain you are reading the wrong number of bytes.  Or looking at the wrong bytes in the response.  Your command is requesting x48 registers, 72.  Each response should have 148 bytes.  One for the slave address, one for the function code, one for the number of bytes, 144 (2 x 72 registers) bytes for the data, and 2 for the CRC.  (Look at http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf for details on modbus.)  Yet you are only trying to read back 74 bytes.

 

You say the power value is in registers 4042H-4032H  (Are you sure you don't mean decimal?)  Register 42d, is index number 41 (since registers are zero-based)  Also, in modbus, you drop the leading #4 since it is assumed.

 

I highly recommend using the Modbus library.  It is not a "black box" vi because you can actually open them up and see how they work.  It will give you the checksum error handling, and give you the basic conversions to data (you will just have to do some typecast conversion to convert two U16's to a SGL, maybe swap words) so that you won't have to use that formula node.

 

The library also provides examples on how to use it.  Look at MB Serial Example Master.VI

 

If the later bytes are frequently cutting off, (perhaps some issue with the device sending out a larger string of data?), break your commands up into separate queries so that you only request the particular registers you are really interested in.

 

Take a look at the attached VI where I implemented the Modbus library.  You'll see it is a lot less work.  Read the modbus spec.  Understand how the addresses are numbered vs. how you ask for them in code.  Also, make sure you know whether the values are in hex or decimal.

 

 

Message 4 of 4
(2,707 Views)