Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus MB Serial Example as Slave

Trying to communicate with a master device using the Modbus library 1.2 and LV 8.5.  We've matched all the serial parameters I think (9600, 8 data, parity None, 2 stop, no flow).  But when I run the Serial Slave example, we see nothing in the holding registers.  The master is using function 16 (write mult. registers).  Should Read All Holding Registers work then?  Master is writing to register address 0x01 if it matters. 

 

We've confirmed correct data is being sent and that the serial port (PXI-8430) is working.  I changed the serial settings in MAX as well, but are the advanced ones there critical?  Anything else to check?  Thanks.    

Message Edited by Beck45 on 03-31-2009 06:13 PM
0 Kudos
Message 1 of 10
(5,949 Views)

Hey Beck,

 

For the serial slave, I'm assuming that you're using one of the serial ports on the 8430? Is the Master device another one of the 8430's ports, or is it some other device? You might want to also verify that you're using the correct cable for your devices (some require Null Modem, some require Straight-Through). Also, what application is the Master device running in? Is it the MB Serial Master example, or is it something else? Thanks

Justin E
National Instruments R&D
0 Kudos
Message 2 of 10
(5,930 Views)
Thanks for replying.  Yes, one of the serial ports.  The master is a gateway I believe and the connector is a terminal so we can switch the wire polarity.  We confirmed with a USB adapter and a different modbus slave program that the data is being recieved correctly.  It's just the Labview program that I can't get to work. 
0 Kudos
Message 3 of 10
(5,914 Views)

Hey Beck,

 

The LabVIEW program that you are using is intended to be run with the MB Serial Example Master program. What this might mean is that the Slave program is expecting the Master to put data in one particular location, but your master is putting data in a different location and thus you aren't seeing anything in the registers on the front panel because nothing has been written to them. What I would recommend you do is open up the MB Serial Example Master program, and make sure that your Master device is writing to the same locations that the example program is. Also, are you receiving any errors with this program, or are you just not seeing the data in the registers?

Justin E
National Instruments R&D
0 Kudos
Message 4 of 10
(5,883 Views)

No, not seeing any errors, just no data.  I looked at the Master Example and it writes to registers 0-3.  Our master writes 8 registers starting at address 1.  But in both cases shouldn't Read All Holding registers in the slave program work?  Other than that, we use slave address 0x10 which the master is set to. 

 

I could probe the Serial Recieve VI to see what's being read but it's called by re-entrant reference so I can't seem to watch it.  The Basic Serial Write and Read VI is able to read data at the same port.

 

Also, I read with no parity, you have to use 2 stop bits.  We only use 1; is this a problem?

0 Kudos
Message 5 of 10
(5,859 Views)

Hey Beck,

 

Yes, you are correct in saying that Read All Holding registers should return what's been written to that space in memory. It definitely could be an issue with the different number of stop bits used between devices, so I would suggest that you match all serial parameters between the two devices. You should be able to either change the COM (slave) settings to match the master, or the master's settings to match the COM. Let me know how changing this works out

Justin E
National Instruments R&D
0 Kudos
Message 6 of 10
(5,832 Views)
I still can't get this to work.  All the serial parameters match, including stop bits, but no data appears.  Is there another VI to try?  Again I have tried another modbus monitor program using the same serial settings, same setup, on same PC and the data is there, in the holding registers.  TY for your help.
0 Kudos
Message 7 of 10
(5,754 Views)

Hi Beck,

 

I think it is best to be sure you communication is OK before looking at the MB protocol en VI's.

 

One remark; the number of stopbits is not important. Once you got things working you will see that it doesn't matter what number of stopbits you use.

 

You ModBus slave device should support the basic MB commands. One of them is the loopback command. Now take the 'Basic Serial Write and Read' example VI.

Put both string indicators in HEX display, set your serial parameters.

Fill the send data control with 0108 0000 AA55 5E94 This is the data for a loopback test. If the communication with your device is OK you should see the same data string coming back.

 

When this is OK we can start the next test. Getting one or more registers. Give me the address of a register and I get back with the data to send.

But first the loopback test. 

 

 

0 Kudos
Message 8 of 10
(5,746 Views)
Hi, we're actually using Labview as the slave; I'm using the MB Serial example VI (see above).  The master is confirmed to be sending the correct modbus messages; Labview just won't show them (see above).  Thanks.
Message Edited by Beck45 on 04-15-2009 06:19 PM
0 Kudos
Message 9 of 10
(5,719 Views)

OK, you are sure that data is send by the master.

I looked at the MB library but never used it for my MB devices. Creating a few dedicated VI's was easier then using  the lib.

 

If the LV program should act as a slave you should be able to see if data is coming in with the serial example. Did you try this? Can you show the data you receive with the serial example.

 

0 Kudos
Message 10 of 10
(5,697 Views)