The first time to use the Web control of an entity hardware, need to call the serial port through the Web page, groping for a while, finally selected with python+php+jquery+html implementation.
The first part: Web homepage Interface index.html
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Relay Control Testing </title>
<script src= "/public/js/jquery.js" ></script>
<script>
$ (document). Ready (function () {
$ ("input"). each (function () {
$ (this). Bind ("click", Function () {
COM ($ (this) [0].checked,$ (This). attr ("Lu"))
})
})
})
function COM (s,lu) {
$.ajax ({
Type: ' Get ',
Async:true,
TIMEOUT:20000,//20 sec
URL: "http://bsfx.longsunhd.com:60096/jdq.php?lu=" +lu+ "&s=" +s,
Data: "",
DataType: "HTML",
Success:function (HTML) {
}
});
}
</script>
<body>
<input type=checkbox on= "Fe", 98, off= "Fe, D9 C5" lu= "0" > 1th <br>
<input type=checkbox on= "Fe-C9 F5" off= "Fe" lu= "1" > 2nd road <br>
<input type=checkbox on= "Fe 2" > 3rd <br>, "off=", "F5", "a.
<input type=checkbox on= "Fe," "off=" Fe, C5 "lu=" 3 "> 4th <br>
<input type=checkbox on= "Fe, FF D9 F4" off= "Fe, 98" lu= "4" > 5th <br>
<input type=checkbox on= "Fe," off= "Fe, C9 C4" lu= "5" > 6th <br>
<input type=checkbox on= "Fe (FF)," off= "Fe, C4" lu= "6" > 7th <br>
<input type=checkbox on= "fe" FF F4 "off=" Fe (lu=) 7 "> 8th <br>"
<input type=checkbox on= "Fe, FF F7" off= "Fe," lu= "8" > 9th <br>
<input type=checkbox on= "Fe, off=" Fe, C7 "lu=" 9 "> 10th <br>".
<input type=checkbox on= "Fe 0A FF B8 PNs" off= "Fe 0A xx xx F9 C7" lu= "> 11th Road <br>
<input type=checkbox on= "Fe 0B FF E9 F7" off= "Fe 0B xx A8" lu= "> 12th <br>
<input type=checkbox on= "Fe 0C FF" off= "Fe 0C" C6 "lu=" > 13th Road <br>
<input type=checkbox on= "Fe 0D FF F6" off= "Fe 0D," lu= "> 14th <br>.
<input type=checkbox on= "Fe 0E FF F9 F6" off= "Fe 0E xx B8" lu= "> 15th <br>
<input type=checkbox on= "Fe 0F FF A8" off= "Fe 0F xx xx E9 C6" lu= "> 16th Road <br>
<input type=checkbox on= "Fe, FF, F0" off= "Fe, D8" lu= "> 17th <br>
<input type=checkbox on= "Fe-one-FF-C8-off=" Fe-xx-C0 "lu=" > 18th <br>
<input type=checkbox on= "Fe," "off=" Fe, C0 "lu=" > 19th road <br>.
<input type=checkbox on= "Fe + FF F0" off= "Fe" lu= "<br>" > 20th Road "
<input type=checkbox on= "Fe", D8 "off=" Fe, C1 "lu=" > 21st Road <br>
<input type=checkbox on= "Fe + FF-F1" off= "Fe-C8" lu= "> 22nd <br>
<input type=checkbox on= "Fe-FF-F1" off= "Fe-XX" lu= "> 23rd <br>
<input type=checkbox on= "Fe + FF" off= "Fe-xx-C1" lu= "> 24th <br>
<input type=checkbox on= "Fe," "off=" Fe, C2 "lu=" > 25th Road <br>.
<input type=checkbox on= "Fe + FF F2" off= "Fe" lu= "> 26th Road <br>".
<input type=checkbox on= "Fe 1 a FF xx B9 F2" off= "Fe 1 a xx F8" lu= "> 27th <br>
<input type=checkbox on= "Fe 1 B FF E8" off= "Fe 1 b xx A9 C2" lu= "> 28th <br>
<input type=checkbox on= "Fe 1C FF F3" off= "Fe 1C xx" lu= "> 29th Road <br>
<input type=checkbox on= "Fe 1D FF" off= "Fe 1D xx C3" lu= "> 30th Road <br>
<input type=checkbox on= "Fe 1E FF F8" off= "Fe 1E xx xx B9 C3" lu= "> 31st <br>
<input type=checkbox on= "Fe 1F FF A9 F3" off= "Fe 1F xx E8" lu= "> 32nd <br>
<br>
<input type=checkbox on= "Fe 1F FF A9 F3" off= "Fe 1F xx xx E8" lu= "> Full road <br>
</body>
Part II jdq.php
<?php
$_request[s]= ($_request[s]== "true")? 0:1;
$result =shell_exec ("D:/python/python.exe com.py $_request[lu] $_request[s]");
Part III com.py
From sys import ARGV
Import serial
Import string
Import time
Import Binascii
Import Sys
Import struct
Import re
F,lu,s = argv
Cm=[]
Cm.append ([[0xfe,0x05,0x00,0x00,0xff,0x00,0x98,0x35],[0xfe,0x05,0x00,0x00,0x00,0x00,0xd9,0xc5]])
Cm.append ([[0xfe,0x05,0x00,0x01,0xff,0x00,0xc9,0xf5],[0xfe,0x05,0x00,0x01,0x00,0x00,0x88,0x05]])
Cm.append ([[0xfe,0x05,0x00,0x02,0xff,0x00,0x39,0xf5],[0xfe,0x05,0x00,0x02,0x00,0x00,0x78,0x05]])
Cm.append ([[0xfe,0x05,0x00,0x03,0xff,0x00,0x68,0x35],[0xfe,0x05,0x00,0x03,0x00,0x00,0x29,0xc5]])
Cm.append ([[0xfe,0x05,0x00,0x04,0xff,0x00,0xd9,0xf4],[0xfe,0x05,0x00,0x04,0x00,0x00,0x98,0x04]])
Cm.append ([[0xfe,0x05,0x00,0x05,0xff,0x00,0x88,0x34],[0xfe,0x05,0x00,0x05,0x00,0x00,0xc9,0xc4]])
Cm.append ([[0xfe,0x05,0x00,0x06,0xff,0x00,0x78,0x34],[0xfe,0x05,0x00,0x06,0x00,0x00,0x39,0xc4]])
Cm.append ([[0xfe,0x05,0x00,0x07,0xff,0x00,0x29,0xf4],[0xfe,0x05,0x00,0x07,0x00,0x00,0x68,0x04]])
Cm.append ([[0xfe,0x05,0x00,0x08,0xff,0x00,0x19,0xf7],[0xfe,0x05,0x00,0x08,0x00,0x00,0x58,0x07]])
Cm.append ([[0xfe,0x05,0x00,0x09,0xff,0x00,0x48,0x37],[0xfe,0x05,0x00,0x09,0x00,0x00,0x09,0xc7]])
Cm.append ([[0xfe,0x05,0x00,0x0a,0xff,0x00,0xb8,0x37],[0xfe,0x05,0x00,0x0a,0x00,0x00,0xf9,0xc7]])
Cm.append ([[0xfe,0x05,0x00,0x0b,0xff,0x00,0xe9,0xf7],[0xfe,0x05,0x00,0x0b,0x00,0x00,0xa8,0x07]])
Cm.append ([[0xfe,0x05,0x00,0x0c,0xff,0x00,0x58,0x36],[0xfe,0x05,0x00,0x0c,0x00,0x00,0x19,0xc6]])
Cm.append ([[0xfe,0x05,0x00,0x0d,0xff,0x00,0x09,0xf6],[0xfe,0x05,0x00,0x0d,0x00,0x00,0x48,0x06]])
Cm.append ([[0xfe,0x05,0x00,0x0e,0xff,0x00,0xf9,0xf6],[0xfe,0x05,0x00,0x0e,0x00,0x00,0xb8,0x06]])
Cm.append ([[0xfe,0x05,0x00,0x0f,0xff,0x00,0xa8,0x36],[0xfe,0x05,0x00,0x0f,0x00,0x00,0xe9,0xc6]])
Cm.append ([[0xfe,0x05,0x00,0x10,0xff,0x00,0x99,0xf0],[0xfe,0x05,0x00,0x10,0x00,0x00,0xd8,0x00]])
Cm.append ([[0xfe,0x05,0x00,0x11,0xff,0x00,0xc8,0x30],[0xfe,0x05,0x00,0x11,0x00,0x00,0x89,0xc0]])
Cm.append ([[0xfe,0x05,0x00,0x12,0xff,0x00,0x38,0x30],[0xfe,0x05,0x00,0x12,0x00,0x00,0x79,0xc0]])
Cm.append ([[0xfe,0x05,0x00,0x13,0xff,0x00,0x69,0xf0],[0xfe,0x05,0x00,0x13,0x00,0x00,0x28,0x00]])
Cm.append ([[0XFE,0X05,0X00,0X14,0XFF,0X00,0XD8,0X31],[0XFE,0X05,0X00,0X14,0X00,0X00,0X99,0XC1]])
Cm.append ([[0xfe,0x05,0x00,0x15,0xff,0x00,0x89,0xf1],[0xfe,0x05,0x00,0x15,0x00,0x00,0xc8,0x01]])
Cm.append ([[0xfe,0x05,0x00,0x16,0xff,0x00,0x79,0xf1],[0xfe,0x05,0x00,0x16,0x00,0x00,0x38,0x01]])
Cm.append ([[0XFE,0X05,0X00,0X17,0XFF,0X00,0X28,0X31],[0XFE,0X05,0X00,0X17,0X00,0X00,0X69,0XC1]])
Cm.append ([[0xfe,0x05,0x00,0x18,0xff,0x00,0x18,0x32],[0xfe,0x05,0x00,0x18,0x00,0x00,0x59,0xc2]])
Cm.append ([[0xfe,0x05,0x00,0x19,0xff,0x00,0x49,0xf2],[0xfe,0x05,0x00,0x19,0x00,0x00,0x08,0x02]])
Cm.append ([[0xfe,0x05,0x00,0x1a,0xff,0x00,0xb9,0xf2],[0xfe,0x05,0x00,0x1a,0x00,0x00,0xf8,0x02]])
Cm.append ([[0xfe,0x05,0x00,0x1b,0xff,0x00,0xe8,0x32],[0xfe,0x05,0x00,0x1b,0x00,0x00,0xa9,0xc2]])
Cm.append ([[0xfe,0x05,0x00,0x1c,0xff,0x00,0x59,0xf3],[0xfe,0x05,0x00,0x1c,0x00,0x00,0x18,0x03]])
Cm.append ([[0xfe,0x05,0x00,0x1d,0xff,0x00,0x08,0x33],[0xfe,0x05,0x00,0x1d,0x00,0x00,0x49,0xc3]])
Cm.append ([[0xfe,0x05,0x00,0x1e,0xff,0x00,0xf8,0x33],[0xfe,0x05,0x00,0x1e,0x00,0x00,0xb9,0xc3]])
Cm.append ([[0xfe,0x05,0x00,0x1f,0xff,0x00,0xa9,0xf3],[0xfe,0x05,0x00,0x1f,0x00,0x00,0xe8,0x03]])
Cm.append ([[0xfe,0x0f,0x00,0x00,0x00,0x10,0x02,0xff,0xff,0xa6,0x64],[0xfe,0x0f,0x00,0x00,0x00,0x10,0x02,0x00, 0x00,0xa7,0xd4]])
#需要将硬件RTU格式命令 (hex) such as FE, FF 00 98 35, turn into bytecode form, that is, in front plus 0x, into the array form [0XFE,0X05,0X00,0X00,0XFF,0X00,0X98,0X35] to the hardware serial port, To implement the instruction process.
Try
Ser = serial. Serial (' COM3 ', 9600) #需要连接串口线后, by looking at the name of the serial port in hardware management (this is COM3).
Except
Print (' Open serial failed. ')
Exit (1)
Cmd_send=cm[int (LU)][int (s)]
S=ser.write (Cmd_send)
Print (Cmd_send)
Ser.close ()
Web Control poly-British relay jy-dam3200 code