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.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus testing CVI code

Hello,

 

I am trying to use the Modbus Test CVI code from 

Always there is a way! Try to find it.
0 Kudos
Message 1 of 30
(5,339 Views)

Hello VeryDetermined,

there may be several reasons for this to happen, from the very basic one (e.g. some problems in cabling) to more complex situations.

 

The first tip that comes to my mind is that salve address 0 is used for broadcast communications: every slave in the network will handle those messages so in case you have more slaves connected their answers will ovelrap and may lead to communications errors. Does your slave have a individual address? It should. Can you test with that address?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 30
(5,334 Views)

Hi,

Thank you.

I am wondering if it is possible to use Modbus in a loopback system to get every message back after sending. (As you mentioned this might be a reason, what I had was a loopback RS485/RS232 and a USB converter)

The other thing is that I checked with other slave addresses. Non of them worked. So, if there is a way to know the slave address or I should assign an address?

I am also want to test it with two come ports and a Modbus simulator as well.

 

 

Always there is a way! Try to find it.
0 Kudos
Message 3 of 30
(5,308 Views)

Hi there. I'm having a little trouble understanding your system setup from your posts. What are you using as your Modbus master? What device are you using as a slave, and how many of them do you have? This may be relevant to how you assign slave addresses. What version of CVI are you trying to work with?

 

Also in terms of doing a loopback test have you seen this document, How to Do a Serial Loopback Test?

Miles G.
National Instruments
Staff Applications Engineering Specialist
0 Kudos
Message 4 of 30
(5,258 Views)

Hello,

Thank you for your attention to my post.

 

In fact there are two options for me. using the real device (which is a coriolis flow meter, just one slave) as slave and my PC as master. Unfortunately, I couldn't communicate with the device in this way yet. (still I ma not sure how I can decide about the slave address and the other relevant settings)

The second method is using loopback test. In this case I am not sure about my slave and master and settings.

And yes. I did checked the NI recommendations for loopback test and the loopback system itself works well using hyperterminal or M&A Explorer.

 

 

 

 

Always there is a way! Try to find it.
0 Kudos
Message 5 of 30
(5,234 Views)

Regarding the first option, setting the slave address is normally achiede via a hardware device (dip switch, rotary switch...) or by some configuration option if the device has a built-in operator panel. It should be noted in documentation.

Does the device come with a demonstration tool for speaking to it in Modbus? Some vendors ship a small software package to communicate with the instrument, which is normally used for a fast setup of it.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 30
(5,213 Views)

I have checked everything with the documentation to make sure there is no problem in communication settings. The only thing that I was not sure about Modbus test CVI code is Big/little endian (could you please help me on that).

However, I checked it out with both situations. Since the query still returns CRC error, I am going to check other things again like cable or device setting for Modus communication.

 

By the way, since Modus protocol address (memory address) in the Modus test code is short into parameter it cannot accept addresses like 40001 or more. Hence, I want to use into variable instead of short into for memory address. Does this make any problem with programming?

 

Thank you

 

Always there is a way! Try to find it.
0 Kudos
Message 7 of 30
(5,170 Views)

I seem to remember that device and memory address are unsigned, so they can hold up values to 65536.

 

With refrence to endianness, in my framework all functions conv_* that transform word values to fload or other data type consider data received in big-endian format. You can, however, adapt them to little-endian format by inverting the order of bytes as they are scanned.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 30
(5,152 Views)

Hello Roberto,

 

Thank you for your response.

 

What I can see is that both memory addresses are short int rather than unsigned. So I think that I can change them to unsigned short int without facing a problem. Can't I?

And thanks for mentioning about endianness. I am able to choose between little/big endians on the device. So I leave it as it is to stop myself from any mistake. (since my background is mechanical engineering I prefer to do less programming 😉 )

 

By the way, I am still trying to deeply understand the write and query functions (WriteMem and QueryMem). I have read the *.pdf file couple of times but I still have problem in understanding how we put everything together to write or query. Could any body help me on that or introduce me a reference with more details, I appreciate it. 

Always there is a way! Try to find it.
0 Kudos
Message 9 of 30
(5,145 Views)

WriteMem and QueryMem are functions I wrote to read and write from a modbus slave. There's nothing special in them, they are simply an implementation of Modbus specifications; I see you have used ModbusTest sample project: there you can find a practical application that uses those commands.

Prior to programing the code you must be sure of device address and memory locations of the instrument you are using: the Producer should give you full documentation about those elements.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 30
(5,122 Views)