Modbus Master Sequence Help


bheskitt

Recommended Posts

I have successfully set up a channel to read a value from a plc that is set up as a modbus slave.  The channel parameters are like this:

 

Channel Name:    Device Type    D#        I/O Type:                       Chn #:    Timing:

time1                  plc                  1          Read Holding U16 (3)     43001     1.00

 

This works fine.  I then tried to use a sequence (so I can read many channels at once), but it doesn't even communicate (according to COMM monitor).  The sequence is below:

 

while (1)

Private.data = Device.plc.ReadHoldingRegistersUSI(1,43001,3)

reg1.AddValue(Private.data[0][0])

delay(1)

endwhile

 

reg1 is a channel I set up with a timing of 0 (zero).  Again, there is not activity on the comm monitor (and there is when I used the channel method to connect), and reg1 never shows data.  I have also tried 3001 and 1 in the ReadHoldingRegisters command instead of 43001.

 

Any suggestions?

 

Thanks,

Brian

 

Link to comment
Share on other sites

You are using the wrong function.  The one you are using I think is from the old (i.e. > 5 years) driver.  The current modbus driver uses:

 

ReadHoldingU16(1, 43001, 3)

 

A few things:

1) I'm assuming you are using a newer version of DAQFactory, (i.e. >= 5.30 I believe).  I'm pretty sure of this because the old modbus driver wasn't called "plc"

2) You don't need to use script to block your channel reads.  If you had three channels, all with the same D# and I/O type, and sequential Chn #'s, DAQFactory will block the query into a single query to the device.  Note that with 32 bit types, the chn #'s need to skip by 2 since 32 bit values use two registers.

3) FYI: 43001's equivilent is 3000, not 3001 or 1.  Strip the 4 and subtract 1.  You want to use one method or another, not both, so I'd just stick with 43001.

Link to comment
Share on other sites

Many thanks,

 

Follow up questions:

 

plc is the device I set up using "quick - device configuration".  I specified it as a modbusRTU protocol on a serial port I named "mod1".  Do I not insert my device name "plc" in the read command?

 

I am using version 5.87 of Daqfactory.

 

I will use the channel method as you said since it will accomplish the same thing - one command to get all the channels.  However, I will use your information just so I know how to make the script work in case that is needed in the future.

 

Just a note for the document editors:  ReadHoldingRegistersUSI is the function still cited in the help file for version 5.87.

 

I already just changed the ReadHoldingRegistersUSI to ReadHoldingU16, and it works fine.  Many thanks again.

 

Brian

 

Link to comment
Share on other sites

I typed "modbus" in the search function in the help within Daqfactory.  The second link that came up simply said "modbus device".  It doesn't refer to any specific section of the help file.  The first sentence says modbus is a legacy device and the second sentence referres you to the Modbus Protocol under serial/ethernet communications.  I now see that If I had went to that section it referred to, I would have been fine.

 

However, the next paragraph starts off with fairly detailed information about modbus, and implementing it in Daqfactory. So I read further and followed that information.

 

This section doesn't appear to be part of the help "contents" tab, but might just be a holdover document from earlier versions of the help that didn't get deleted.

 

Hope that helps,

 

Best,

Brian

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.