From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
09-22-2021 01:32 AM
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?
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:
The address for my parameter also varies depending on whether I'm using 4-byte mode and 2-byte mode:
I don't understand this part. Does the API handle the byte mode and adjust what 'Number of Elements' should be?
Thanks in advance!
Solved! Go to Solution.
09-22-2021 03:19 AM
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?
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:
The address for my parameter also varies depending on whether I'm using 4-byte mode and 2-byte mode:
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
09-22-2021 04:34 AM
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?
09-22-2021 07:55 AM
@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
09-24-2021 03:56 AM - edited 09-24-2021 03:56 AM
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.
09-24-2021 06:13 AM
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.
09-24-2021 03:04 PM
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").