LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write multiple register uing modbus library

eloo..i need help plz..i want to write multiple data to my device by using modbus library. but there is some time out error occured when i try to write more than i data to the device. actually i am not really expert in using this library. i try to seatch any labview code using this library in order to write multiple register in interenet. unfortunately i can't find it..plz..anyone can solve this problem
0 Kudos
Message 1 of 12
(11,560 Views)
0 Kudos
Message 2 of 12
(11,540 Views)
ermm..u are not using modbus library..ok..never mind..nway thanks..i don't think it is about the delay at timeout. actually i'm looking for an example to write multiple register using modbus library. i try to search an example at the internet but unfortunately i can't get one...if i get some example, it's easy for me to solve this problem..i have no idea what should i do right now..tq...
0 Kudos
Message 3 of 12
(11,529 Views)
Let me give you an example of one I used recently.  I used the modbus libraries and rewrote one of the upper level VI's a little bit.  I made it into a sub-VI for my main program by giving it a get vs. set functionality and using typedef's to name different registers or group of registers.  Attached is a screen shot of one case that uses a write multiple registers as well as a copy of the VI in LV8.2.1


Message Edited by Ravens Fan on 11-20-2007 08:30 PM
Download All
0 Kudos
Message 4 of 12
(11,526 Views)
Hi Ravens Fan,
thanks...i have try your example. when i downloading your example..there is an error that make the MB modbus Serial master query become invisible. so i replace it with the original mb modbus serial query in the library.did u use the original mb modbus serial master query?? after that i change  the starting address to 6 and quantity to 4 because i want to write 2 data on my device. but unfortunately i still get error out. can u please help me...tq..
0 Kudos
Message 5 of 12
(11,518 Views)
There are some special circumstances to my code that may or may not apply to your code.  For my code I was writing to paired registers.  I had to write a single 32-bit value into a pair of 16 bit registers.  So 40001 and 40002 were the high word and low word of the 32-bit value.  (Or low then high, I can't remember which).  So if I needed to write 3 32-bit values, I did a split word on the entire array and then iterleaved the arrays so that I would get high-low, high-low, high-low for each of the 3 values.  In your screen shot, you have 3 values, and you are writing to them starting at register 6, but are only writing to 4 registers.  I'm not sure whether that would cause a timeout error, no error, or some other error.
 
I would recommend writing some code to just write to a single register to begin with.  Make sure that works.  Open up the MB read write VI's and put probes on some of their error wires to see where the errors are getting generated.  Make sure that the registers you are writing to actually exist on the device.  (I had a problem where I created a modbus register on a device, but forgot to save its settings, then struggled for half hour trying to figure out why my LV code couldn't read from it.)  Also check the addressing scheme.  For instance 40001 might be referred to as address 0 in LV, or vice versa.  Sometimes there is a +1 or -1 relationship in the count of registers between devices.
 
Start with a simpler configuration, even just read a single register that is in the middle of a group of them so you can determine if your code is reading the right one, or the one before or after.  Then build on that.  Then read multiple registers (but just two).  Then write to the two registers.  Make sure the code handles the registers properly depending on whether it is 2 16-bit values, or a single 32-value going to a pair of registers.
 
If you have any software that the device manufacturer uses for setup or configuration of the equipment, trying using that and using NI-spy or put a serial port sniffer software to  see if you can capture the traffic.
0 Kudos
Message 6 of 12
(11,495 Views)
Hi,
 
I am having a very similiar issue regarding writing a value to multiple registers. Trying to startup the device using the following:
 
Write Multiple Registers: 16
Starting Address: 12 (actually 13 but shifted -1)
Quantity: 1
Data: 17096 (single presicion)
CRC
 
