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/Fc15WriteMultipleCoilsTest.php

41 lines
1.4 KiB

<?php
namespace Tests\ModbusMaster;
use PHPModbus\ModbusMaster;
class Fc15WriteMultipleCoilsTest extends MockServerTestCase
{
public function testFc15WriteMultipleCoils()
{
$mockResponse = '455000000006000f30000003';
$clientData = static::executeWithMockServer($mockResponse, function ($port) {
$modbus = new ModbusMaster('127.0.0.1', 'TCP');
$modbus->port = $port;
$this->assertTrue($modbus->fc15(0, 12288, [1, 0, 1]));
});
$packetWithoutTransactionId = substr($clientData[0], 4);
$this->assertEquals('00000008000f300000030105', $packetWithoutTransactionId);
}
public function testFc15WriteMultipleCoilsWithMultiWordPacket()
{
$mockResponse = 'a51100000006000f00000020';
$clientData = static::executeWithMockServer($mockResponse, function ($port) {
$modbus = new ModbusMaster('127.0.0.1', 'TCP');
$modbus->port = $port;
$this->assertTrue($modbus->fc15(0, 0,
[
1, 0, 1, 1, 0, 1, 1, 1,
1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
]));
});
$packetWithoutTransactionId = substr($clientData[0], 4);
$this->assertEquals('0000000b000f0000002004ed0ff0ff', $packetWithoutTransactionId);
}
}