Simulator API

<< Click to Display Table of Contents >>

Navigation:  Modbus Universal MasterOPC Server > Description of the Mod_RSSim Simulator > Script Automation >

Simulator API

Simulator API

mbul_mail GetRegisterValue (REG_TYPE as long , ADDRESS as long) As int

mbul_mail SetRegisterValue (REG_TYPE as long, ADDRESS as long, REGISTERVALUE as long) As none

mbul_mail DisableStation (STATIONID as int) As none

mbul_mail EnableStation (STATIONID as int) As None

mbul_mail DisplayAbout( ) As None

mbul_mail GetLastRunTime( ) As long

mbul_mail StationEnabled (STATIONID as int) As long

mbul_mail TransmitRegisters (STATIONSRC as int, STATIONDEST as int, REG_TYPE as long, ADDRESS as long, REGISTERS as long) As long

mbul_mail AddDebugString (STATIONID as string) As None

mbul_mail TransactionBusy () As long

mbul_mail Example of a script

In addition to general functions (see Language Help ), the following API simulator functions may be used in a script.

GetRegisterValue (REG_TYPE as long , ADDRESS as long) As int

Returns the current value in the Modbus/AB register specified:

mbul   REG_TYPE = register type 0=input, 1=output, 2=analog in, 3=holding reg. 4=extended reg. (For AB, this is the file #.)

mbul   ADDRESS = register or I/O point number (Zero always corresponds to the first item.)

E.g. 0 is similar to 40001 if REG_TYPE is 3

E.g. 63 would be 64th output coil if REG_TYPE=1

SetRegisterValue (REG_TYPE as long, ADDRESS as long, REGISTERVALUE as long) As none

Set the value in the Modbus/AB register specified.

mbul   REG_TYPE = register type 0=input, 1=output, 2=analog in, 3=holding reg. 4=extended reg. (For AB, this is the file #.)

mbul   ADDRESS = register or I/O point number (Zero always corresponds to the first item.)

E.g. 0 is similar to 40001 if REG_TYPE is 3

E.g. 63 would be 64th output coil if REG_TYPE=1

mbul   REGISTERVALUE = register value, permitted range (-32767 to +32767) other values are clipped, and thus undefined

DisableStation (STATIONID as int) As none

Disable a Modbus slave station. This function can be used to take the station out of the ring, as if it was not present in the system/network

mbul   STATIONID = Modbus station number (valid values 0 to 255; 0 = broadcast station)

EnableStation (STATIONID as int) As None

Enable a Modbus slave station. This function can be used to restore a station to the ring (see also DisableStation (STATIONID as int) As none ).

mbul   STATIONID = Modbus station number (valid values 0 to 255; 0 = broadcast station)

DisplayAbout( ) As None

Display the application about box (see Built-In Help ), the script is suspended until the "About" window is closed by the user.

GetLastRunTime( ) As long

Return the duration in milliseconds that it took for the last execution of the script. This value will be -1 on the first script execution, or if the scrip fails to execute to completion without errors.

StationEnabled (STATIONID as int) As long

Return the enable state of the station (0=disabled, 1=enabled).

mbul   STATIONID = Modbus station number (valid values 0 to 255; 0 = broadcast station)

TransmitRegisters (STATIONSRC as int, STATIONDEST as int, REG_TYPE as long, ADDRESS as long, REGISTERS as long) As long

Sends a value to the desired slave PLC (simulation must be in and support master mode.)

This function is currently not supported on MODBUS.

mbul   STATIONSRC = Allen-Bradley Source station (ignored for Modbus protocol).

mbul   STATIONDEST = destination or target station ID register type 0=input, 1=output,2=analog in, 3=holding reg. 4=extended reg. (For AB, this is the file #)

mbul   REG_TYPE = register type 0=input, 1=output, 2=analog in, 3=holding reg. 4=extended reg. (For AB, this is the file #)

mbul   ADDRESS = register or I/O point number (Zero always corresponds to the first item.)

E.g. 0 is similar to 40001 if REG_TYPE is 3

E.g. 63 would be 64th output coil if REG_TYPE=1

mbul   REGISTERS = number of registers to transmit, protocol specific framing or PDU limits are not tested before sending.

AddDebugString (STATIONID as string) As None

Sends text to the communications debugger, the text will appear with a double hash ## in front of it.

TransactionBusy () As long

Returns TRUE if this simulation device supports master-mode, and is busy with a transaction at this time.

Example of a script

The sample code illustrates how to increment a few registers, and also turn the communication for the 1st 12 stations on and off continuously. The script runs on every animation update.

dim x

dim n

dim runtime

dim station

n=0

for n=0 to 240

x = getregistervalue(3,n)

SetRegisterValue 3, n, x+1

next

runtime = Getlastruntime

SetRegisterValue 3, 241, runtime

if (StationEnabled (station)) then

Disablestation station

else

enablestation station

end if

SetRegisterValue 3, 242, station

station = station + 1

if station > 12 then station = 0