-
Notifications
You must be signed in to change notification settings - Fork 0
/
modbustcp2.php
50 lines (47 loc) · 1.8 KB
/
modbustcp2.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
<?php
require_once 'ModbusMaster.php';
require_once 'PhpType.php';
include("PhpSerialModbus.php");
if (isset($_POST["Host"]) && isset($_POST["Port"]) && isset($_POST["UnitID"]) && isset($_POST["Address"]) && isset($_POST["Quantity"]) && isset($_POST["FC"]))
{
$Host=$_POST["Host"];
$Port=$_POST["Port"];
$UnitID=$_POST["UnitID"];
$Address=$_POST["Address"];
$Quantity=$_POST["Quantity"];
$FunCode=$_POST["FC"];
//echo "Host is: $Host";
//echo "Port is: $Port";
//echo "Unit ID is: $UnitID";
//echo "Address is: $Address";
//echo "Quantity is: $Quantity";
//echo "Function Code is: $FunCode";
if ($FunCode == "5") {
$modbus = new ModbusMaster("$Host", "UDP");
try {
$recData = $modbus->writeMultipleCoils($UnitID, $Address, $Quantity);
} catch (Exception $e) {
echo $modbus;
echo $e;
echo '<a href="Modbustcp.html"><br /><br />Return to Modbus Page</a>';
exit;
}
echo PhpType::bytes2string($recData);
} elseif ($FunCode == "6") {
$modbus = new ModbusMaster("$Host", "UDP");
$data = array(10,-1000,2000,3.0);
$dataTyoes = array("WORD","INT","DINT","REAL");
try {
$recData = $modbus->writeMultipleRegister($UnitID, $Address, $data, $dataTypes);
} catch (Exception $e) {
echo $modbus . "\n";
echo $e;
echo '<a href="Modbustcp.html"><br /><br />Return to Modbus Page</a>';
exit;
}
echo PhpType::bytes2string($recData);
} else {
echo "Invalid FC";
}
}
?>