|
楼主 |
发表于 2013-8-30 20:46:07
|
显示全部楼层
本帖最后由 zncs520 于 2013-8-30 21:01 编辑
写了半天
#!/usr/bin/lua
io.output("/dev/ttyUSB0")
print [[
Content-Type: text/html
]]
a = string.len(string.sub(os.getenv("QUERY_STRING"),3,-1))+3
b = string.sub(os.getenv("QUERY_STRING"),3,-1)
c = string.char(0xfd,0x00,a,0x01,0x01)
n = string.char(0xfd,0x00,a,0x01,0x01),b
m = string.byte(string.sub(n,1,1))+string.byte(string.sub(n,2,2))+string.byte(string.sub(n,3,3))+string.byte(string.sub(n,4,4))+string.byte(string.sub(n,5,5))+string.byte(string.sub(b,1,1))+string.byte(string.sub(b,2,2))+string.byte(string.sub(b,3,3))+string.byte(string.sub(b,4,4))+string.byte(string.sub(b,5,5))+string.byte(string.sub(b,6,6))
print (m)
m2 = string.format("%02x ", tostring(m))
print (m2)
i = string.sub(m2,-1,-1)
z = tostring(i)
print(i)
print(b)
action = {
["C0"] = function (x) io.write(string.char(0xff,0x00,x,0x00,0xff)) end,
["C1"] = function (x) io.write(string.char(0xff,0x01,0x01,x,0xff)) end,
["C2"] = function (x) io.write(string.char(0xff,0x01,0x02,x,0xff)) end,
["C3"] = function (x) io.write(string.char(0xff,0x01,0x03,x,0xff)) end,
["C4"] = function (x) io.write(string.char(0xff,0x01,0x04,x,0xff)) end,
["C5"] = function (x) io.write(string.char(0xff,0x01,0x05,x,0xff)) end,
["C6"] = function (x) io.write(string.char(0xff,0x01,0x06,x,0xff)) end,
["C7"] = function (x) io.write(string.char(0xff,0x01,0x07,x,0xff)) end,
["C8"] = function (x) io.write(string.char(0xff,0x01,0x08,x,0xff)) end,
["C9"] = function (x) io.write(string.char(0xff,0x02,x,0x00,0xff)) end,
["YY"] = function (x) io.write(c,b,z) end,
}
action[string.sub(os.getenv("QUERY_STRING"),1,2)](string.sub(os.getenv("QUERY_STRING"),3,5))
|
|