09-19-2013 11:58 AM
Hey Nishant,
My first recommendation is that for something simple, it really is worth it to use the Modbus I/O servers included in LVRT and LVDSC. If you have either of those products you can use the I/O servers. The benefit to this is that it provides a background process which handles the modbus for you--you just need to look up the registers that your slave sensor is using and it will work.
This library is useful if you need lower level control. In the case of Tarsel, he is trying to test a slave device he created. In my case, I've used the library to meet my performance needs. If you need either low level control or higher performance, you can and should use this library, but you'll need to basically do the following:
09-23-2013 10:56 AM
Hi all!
Is there any more detailed tutorial on how to use this library? I see those examples, but still have no idea where to start from
Problem description:
I have NI 9871 module, with 5 devices (ABB network analyzers DMTME-I-485) connected in series via RS485 in a single NI 9871 port (Port 1). Each of these devices are assigned with unique address 1-5 (via device settings), and I'm trying to read some values from these analyzers (in device communication protocol manual, it says that holding registers are starting from address 0). However, I don't know what is the procedure: do I have to initialize slave device, or do I have to initialize the master device first, how to show obtained values on front panel (i tried to create indicator, but without any success), who sends the read query - labview application on my crio or initialized master etc.
Thanks in advance!
Best regards,
Marko Gulin
09-23-2013 12:06 PM
mgulin wrote:
Hi all!
Is there any more detailed tutorial on how to use this library? I see those examples, but still have no idea where to start from
Problem description:
I have NI 9871 module, with 5 devices (ABB network analyzers DMTME-I-485) connected in series via RS485 in a single NI 9871 port (Port 1). Each of these devices are assigned with unique address 1-5 (via device settings), and I'm trying to read some values from these analyzers (in device communication protocol manual, it says that holding registers are starting from address 0). However, I don't know what is the procedure: do I have to initialize slave device, or do I have to initialize the master device first, how to show obtained values on front panel (i tried to create indicator, but without any success), who sends the read query - labview application on my crio or initialized master etc.
Thanks in advance!
Best regards,
Marko Gulin
I have found my approach to be pretty robust (using the old Modbus Library - cRIO being the Master / Client - other devices being the Slave / Server).
Timed loop with case statement within. Three states Dial, Talk, Hangup.
Dial state: TCP Open Connection FB (Or the equivalent in this library), pass the refnum to a shift register to be used by subsequent states. If no errors, go to Talk State - otherwise go to Hangup state.
Talk state: Initialize arrays outside of the timed loop and wire them in. MB Ethernet Master Query FBs (Read and Write flavors, again equivalent FBs from this API) If no errors, go to Talk state. Otherwise, go to Hangup.
Hangup: TCP Close Connection FB - and back to Dial State
For unpacking the array, a For loop tied to the returned array's size and combine / manipulate the U16s as required.
Message was edited by: S1ack
09-23-2013 11:22 PM
mgulin wrote:
Hi all!
Is there any more detailed tutorial on how to use this library? I see those examples, but still have no idea where to start from
Problem description:
I have NI 9871 module, with 5 devices (ABB network analyzers DMTME-I-485) connected in series via RS485 in a single NI 9871 port (Port 1). Each of these devices are assigned with unique address 1-5 (via device settings), and I'm trying to read some values from these analyzers (in device communication protocol manual, it says that holding registers are starting from address 0). However, I don't know what is the procedure: do I have to initialize slave device, or do I have to initialize the master device first, how to show obtained values on front panel (i tried to create indicator, but without any success), who sends the read query - labview application on my crio or initialized master etc.
Thanks in advance!
Best regards,
Marko Gulin
Hey Marko,
I think S1ack did an excellent job of describing the basic process for using the code--a state machine of some form or another really is usually the best way to handle modbus, simply because it is a network process. The function he described is also what we'd use for normal TCP or UDP, so it makes sense to do the same with modbus.
To give you a slightly different view, I wanted to point out a few things:
Not to sound like a broken record, but I would highly recommend you contact our support or sales staff and talk to them about modbus I/O servers. I/O servers have their disadvantages, but for the most common use case they are well worth the money--especially if you already have LabVIEW Real-Time or DSC. For example (from the help: http://zone.ni.com/reference/en-XX/help/371618J-01/lvmve/dsc_modbus_using/ ) you can specify a shared variable as being bound to a single-precision floating point register F3000046 and simply read (or write) that value in the code. To do the same with this library, you'd have to follow the process outlined in post 40 above.
09-24-2013 07:49 AM
S1ack, smithd,
First, thank you for your quick and excellent answers! I have one more question - since NI MAE (Measurement & Automation Explorer) cannot list slaves connected in certain COM port, is there any other way to check whether or not slave is alive? I have 4 slaves all connected in a single COM port and assigned (by device settings) with unique address 1-4. I'm afraid that slaves are not properly connected, but couldn't find the way how to check this in LV, i.e. I tried to initialize slave with some random address (lets say 50), and program didn't threw any warning/error, e.g. "slave could not be found".
Also, I checked devices factory settings (baud, parity etc.), and they all agree with the ones in MAE for COM port they are connected in.
P.S. I found out that we have install Modbus I/O Server on our cRIO 9074 - what would you suggest that we use for reading from slaves (i.e. devices) - MODBUS library or Modbus I/O Server?
Thank you!
Best regards,
Marko.
10-03-2013 10:42 PM
Hi Marko,
Sorry for not getting back to you sooner. The past few weeks have been busy.
I/O vs Lib:
For most basic use cases the I/O server is far better. It has a lot of niceties that the library does not have. However, it is limited in flexibility and performance, which is where the library shines if you use it correctly. If you intend to work your way towards high loop rates, complex architectures, etc...you may wish to start with the library. Otherwise work with the IO server. In my experience the biggest problem occurs not when using one or the other, but when switching. This is because I/O servers have certain usability features, like persistence between system reboots, which then cause problems when people don't realize that those I/O servers they stopped using a month ago are actually still running
Your core issue:
I notice you said "I tried to initialize slave with some random address". If I could, I want to make it very clear that this library allows you to create a slave instance or master instance. The slave instance would be if you want to use something like a cRIO or PXI chassis as a modbus slave. This is very common in cases where customers want to create a drop-in replacement for their PLC while also allowing for the advantages provided by the cRIO platform. In your case, it sounds like you want 4 master instances. You can generate 4 masters with different Unit ID parameters and use them to speak to all 4 slaves. If you generate 4 masters and still cannot communicate with your slaves, I recommend the following:
I'd also appreciate it if you could post back here with your results. I may not have the time to answer, but I'm definitely monitoring this forum and its nice to hear when people have success/failure and why.
Thanks,
Daniel
10-07-2013 01:26 AM
Hi Daniel,
I am using your library (LabView 2011) to build up a emulator for equipment I don't have yet. I am running the Master and Slave TCP examples in the library you provided. I am having trouble using "Fetch Input Registers" in the Master. I use "Write Multiple Input Registers" in the slave, and increase the base address (0=30001) to write to registers in the 30001-32000 range, with an input register of 100 U16 values. The "Fetch Input Registers" in the Master does not seem to be able to retrieve anything other than the first 125 U16 registers. Starting addresses <125 show data up to 125. Setting the number of inputs >125 causes disconnection, with the following errror message.
"Disconnected
Error 1 occurred at SubVI in TCP Master.lvclass:Protocol Write.vi:1->IP Data Unit.lvclass:Write ADU Packet.vi:1->Modbus Master.lvclass:Read Input Registers.vi:1->SIM_Modbus_Master.vi"
I suspect I am missing something basic.
Thanks,
Dave
10-07-2013 06:39 AM
DWS23 wrote:
Setting the number of inputs >125 causes disconnection, with the following errror message.
Thanks,
Dave
Pretty sure that is close to or at a Modbus limitation.
You will have to create another n fetch commands, in 125 word blocks, to read more than 125 words of data.
Maximum Number of Addresses Which Can be Read or Written at Once:
The modbus protocol specifies the maximum number of addresses which can be read or written at one time. This limits the amount of data which must be transferred in a single command to no more than 255 bytes. For a read command, the limit is 2000 coils or discrete inputs or 125 registers. For a write command, the limit is 1968 coils or 123 registers.
10-07-2013 05:55 PM
Thank you. I had missed that. Understanding this also cleared up my other issues.
10-10-2013 05:04 AM
Hi,
I was following the link and VIs attached on : https://decibel.ni.com/content/docs/DOC-30140 .
However each time my customer tried running the code, he was getting the error code 6101.
What could be the possible reason for the same?
Thanks