Skip to content

Commit 4839513

Browse files
committed
Allow unit ID to be in range of 0-255.
Older MODBUS specification limited unit ID (slave id) in range of 0-247). See "Modicon Modbus Protocol Reference Guide PI–MBUS–300 Rev. J" page 19. But newer spec has that limitation removed.
1 parent 53657b3 commit 4839513

File tree

14 files changed

+21
-17
lines changed

14 files changed

+21
-17
lines changed

examples/fc1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
$startAddress = 12288;
1818
$quantity = 16;
19-
$unitID = 0;
19+
$unitID = 1;
2020
$packet = new ReadCoilsRequest($startAddress, $quantity, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2121
echo 'Packet to be sent (in hex): ' . $packet->toHex() . PHP_EOL;
2222

examples/fc15.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
0, 0, 0, 0, 0, 0, 0, 0, // dec: 0, hex x0
2121
1, 0, 0, 1 // dec: 9, hex: x9
2222
];
23-
$unitID = 0;
23+
$unitID = 1;
2424
$packet = new WriteMultipleCoilsRequest($startAddress, $coils, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2525
echo 'Packet to be sent (in hex): ' . $packet->toHex() . PHP_EOL;
2626

examples/fc16.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Types::toInt16(-1000), //hex: FC18 as word
2323
Types::toInt32(2000), //dec: 2000 -> hex: 7d00 is as 2 word 7D00 0000
2424
];
25-
$unitID = 0;
25+
$unitID = 1;
2626
$packet = new WriteMultipleRegistersRequest($startAddress, $registers, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2727
echo 'Packet to be sent (in hex): ' . $packet->toHex() . PHP_EOL;
2828

examples/fc2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
$startAddress = 12288;
1818
$quantity = 16;
19-
$unitID = 0;
19+
$unitID = 1;
2020
$packet = new ReadInputDiscretesRequest($startAddress, $quantity, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2121
echo 'Packet to be sent (in hex): ' . $packet->toHex() . PHP_EOL;
2222

examples/fc22.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
$ORMask = 0x0007; // 2 bytes, bin = 0b00000111
2424
$ORMask &= ~(1 << $bitPosition); // clear the bit, set third bit to 0. $ORMask = 0x0003, 0b00000011
2525

26-
$unitID = 0;
26+
$unitID = 1;
2727
$packet = new MaskWriteRegisterRequest(
2828
$readStartAddress,
2929
$ANDMask,

examples/fc23.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Types::toInt16(10), //000a as word
2424
Types::toInt16(-1000), //hex: FC18 as word
2525
];
26-
$unitID = 0;
26+
$unitID = 1;
2727
$packet = new ReadWriteMultipleRegistersRequest(
2828
$readStartAddress,
2929
$readQuantity,

examples/fc3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
$startAddress = 256;
2424
$quantity = 6;
25-
$unitID = 0;
25+
$unitID = 1;
2626
$packet = new ReadHoldingRegistersRequest($startAddress, $quantity, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2727

2828
try {

examples/fc4.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
$startAddress = 256;
1818
$quantity = 6;
19-
$unitID = 0;
19+
$unitID = 1;
2020
$packet = new ReadInputRegistersRequest($startAddress, $quantity, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2121
echo 'Packet to be sent (in hex): ' . $packet->toHex() . PHP_EOL;
2222

examples/fc5.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
$startAddress = 12288;
1818
$coil = true;
19-
$unitID = 0;
19+
$unitID = 1;
2020
$packet = new WriteSingleCoilRequest($startAddress, $coil, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2121
echo 'Packet to be sent (in hex): ' . $packet->toHex() . PHP_EOL;
2222

examples/fc6.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
$startAddress = 12288;
1818
$value = 55;
19-
$unitID = 0;
19+
$unitID = 1;
2020
$packet = new WriteSingleRegisterRequest($startAddress, $value, $unitID); // NB: This is Modbus TCP packet not Modbus RTU over TCP!
2121
echo 'Packet to be sent (in hex): ' . $packet->toHex() . PHP_EOL;
2222

0 commit comments

Comments
 (0)