LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Modbus API

Solved!
Go to solution

I'm trying to figure out how to use the Modbus API. I've read quite a bit and watched some tutorials but there are still things that I am struggling with.

 

1) Why is there a Master API and Slave API ? 

2) Do the read/write VIs in the API automatically assign the correct function codes based on what you are trying to read/write? 
    This NI page(The Modbus Protocol In-Depth - NI) lists the standard function codes. Based on that, I'm assuming the 'Read Holding Registers.vi' will assign a function code of 03.

3) My device has a function code (H10) which does not appear in this standard function code. How can I send this frame?

MrXXX_0-1632291449295.png

4) The documentation for my device states that I need to provide 'Number of Elements' in the field. This is the description of what 'Number of Elements' is:

MrXXX_1-1632291759236.png

The address for my parameter also varies depending on whether I'm using 4-byte mode and 2-byte mode:

MrXXX_2-1632291964739.png

I don't understand this part. Does the API handle the byte mode and adjust what 'Number of Elements' should be?

 

Thanks in advance!

0 Kudos
Message 1 of 7
(246 Views)
Solution
Accepted by topic author MrXXX

Hello MrXXX

 


@MrXXX wrote:

I'm trying to figure out how to use the Modbus API. I've read quite a bit and watched some tutorials but there are still things that I am struggling with.

 

1) Why is there a Master API and Slave API ? 

The slave API is used if your program is providing the values/memory. The slave waits passively for connections from another system.

The master API is used for querying another system.

Usually you need to use the master API

 


2) Do the read/write VIs in the API automatically assign the correct function codes based on what you are trying to read/write? 
    This NI page(The Modbus Protocol In-Depth - NI) lists the standard function codes. Based on that, I'm assuming the 'Read Holding Registers.vi' will assign a function code of 03.

Yes, the API that are available will use the correct function code

 


3) My device has a function code (H10) which does not appear in this standard function code. How can I send this frame?

MrXXX_0-1632291449295.png


H10 = Hex 10 = Function code 16, ie write multiple registers, that is a standard function code available in all APIs that I know of.

 

4) The documentation for my device states that I need to provide 'Number of Elements' in the field. This is the description of what 'Number of Elements' is:

MrXXX_1-1632291759236.png

The address for my parameter also varies depending on whether I'm using 4-byte mode and 2-byte mode:

MrXXX_2-1632291964739.png

I don't understand this part. Does the API handle the byte mode and adjust what 'Number of Elements' should be?

 


Your specific instrument/sensor seems to provide the same settings as a U32/I32 and as a U16/I16 memory area. A little bit ununsual but not unheard of. So it is up to you either you set values as U16 (starting at the two-byte register address) or as U32/I32 (splitting this to two U16 registers) in this case starting at the register address of the four-byte mode.

 

The APIs I know of handle the number of elements (when writing) because you hand over a array of U16 of a specific size. The API can determine the number of elements from that.

 

Regards, Jens

Kudos are welcome...
Message 2 of 7
(214 Views)

Thanks for the help!

So it is up to you either you set values as U16 (starting at the two-byte register address) or as U32/I32 (splitting this to two U16 registers) in this case starting at the register address of the four-byte mode.

Does this mean that I can either use the 2-byte mode address or the 4-byte mode address without having to adjust any settings?

0 Kudos
Message 3 of 7
(191 Views)

@MrXXX wrote:

Does this mean that I can either use the 2-byte mode address or the 4-byte mode address without having to adjust any settings?


I cannot answer that. Read the manual for your Modbus slave.

 

Regards, Jens

Kudos are welcome...
0 Kudos
Message 4 of 7
(176 Views)

One more question. How does this API handle exceptions from responses?

Let's say I have a response with an H03 exception. Will this be displayed in the error output of the read/write VIs ? I can't look into the VIs because they are password protected.

0 Kudos
Message 5 of 7
(104 Views)

Personally, I recommend Plasmonique Modbus Master to connect to Modbus instruments.   It is not password protected, so you can at least look inside it to see what it does.

0 Kudos
Message 6 of 7
(91 Views)

The NI Modbus Library is password protected but only when installed from the .vip. None of the source is password protected on GitHub and the vipb adds the password on build (if you open up the .vipb you can see that the password is "bestbus").

Matt J | National Instruments | CLA
0 Kudos
Message 7 of 7
(71 Views)