LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to decode Modbus serial master query

Solved!
Go to solution

Hello,
I am new to use Ni Modbus, Kindly help me with below as I am stuck at very initial stage
I am trying to create Modbus slave using LabVIEW where I have to send data when master sends a query. the master will always send query to read holding registers with different starting address (Starting address 00H, 51H, A2H.. etc) . I am stuck at how to decode the query which is coming from master, to compare starting address and send data accordingly.


0 Kudos
Message 1 of 4
(1,053 Views)

Hi. We should be able to help, but could you answer a few questions and maybe provide a little more information?

 

How are you connecting to the master? Could you post the data that you are receiving from the master? Could you post the VI that you have right now?

Wes Pierce
Principal Engineer
Pierce Controls
0 Kudos
Message 2 of 4
(1,005 Views)

Hello,

I am connecting to master using a com port (Visa resource). 
There are so many examples on internet that i m really stuck what to use and what not.
I have tried numerous ways but found stuck someway or other.
Can you suggest any tutorial for Ni Modbus?
I am attaching a vi but I dnt know if that make sense.

 

The Master query that I will be receiving is
Unit Id:01H
Function Code:03H

Starting address Hi:00H

Starting address Lo:00H
No of reg to read Hi:00H
No of reg to read Lo:51H
CRC: as calculated


0 Kudos
Message 3 of 4
(989 Views)
Solution
Accepted by topic author Nectar_techabhi

If I understand correctly, you are wanting to take the data coming over the VISA resource and parse out the start address, length, etc that you will input to the MB Registers Manager VI?

 

You might need to just use a basic VISA read and get the literal data, instead of using MB Serial Master Query VI. That just depends on the details of your network. But, assuming that is the case, take the raw hex data in the string that you expect, something like this:

 

01 03 00 00 00 51 FF

 

To convert that into numeric data, use the Type Cast function and use a 1 D array of U8 integers as the type. That will convert each char of the string to a byte integer in your array:

Type Cast.png

 

Screenshot 2022-03-23 105257.png

 

You will likely have to do some parsing/splitting out of that data to get it how you want it. But see if this helps to get you a little further. 

 

Wes Pierce
Principal Engineer
Pierce Controls
0 Kudos
Message 4 of 4
(977 Views)