01-04-2009 12:29 PM
Hi,
Has anybody used Modbus driver for labview to communicate to a device using RTU over RS-232?
I have a device to which I need to send messages to and I tried using the labview drivers from NI for this purpose.
I used "MB Serial Master Query.vi" to send a message.
But, I dont know what should be given as input to this vi to frame the message using RTU protocol.
Also, I have written a program to calculate CRC for an input string. I don't know where to give that as the input for this vi to append the CRC to the message frame.
Does the vi automatically calculate CRC?
I have attached the document for the device in which pages 106 - 117 talks about developing an application to control the device.
Can anyone please tell me how to use the modbus driver for this purpose? The document supporting this driver doesn't provide me with much information.
Thank you
VJ
Solved! Go to Solution.
01-04-2009 01:30 PM
The modbus VI's automatically calculate the CRC for you. Right click on the inputs to the Modbus query VI and select create constants. The constants will be clusters for the data needed. Key parameters are Modbus slave address, command, starting address, ....
Note that the modbus register addresses may or may not be shifted by 1. So address 1 in the manual might actually be address 0 in the Modbus VI's.
01-04-2009 01:49 PM
Hi,
Thanks a lot for you input.
I actually tried creating constants, but I couldn't make sense of two input terminals to the Modbus Serial query vi.
Say I need to send a frame with inputs as
09 06 01 2C 00 C8 49 21
where 09 - address of the device
06 - function code to write to single register
01 2C - register address 300
00 C8 - value 200
49 21 - calculated CRC which modbus will itself calculate for me.
One of them is modbus command which has a cluster of inputs with the following
modbus function - this one i can understand and i choose 06 for writing to single register
starting address - 09
quantity - is this the number of bytes? what should it be for the above message
an array called data - how to give register value and data value in this array
array for discrete - i dont know what this is used for.
I pass in the visa resource name through the MB serial init.vi and also the parameters for the modbus message.
Then I pass the visa resource name from this vi into the MB serial query vi.
i couldn't trace the significance of each of these input terminals to the serial query vi.
Thanks in advance,
VJ
01-04-2009 01:53 PM
Thanks buddy,
I got it,
I have been mistaking starting address as the slave address..
i am poor in labview.
Thanks a ton for your help.
Now, i can't make sense of "quantity" and "discrete array".
Can you tell me what these are for?
If they are used for writing multiple registers or some other function, can u tell me how to make use of it..
Thanks a lot again.
NI forums ROCK!!
VJ
01-04-2009 02:14 PM
Yes. Quantity is for reading or writing multiple registers. For example, you would use 3 and a starting register of 50 if you wanted to read registers 50, 51, and 52. It would be returned as an array. Off hand, I can't remember precisely the command codes for mulitple registers, but you will find them in the command code enum.
Discrete array is used if you were reading or writing to coils, the modbus name for boolean registers.
01-04-2009 02:31 PM
Thank you so much,
Kudos to you
VJ
04-21-2011 06:47 PM
Hi, I need help to meak a VI to get data from a multimeter that measure eletrical values, the multimeter uses a modbus-rtu protocol and a usb to rs-485 converter to communicate to the tha computer. I've red on the user manual that I have to use a read input registers function 4 to get the values. I have the ni modbus library and dsc library but I don't know how use it. The usb to rs-485 appear as COM4 port on my computer.
04-22-2011 12:04 AM
Please keep your question to a single thread.
What have you tried? You said you have the Modbus Library. Did you look at the MB Serial Example Master.vi? In reality, all you need is the MB Serial Master.vi.
04-22-2011 12:46 PM
But how could I use the MB Serial Example Master.vi?Do I need to use that Data to write to the slave on the VI or I can leve this without fill in? And I need read more than one values.
Thanks for the reply.
04-22-2011 01:07 PM
You just need to use which ever type of data matches your situation. So if you are writing holding registers, then you just need to fill in the register number, number of registers, and the data which is an array of length equal to the number of registers you are writing.
Note that in LabVIEW, the registers start counting at 0. So if you are trying to write to Register 40001, your starting address will be 0. If it is Register 40008, the starting address will be 7.
If you'd like more information on the Modbus protocol, then I recommend you look at the technical papers at the modbus.org website http://www.modbus.org/specs.php