beautypg.com

B&B Electronics MODSCAN32 - Manual User Manual

Page 44

background image

44

OLE Automation

An optional feature of ModScan32 is the ability to access modbus data using OLE Automation routines.
This allows custom programs to be generated, (using Visual Basic, Excel Basic, etc.,), to interpret and
format data according to your specific requirements. OLE Automation routines provide both read and write
access to one or more modbus slave devices through the ModScan application.

Using the OLE Automation routines is a very simple process:

The VBA application links to the ModScan32.tlb file, (Type Library), which details the names for each
automation procedure and its argument list. From the Visual Basic development framework, this is done by
selecting the menu item to include a custom type library and then browsing for ModScan32.tlb. During the
initial Form Load operation, the application must call Create Object as follows:

CreateObject("ModScan32.Document")

The application then creates one or more PollRequests which define an array of data points to be read from
a modbus device. Data defined by the Poll Request will be automatically scanned by the ModScan
application on a 1 second basis. (NOTE: The ModScan application must be connected to the modbus
network prior to the VBA application starting up.)

The application uses the handle returned from the CreatePollRequest procedure to access, (read or write), a
value within the defined array.

During application termination, it must free the memory used by the ModScan application to maintain the
data points by deleting any Poll Requests created.

Refer to the Visual Basic Example application included with the ModScan distribution files for additional
details.

OLE Automation Routines


The following OLE Automation routines are supported by ModScan32:

short CreatePollRequest (short Device, long Address, short Length)

Arguments:

Device - Specifies the slave device address
Address - Specifies the data point address,(in modbus master (5 digit) format.

coil status addresses:

00000-09999

input status addresses:

10000-19999

input register addresses: 30000-39999
holding register addresses:

40000-49999

Length - Specifies the number of values included in the definition

Return Value:

Point Handle - Defines the array structure for future reads & writes

Notes:

Sets up data structures within ModScan to begin polling the specified data. ModScan must be
connected to the modbus network prior to creating the data array. CreatePollRequest returns a
non-zero value if the data structure was successfully created, otherwise it returns 0.

short ReadValue (short PointHandle, short Index, short *pValue)

Arguments:

Point Handle - refers to value returned from CreatePollRequest
Index - Specifies the index into the array structure
*pValue - is a pointer to a value to be returned.

Return Value: