Modbus TCP and UDP library for PHP., originally from code.google.com/p/phpmodbus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
php-modbus/tests/ModbusMaster/Fc6WriteSingleRegisterTest.php

35 lines
1.2 KiB

<?php
namespace Tests\ModbusMaster;
use PHPModbus\ModbusMaster;
class Fc6WriteSingleRegisterTest extends MockServerTestCase
{
public function testFc6WriteSingleRegister()
{
$mockResponse = 'ecd10000000600061000000f';
$clientData = static::executeWithMockServer($mockResponse, function ($port) {
$modbus = new ModbusMaster('127.0.0.1', 'TCP');
$modbus->port = $port;
$this->assertTrue($modbus->writeSingleRegister(0, 4096, [15]));
});
$packetWithoutTransactionId = substr($clientData[0], 4);
$this->assertEquals('0000000600061000000f', $packetWithoutTransactionId);
}
public function testFc6WriteSingleRegisterWith0()
{
$mockResponse = '489c00000006000510000000';
$clientData = static::executeWithMockServer($mockResponse, function ($port) {
$modbus = new ModbusMaster('127.0.0.1', 'TCP');
$modbus->port = $port;
$this->assertTrue($modbus->fc6(0, 4096, [0]));
});
$packetWithoutTransactionId = substr($clientData[0], 4);
$this->assertEquals('00000006000610000000', $packetWithoutTransactionId);
}
}