PHP Modbus可以使用modbus_write_multiple_registers()函數(shù)來進行數(shù)據(jù)寫入操作。以下是一個示例代碼:
$modbus = new Phpmodbus\ModbusMaster("192.168.1.1", "TCP");
// Connect to Modbus TCP/IP server
$modbus->connect();
// Define the data to be written
$data = array(100, 200, 300);
// Write the data to the Modbus server starting from address 0
$modbus->modbus_write_multiple_registers(0, $data);
// Close the connection
$modbus->disconnect();
在上面的示例中,我們首先實例化了一個ModbusMaster對象,并連接到Modbus TCP/IP服務(wù)器。然后定義了要寫入的數(shù)據(jù),這里是一個包含三個整數(shù)值的數(shù)組。接著使用modbus_write_multiple_registers()函數(shù)將數(shù)據(jù)寫入Modbus服務(wù)器的寄存器中,起始地址為0。最后斷開與服務(wù)器的連接。