======Modbus Library Reference======
Available in
include("/lib/uphp/modbus.inc");**Source:** [[modbus.inc|View Source]] ===== Defines ===== ^DEFINE^VALUE^ |MB_ILLEGAL_FUNCTION|-1| |MB_ILLEGAL_ADDRESS|-2| |MB_ILLEGAL_VALUE|-3| |MB_SLAVE_FAILURE|-4| ===== Functions ===== Click on the function name for further details: ^FUNCTION NAME^PARAMETER(S)^RETURN^LIBRARY^DESCRIPTION^ |[[mb_get_error_string]]|int error|string|[[modbus]]|Get human readable error description| |[[mb_set_float_be_0x10]]|int id, int bus, int reg, int val, int retries|int|[[modbus]]|Set a modbus float in big endian using function 10h| |[[mb_set_float_le_0x10]]|int id, int bus, int reg, int val, int retries|int|[[modbus]]|Set a modbus float in little endian using function 10h| |[[mb_set_int16_0x03]]|int id, int bus, int reg, int val, int retries|int|[[modbus]]|Set a modbus device register using function 03h| |[[mb_set_int16_0x10]]|int id, int bus, int reg, int val, int retries|int|[[modbus]]|Set a modbus device register using function 10h| |[[mb_set_uint32_be_0x10]]|int id, int bus, int reg, int val, int retries|int|[[modbus]]|Set a modbus UINT32 in big endian using function 10h| |[[mb_set_uint32_le_0x10]]|int id, int bus, int reg, int val, int retries|int|[[modbus]]|Set a modbus UINT32 in little endian using function 10h| ===== Example =====
// assume a modbus TCP connection on ID 1 on Channel 2
$DEBUG=1;
include("/lib/uphp/modbus.inc");
$id=1;
$bus=2;
$reg=1;
$cmd=100;
$retries=1;
$res=mb_set_int16_0x03($id, $bus, $reg, $cmd, $retries);
print("\r\nSet INT 16 func 03 result is : ".$res." ".mb_get_error_string($res));
$reg++;
$res=mb_set_int16_0x10($id, $bus, $reg, $cmd, $retries);
print("\r\nSet INT 16 func 10 result is : ".$res." ".mb_get_error_string($res));
$reg+=2;
$res=mb_set_uint32_le_0x10($id, $bus, $reg, $cmd, $retries);
print("\r\mb_set_uint32_le_0x10 result is : ".$res." ".mb_get_error_string($res));
$reg+=2;
$res=mb_set_uint32_be_0x10($id, $bus, $reg, $cmd, $retries);
print("\r\mb_set_uint32_be_0x10 result is : ".$res." ".mb_get_error_string($res));
$reg+=2;
$res=mb_set_float_le_0x10($id, $bus, $reg, $cmd, $retries);
print("\r\mb_set_float_le_0x10 result is : ".$res." ".mb_get_error_string($res));
$reg+=2;
$res=mb_set_float_be_0x10($id, $bus, $reg, $cmd, $retries);
print("\r\mb_set_float_be_0x10 result is : ".$res." ".mb_get_error_string($res));
?>