【发布时间】:2021-09-10 12:25:21
【问题描述】:
我正在尝试使用 nodejs 、 php 、 html 和 css 构建一个 html scada 系统。
我的程序:我在 nodejs 中有这个 9 行的小代码;我使用此代码在 modbus rtu 协议中与 PLC 通信。如果我从终端运行,代码运行良好;
我的问题:我试图在 html 页面中使用 php 提交按钮 运行此代码,但我认为我遗漏了一些东西,因为它不起作用。
谢谢。 nodejs 代码:
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();
// open connection to a serial port
client.connectRTUBuffered("COM2", { baudRate: 9600 ,parity: "even", dataBits: 8, stopBits: 1} , write );
function write() {
client.writeCoil(22, 1);
}
html代码::
<html>
<head>
<title>PHP isset() example</title>
</head>
<body>
<form method="post">
<input type="submit" value="Sum" name="Submit1"><br/><br/>
<?php
if(isset($_POST["Submit1"]))
{
exec('write.js >/dev/null/ 2>&1 &');
}
?>
</form>
<script src="write.js" type="text/javascript" ></script>
</body>
</html>
【问题讨论】:
-
不要发布代码图片。将所有相关代码复制/粘贴到问题本身中。 Why not upload images of code/errors when asking a question?