ModbusMaster
This is the constructor that defines $host IP address of the object.
ModbusMaster
ModbusMaster
(String $host, String $protocol)
-
String
$host: An IP address of a Modbus TCP device. E.g. "192.168.1.1"
-
String
$protocol: Socket protocol (TCP, UDP)
fc1
Alias to readCoils method
type
fc1
(type $unitId, type $reference, type $quantity)
-
type
$unitId
-
type
$reference
-
type
$quantity
fc2
Alias to readInputDiscretes method
type
fc2
(type $unitId, type $reference, type $quantity)
-
type
$unitId
-
type
$reference
-
type
$quantity
fc3
Alias to readMultipleRegisters method.
false|Array
fc3
(int $unitId, int $reference, int $quantity)
-
int
$unitId
-
int
$reference
-
int
$quantity
fc4
Alias to readMultipleInputRegisters method.
false|Array
fc4
(int $unitId, int $reference, int $quantity)
-
int
$unitId
-
int
$reference
-
int
$quantity
fc5
Alias to writeSingleCoil method
bool
fc5
(int $unitId, int $reference, array $data, array $dataTypes)
-
int
$unitId
-
int
$reference
-
array
$data
-
array
$dataTypes
fc6
Alias to writeSingleRegister method
bool
fc6
(int $unitId, int $reference, array $data, array $dataTypes)
-
int
$unitId
-
int
$reference
-
array
$data
-
array
$dataTypes
fc15
Alias to writeMultipleCoils method
bool
fc15
(int $unitId, int $reference, array $data)
-
int
$unitId
-
int
$reference
-
array
$data
fc16
Alias to writeMultipleRegister method
bool
fc16
(int $unitId, int $reference, array $data, array $dataTypes)
-
int
$unitId
-
int
$reference
-
array
$data
-
array
$dataTypes
fc23
Alias to readWriteRegisters method.
false|Array
fc23
(int $unitId, int $referenceRead, int $quantity, int $referenceWrite, array $data, array $dataTypes)
-
int
$unitId
-
int
$referenceRead
-
int
$quantity
-
int
$referenceWrite
-
array
$data
-
array
$dataTypes
readCoils
Modbus function FC 1(0x01) - Read Coils
Reads $quantity of Coils (boolean) from reference $reference of a memory of a Modbus device given by $unitId.
void
readCoils
(type $unitId, type $reference, type $quantity)
-
type
$unitId
-
type
$reference
-
type
$quantity
readInputDiscretes
Modbus function FC 2(0x02) - Read Input Discretes
Reads $quantity of Inputs (boolean) from reference $reference of a memory of a Modbus device given by $unitId.
void
readInputDiscretes
(type $unitId, type $reference, type $quantity)
-
type
$unitId
-
type
$reference
-
type
$quantity
readMultipleInputRegisters
Modbus function FC 4(0x04) - Read Multiple Input Registers.
This function reads $quantity of Words (2 bytes) from reference $referenceRead of a memory of a Modbus device given by $unitId.
false|Array
readMultipleInputRegisters
(int $unitId, int $reference, int $quantity)
-
int
$unitId: usually ID of Modbus device
-
int
$reference: Reference in the device memory to read data.
-
int
$quantity: Amounth of the data to be read from device.
readMultipleRegisters
Modbus function FC 3(0x03) - Read Multiple Registers.
This function reads $quantity of Words (2 bytes) from reference $referenceRead of a memory of a Modbus device given by $unitId.
false|Array
readMultipleRegisters
(int $unitId, int $reference, int $quantity)
-
int
$unitId: usually ID of Modbus device
-
int
$reference: Reference in the device memory to read data (e.g. in device WAGO 750-841, memory MW0 starts at address 12288).
-
int
$quantity: Amounth of the data to be read from device.
readWriteRegisters
Modbus function FC23(0x17) - Read Write Registers.
This function writes $data array at reference $referenceWrite position of memory of a Modbus device given by $unitId. Simultanously, it returns $quantity of Words (2 bytes) from reference $referenceRead.
false|Array
readWriteRegisters
(int $unitId, int $referenceRead, int $quantity, int $referenceWrite, array $data, array $dataTypes)
-
int
$unitId: usually ID of Modbus device
-
int
$referenceRead: Reference in the device memory to read data (e.g. in device WAGO 750-841, memory MW0 starts at address 12288).
-
int
$quantity: Amounth of the data to be read from device.
-
int
$referenceWrite: Reference in the device memory to write data.
-
array
$data: Array of values to be written.
-
array
$dataTypes: Array of types of values to be written. The array should consists of string "INT", "DINT" and "REAL".
writeMultipleCoils
Modbus function FC15(0x0F) - Write Multiple Coils
This function writes $data array at $reference position of memory of a Modbus device given by $unitId.
type
writeMultipleCoils
(type $unitId, type $reference, type $data)
-
type
$unitId
-
type
$reference
-
type
$data
writeMultipleRegister
Modbus function FC16(0x10) - Write Multiple Register.
This function writes $data array at $reference position of memory of a Modbus device given by $unitId.
bool
writeMultipleRegister
(int $unitId, int $reference, array $data, array $dataTypes)
-
int
$unitId: usually ID of Modbus device
-
int
$reference: Reference in the device memory (e.g. in device WAGO 750-841, memory MW0 starts at address 12288)
-
array
$data: Array of values to be written.
-
array
$dataTypes: Array of types of values to be written. The array should consists of string "INT", "DINT" and "REAL".
writeSingleCoil
Modbus function FC5(0x05) - Write Single Register.
This function writes $data single coil at $reference position of memory of a Modbus device given by $unitId.
bool
writeSingleCoil
(int $unitId, int $reference, array $data)
-
int
$unitId: usually ID of Modbus device
-
int
$reference: Reference in the device memory (e.g. in device WAGO 750-841, memory MW0 starts at address 12288)
-
array
$data: value to be written (TRUE|FALSE).
writeSingleRegister
Modbus function FC6(0x06) - Write Single Register.
This function writes $data single word value at $reference position of memory of a Modbus device given by $unitId.
bool
writeSingleRegister
(int $unitId, int $reference, array $data, array $dataTypes)
-
int
$unitId: usually ID of Modbus device
-
int
$reference: Reference in the device memory (e.g. in device WAGO 750-841, memory MW0 starts at address 12288)
-
array
$data: Array of values to be written.
-
array
$dataTypes: Array of types of values to be written. The array should consists of string "INT", "DINT" and "REAL".
__toString
Magic method
void
__toString
()