-
Notifications
You must be signed in to change notification settings - Fork 54
/
WriteMultipleRegistersResponse.php
60 lines (52 loc) · 1.53 KB
/
WriteMultipleRegistersResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
namespace ModbusTcpClient\Packet\ModbusFunction;
use ModbusTcpClient\Packet\ModbusPacket;
use ModbusTcpClient\Packet\StartAddressResponse;
use ModbusTcpClient\Utils\Endian;
use ModbusTcpClient\Utils\Types;
/**
* Response for Write Multiple Registers (FC=16)
*
* Example packet: \x01\x38\x00\x00\x00\x06\x11\x10\x04\x10\x00\x03
* \x01\x38 - transaction id
* \x00\x00 - protocol id
* \x00\x06 - number of bytes in the message (PDU = ProtocolDataUnit) to follow
* \x11 - unit id
* \x10 - function code
* \x04\x10 - start address
* \x00\x03 - count of registers written
*
*/
class WriteMultipleRegistersResponse extends StartAddressResponse
{
/**
* @var int number of registers written
*/
private int $registersCount;
public function __construct(string $rawData, int $unitId = 0, int $transactionId = null)
{
parent::__construct($rawData, $unitId, $transactionId);
$this->registersCount = Types::parseUInt16(substr($rawData, 2, 2), Endian::BIG_ENDIAN);
}
public function getFunctionCode(): int
{
return ModbusPacket::WRITE_MULTIPLE_REGISTERS;
}
/**
* @return int
*/
public function getRegistersCount(): int
{
return $this->registersCount;
}
protected function getLengthInternal(): int
{
return parent::getLengthInternal() + 2; //registersCount is 2 bytes
}
public function __toString(): string
{
return parent::__toString()
. Types::toRegister($this->registersCount);
}
}