Client Interface for WA_MODBUS.OCX ActiveX Control  

Name

Type

Data Type

Comments

Settings

Property

String

Set communication baud rate/parity/data bits/stop bits configuration, Example: “9600,N,8,1”

Where baud rate=9600, parity=None, data bits=8, and stop bits=1

ComPort

Property

Integer

0 : COM1

1 : COM2

2 : COM3

3 : COM4

etc.

PortOpen

Property

Boolean

Set TRUE to Open PORT, FALSE to close it

DataAddr

Property

Long

Enter absolute data address of item in MODBUS data table,

Range: (1-50,000)

NodeAddr

Property

Integer

MODBUS device Address,

Range: (1-247)

DataElement(index%)

Property

Integer

To access data elements individually

DataQty

Property

Integer

Number of elements to read or write, (for data addresses 1-30,000 Range: 1-2000, for data addresses 30,001-50,000 Range:1-250)

Busy

Property

Boolean

Returns TRUE when in the midst of a READ or WRITE transaction

MsgTimeout(milliSeconds)

Property

Integer

Timeout value in milliseconds

GetReadData(dataArray) as Integer

Method

 

Returns value is array size. Call this method to get data after READ command issued (Action(0)), and TransactioDone() event has been fired. The passed parameter dataArray should be a raw (undimensioned) INTEGER array, it will be properly dimensioned upon return.

SetWriteData(dataArray)

Method

 

Pass in array of INTEGER data to be transmitted to the device, the write will be automatically invoked without requiring a call to Action(1)

Action(invokeIndex%)

Method

 

invokeIndex=0 initiates Read

invokeIndex=1 initiates Write.

OpenPort(portStr as String) as 

          BOOLEAN

Method

 

Returns TRUE if port was actually opened, typical portStr values are “COM1”, “COM2”, “ROCKET1”, etc. This Method must be used if a custom COM port card is installed, implementing non-conventional port names.

ClosePort as BOOLEAN

Method

 

Returns TRUE if port was actually closed.

TransactionDone(commResult as Integer)

Event

 

Fires after communication transaction is complete between host and MODBUS device, or a device time-out occurs.

 

 

Application Notes:

·         Ensure the COM port is closed before changing one of the following: COM port #, baud rate, parity, data bits, data bits, or timeout value.

·         Typical order of use

1.        Configure port settings with call to Settings()

2.        Select and open port via one of two possible methods

I.                     Select port number assigning value to the property ComPort()

II.                   Open port by setting the property PortOpen = TRUE

Or

I.                     Issue call to the method OpenPort(portName) which accepts the names for both standard and custom COM ports, and opens the port and the same time.

3.        Set communication address for device via property NodeAddr()

4.        Set address of value to be READ from or to WRITE to via call to DataAddr()

5.        Set number of items to READ or WRITE via property DataQty()

6.        If writing to device, set values to be written inidividually using .DataElement(index), or set values to write by passing in an array-full of data via .SetWriteData(intArray), where intArray is an array of integers having a size as indicated by DataQty.

7.        Invoke READ or WRITE to device by issuing a call to .Action(invokeIndex)

8.        When the MODBUS message has been sent to the device, and a response has been received from the device or the device has not reponded and therefore timed-out, the OCX event TransactionDone will be fired. An indication of whether the communication transaction was successful or an error was encountered is passed as a parameter in the event.

9.        READ from or WRITE to the device as many times as needed

10.     Close port when finished with device via call to the method ClosePort() or setting the property .PortOpen=FALSE