I believe we need to write one 64-bit number (first 32-bits being 0000's) to register 12. I'm not sure how to go about this. Couple of questions come to mind though. Am I best writing to a single register? In which case would I need to pad the data out with 32-bits worth of zeros at the begining? Using Version 8.0 by the way, so can't open your VI Ravens Fan .
 
We have been seeing an error code "6002" is this device specific?

Thanks,

Gordon
 
 
0 Kudos
Message 7 of 12
(11,281 Views)

You may need to post a little more information, like a link to the manual describing the communications for your device.

In Modbus, each register is 16 bits.  Often, you would use 32 bit values which would go to a pair of 16 bit registers.  Which is the the high order word and which is the low order word could vary depending on the device you are trying to talk to.  On the Numeric/Data manipulation palette are several function for joining and splitting numbers which are very useful for combining 2 registers into a single 32 bit number, or splitting a 32 bit number for writing to 2 registers.

64 bit numbers are rather unusual for ModBUS applications.  I haven't seen any using them yet.  But it would require 4 16 bit registers to handle them.

Attached is a LV 8.0 version of the previous file.  You may have  a broken arrow because of missing typedef's for some of the constants.  Also I made a copy of the NI modbus VI's and added CTA which was my project name to help prevent conflict with some other applications.  With this file and the screenshot above, you should be able to clean up the errors for the broken arrow.  You will have to rework to make it fit your application.  This was just basically a wrapper so that I could use more meaningful names in my top level application and hide the MB register address details in a subVI.

As for error 6002, I think I've seen it before, but I don't remember where it comes from.  I want to say it is either a timeout type of error or something being generated from within one of the MB subVI's.  I ran a MB query and the timeout error was 6101 and was generated from a MB read subVI.  So I think 6002 is a related error from one of the MB VI's.



Message Edited by Ravens Fan on 03-27-2008 11:51 AM
0 Kudos
Message 8 of 12
(11,254 Views)

Thanks for that...yeah my mistake...I meant one 32-bit number sent to two 16-bit paired registers. Currently we can only send one 16-bit number to the first register, where we actually need to send it to the second 16-bit register. We have tried writing to multiple registers (setting the first to all zeros) however this gave us an error. The starting address only seems to signify the first of the pair of registers, while the other seems to be inaccessable to us at the moment. 

What we want to try now is pad our 16-bit command with zeros at the begging so it spans across to the second register. I've attached the pdf specifying the modbus protocol for our device, which contains an example start-up request and error codes. I thought the "6002" error code may have been related to the "Illegal Data Address" code shown in the manual.

So far when we write a single register, no matter which set-up/arrangement we try, the register is showning a number "62403." Again not sure if that corresponds to something that is vendor specific or is a saturated variable.

Thanks.

0 Kudos
Message 9 of 12
(11,245 Views)

Hi G.noble,

I'm looking at page 8 of the document you attached, and it confuses me.

It says "The following table details the register addresses assigned to the GCC data. Note that float types use two registers"

But the table shows all the register addresses only separated by 1.  Usually for paired registers 40,001 and 40,002 will be one pair for one value, 40,003 40,004 would be the next pair for the next value.

It may be worth giving them a call to clarify how they address the registers.  Also, do they provide any software  of their own for communication?  If they do, it might be worthwhile to run that and use NI-SPY or some other port capture program to captures some communication between that software and the device to see how it accesses the addresses.

Also be careful about just writing a bunch of zeroes to one register.  IEEE 32 bit assigns certain bits to the mantissa, certain ones to the exponent, and also to the sign.  So reading the bits for 32 bit floating number is not an easy conversion like it is if you were convering from binary to decimal integers.

Also always try reading from registers before writing to them.  That way you can confirm if the value you read is what you expect based on reading it using their software, or a front panel interface, ....   Otherwise you could write a completely wrong value by accident either by because the registers are shifted by one, or you are working with the wrong pair.  Once you know you have things figured out so that the reads are correct, then you can work with writing.

It is a good chance that 6002 means illegal data address.  I just don't have any Modbus hardware powered up at the moment to confirm this.

EDIT:  Another thing I just noticed is that the vast majority of those registers are Read Only, so most of them you can't write to.



Message Edited by Ravens Fan on 03-27-2008 01:53 PM
0 Kudos
Message 10 of 12
(11,240 Views)