@Timer(timerno)
The @Timer function is called when a millisecond timer set with the
“SetTimer” function expires. Note that the millisecond times has nothing to
do with the timers in the configuration settings.
Parameter
Description
timerno
The number of the timer that expired (1-4)
@ModbusReply(address, command, length, data[])
This function is called when a reply is received from a Modbus device as a
result of a call to ModbusSend.
Parameter
Description
address
The modbus device address that replied
command
The modbus command number (see ModbusSend)
length
Number of bytes in the data[] array.
data[]
A byte-array with the received data as it was received over ModBus.
Note that the array starts with the byte after the command byte.
The max number of bytes that can be received in one call is 20.
Example:
mbReadReg(deviceadr, regno, regcount)
{
new
b[4 char];
regno = (regno%10000)-1;
//
Modbus address mapping
b{0} = (regno>>8)&0xFF;
//
Build command buffer
b{1} = regno&0xFF;
b{2} = (regcount>>8)&0xFF;
b{3} = regcount&0xFF;
ModbusSend
(deviceadr,
READ_REGISTERS
, 4, b); //
Queue to send
}
@Tick
(uptime)
{
if((uptime%20)==0) { //
every 20 seconds..
mbReadReg(5, 40047, 1); //
Request reg 40047 from device 5
}
}
@ModbusReply
(address, command, length, data[])
{
new
x;
//
Make sure this is a reply to the above query
if((address==5) && (
ModbusCommand
:command==
READ_REGISTERS
)) {
x = (data{1}<<8) | data{2}; //
Extract a 16 bit value
PDebug
("Read %d", x); //
Print on debug console
}
}
Page 115 of 121