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

23 lines
812 B

<?php
namespace Tests\ModbusMaster;
use PHPModbus\ModbusMaster;
use PHPModbus\ModbusMasterUdp;
class UdpFc1ReadCoilsTest extends MockServerTestCase
{
public function testUdpFc1Read1Coil()
{
$mockResponse = '89130000000400010101';
$clientData = static::executeWithMockServer($mockResponse, function ($port) {
$modbus = new ModbusMasterUdp('127.0.0.1');
$modbus->port = $port;
usleep(50000); // no idea how to fix this. wait for server to "warm" up or modbus UDP socket will timeout. does not occur with TCP
$this->assertEquals([1], $modbus->readCoils(0, 256, 1));
}, 'UDP');
$packetWithoutTransactionId = substr($clientData[0], 4);
$this->assertEquals('00000006000101000001', $packetWithoutTransactionId);
}
}