LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

modbus tcp - receiving messages from slave

Based on your code screenshot (not actual code *grumble*) I think you might be running into a problem with your conversions to single. Modbus registers are 16-bit and therefore it takes two registers to store and then interpret a 32-bit IEEE floating point number. You are performing coercion which does not re-interpret bits but simply converts to the different format.

 

Typically the device you communicate with will specify the word order so that you know whether index0 is the Low word, index1 the High word or vice versa. Once you have the words in the correct order you can then Typecast to single. A quick forum search would find you some pertinent code you can re-create: https://forums.ni.com/t5/LabVIEW/Converting-modbus-data-from-two-registers-into-float/td-p/1626940

0 Kudos
Message 11 of 27
(632 Views)

Oh my.  What a mess.

 

Why would you use Byte Array to String which takes U8's and converts them to the ASCII equivalent?

This is what you need to do:  ( I put a space after %04x so every 4 hex digits are separated for readability)

 

Why would you take a U16 value and convert it to a Double?  2 bytes to 8 bytes?  It depends on what the register represents, or if two registers combine together to give you a Single precision number.  (4 bytes).  In which case you would use Join Numbers then Typecast it to a Single.

 

And Index Array is resizable.  No need to drop down 4 and wire up an index to each one.  Drop down 1 and drag the bottom down.  You'll automatically get index 0, 1, 2, 3, ....

 

0 Kudos
Message 12 of 27
(603 Views)

Hi Raven, Thanks for your suggestions, for the build message part of the Modbus Query is there any ways that I could improve it? Also for my VI is there any suggestions that you have other that the one you have previously? Thanks.

0 Kudos
Message 13 of 27
(599 Views)

Hi Raven,

I have tried out your method but it isn't getting the desired results I want.  As you can see in the picture I attached this I had set to the hex display for the string display but the modbus response message does not tally up. Any advice on this?

0 Kudos
Message 14 of 27
(582 Views)

@cyongjed wrote:

Hi Raven,

I have tried out your method but it isn't getting the desired results I want.  As you can see in the picture I attached this I had set to the hex display for the string display but the modbus response message does not tally up. Any advice on this?


Not without seeing the actual VI.  Better yet, put in indicators that show the response that you get.  Run the VI.  Set those indicators to save the data as default.  Save.  Attach to message.

0 Kudos
Message 15 of 27
(578 Views)

Hi Raven,

I attached it here. For your reference.The first image is the string output where I set the display to hex with the Modbus Query Message in Labview. The second image is using the CAS scanner, where the Modbus Response and Query Message is shown. Third image is the VI Block diagram. Could you advise me on how to get the same response message as the CAS Scanner. By right the CAS Scanner and the Labview message should tally with each other... but only the query does not the response...

0 Kudos
Message 16 of 27
(573 Views)

I said attach your VI.  Those are pictures.

 

And the picture that is named VI block diagram.png is not a picture of the block diagram!

 

And what is wrong with the picture that shows Modbus Query Message in Hex?

0 Kudos
Message 17 of 27
(570 Views)

Apologies wrong file. As mentioned that is the free software CAS Modbus Scanner that Chipkin Automation provides for real-time testing on applications using Modbus... I am expecting the VI to get the same message as the one in the CAS Scanner image attached previously for the Modbus Response Message....

0 Kudos
Message 18 of 27
(559 Views)

You didn't run this and save the data in your indicators as default.

I had set the format string to %04x with a space after it.  I don't know why you have it has %0.4x

Set Concatenated String to Normal display.

 

So the only thing you want is to put a space between every two hex digits and not every four?

 

If you want to make the space after every 2 hex digits, then typecast your U16 array to a U8 array.  Set your format string to %02x{space}

 

 

 

0 Kudos
Message 19 of 27
(549 Views)

Ok thanks Raven got it, can I ask why did you use a for loop in this case?

0 Kudos
Message 20 of 27
(544 Views)