-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodbus2.php
More file actions
33 lines (31 loc) · 1.15 KB
/
modbus2.php
File metadata and controls
33 lines (31 loc) · 1.15 KB
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
<?php
include("PhpSerialModbus.php");
if (isset($_POST["UnitID"]) && isset($_POST["Address"]) && isset($_POST["Quantity"]) && isset($_POST["FC"]))
{
$UnitID=$_POST["UnitID"];
$Address=$_POST["Address"];
$Quantity=$_POST["Quantity"];
//$FunctionCode=$_POST["FunctionCode"];
$FunCode=$_POST["FC"];
//$PortNo=$_POST["PortNo"];
//echo "Unit ID is: $UnitID";
//echo "Address is: $Address";
//echo "Quantity is: $Quantity";
//echo "FunctionCode is: $FunctionCode";
$modbus = new PhpSerialModbus;
$modbus->deviceInit('/dev/ttyUSB0',115200,'none',8,1,'none');
$modbus->deviceOpen();
//$modbus->debug = true;
$result=$modbus->sendQuery($UnitID,$FunCode,"$Address",$Quantity);
sleep(2);
//print_r($result);
$jsonresult=json_encode($result);
print_r($jsonresult);
session_start();
$_SESSION["b"]=$jsonresult;
//print "\nVoltage: ".(hexdec($result[0].$result[1])/100);
$modbus->deviceClose();
session_start();
echo '<a href="Modbus.html"><br /><br />Return to Modbus Page</a>';
}
?>