LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

writing multiple registers modbus

Solved!
Go to solution

Hi,

I am communicating to a controller from my labview program using modbus RTU and the controller has modbus 16 bit registers.

To send in float values like "1.23" , I have to write two registers to store the 32-bit hexadecimal value for this float value.

I use the modbus driver provided by labview for this purpose and I use labview 8.2.1

I have the following doubts regarding this.

 

 

  1. The "Modbus  Serial Master Query. vi" has the Modbus command as a input which I use to set register values in the controller device's modbus registers. To send the above mentioned float value to registers 501 and 502 (holds the integral value of the PID parameters), to use the same vi, which value should be written first.. is it the high or low which should be written at 501 and 502.
  2. The function code for writing to multiple registers in the modbus driver is 16. But my document which is specific to controller has explained the 'writing to multiple registers' section with function code as 10. And I see that the 'write to single register' function codes matching and the modbus driver yielding the same type of message frame as discussed in the document. But I dont see any similarity in the 'write to multiple registers' function in the document and the labview driver for modbus.
  3. Will be the same if I write the registers 501 and 502 one after the other using 'write to single register' function code when these registers implement a single float value using 2 '16 - bit' registers. If this method is feasible, then I will go ahead doing it the same way as I have been doing it for writing to single register. So does writing data to the registers one after the other with a delay between the two writes as small as 4 ms do good?
I have attached the document for the controller in which pages 106 to 117 talks about writing a application using modbus to control the controller.Pg 111 speaks about writing to multiple registers and function code is mentioned as 0X10.
 
I really appreciate any help in this concern.
Thanks,
VJ 
 

 

 

0 Kudos
Message 1 of 10
(9,299 Views)
Solution
Accepted by topic author vijay shankar

I suspect a confusion between decimal 16 and hexadecimal 10 😉

Two successive register writes are not equivalent to one double write : during the period between the two writes your controler will be loaded with a false parameter. This may not necessarily be a source of problems. It depends on your application. Writing the MSB first should reduce the problem.

The Hi-Lo order is dependent on the controler maker. Some use Big Endian, other Little Endian. But this choice should affect single register values (U16) as well.

If this is not documented, you should read the registers, and see if the result makes sense. If not, reverse the byte order and verify that the problem is solved. Good luck 😄

 

By the way, I suppose you know how to use the typecast function to convert a single (32 bits float) into 2 U16 ? 

Chilly Charly    (aka CC)
Message 2 of 10
(9,295 Views)

Thank you CC,

How am I so dumb not to recognise that 16 in decimal is 10 in hexa..:manindifferent:

haha.. happens.. phew!!

Ya, I have converted a floating point into  U32.

Now to split it, and give decimal values to the vi, should I give the decimal equivalent of the MSB and LSB to the vi..

For example 

 12.3 in U32 is 4144CCCD

so to give two values to two registers, should I give 16708 and 52429 to the registers as MSB and LSB as they are equivalents of the values shown below

  || ||  

    4144          CCCD

Please clarify this alone..

Thanks a ton for your help.

🙂

 

VJ 

0 Kudos
Message 3 of 10
(9,293 Views)

Not sure about the way you do your conversion. Have a look at the diagram below and tell me if this is what you were doing 🙂

 

The most interesting thing here is that casting the single precision float to an U16 array (top type cast operation) gives directly the data to be transfered to your ModBus VI. 😉  

 

And by the way, congratulations, you have already done a good job out of LabVIEW since your first question on these forums 😉
Message Edité par chilly charly le 01-05-2009 10:16 PM
Chilly Charly    (aka CC)
Message 4 of 10
(9,276 Views)

 

Thank you so much..

I was using the method that I have attached to this post.

Which is nothing but one of the methods in your VI. 

Yours seems to be a short method than mine as it directly converts it to an array.

I will use yours  :smileyhappy:

Thanks a lot

 

VJ 

Message 5 of 10
(9,272 Views)

This image is more clearer than I posted above..

Thank you  :smileytongue:

0 Kudos
Message 6 of 10
(9,270 Views)

vijay shankar a écrit:

This image is more clearer than I posted above..

Thank you  :smileytongue:


The prefered format to post clean diagrams is png.
And never forget the Kudos button 😄 😄 😄 

 

Chilly Charly    (aka CC)
Message 7 of 10
(9,257 Views)

can somehelp me out. im new to labview. Im doing a small project on communication between two computers via labview on modbus protocol. So we have to select the com port in the field dats written "visa resource name" but somehow there are no options in mb serial init.vi. it only has "refresh". wat could be the reason that i dont see the drop down menu to choose the com port in "visa resource name" ???

0 Kudos
Message 8 of 10
(8,498 Views)

Don't post the same question in multiple highjacked threads.  If the answer given for your other post does not help, then move the discussion into a single brand new thread.

 

The same question in multiple threads (especially ones that aren't related to your problem) just annoys people.  Especially when they answer your question to one thread that has already been answered in one of the other threads.  Also, if you wind up with on going discussions in multiple threads, it just duplicates everyone's work, and the information you are given and questions asked are just scattered among multiple places.

0 Kudos
Message 9 of 10
(8,482 Views)

ohh sorry. Very new to this forum and i was desperate. Anywayzz will remember that. Tq 🙂

0 Kudos
Message 10 of 10
(8,465 Views)