mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
fixes to modbus_packet()
This commit is contained in:
parent
6e1e4c4685
commit
5642e3283d
@ -1,5 +1,3 @@
|
|||||||
-- #REQUIRES rtu.lua
|
|
||||||
|
|
||||||
-- modbus function codes
|
-- modbus function codes
|
||||||
local MODBUS_FCODE = {
|
local MODBUS_FCODE = {
|
||||||
READ_COILS = 0x01,
|
READ_COILS = 0x01,
|
||||||
@ -178,6 +176,8 @@ function modbus_init(rtu_dev)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function modbus_packet()
|
function modbus_packet()
|
||||||
|
local MODBUS_TCP = 0
|
||||||
|
|
||||||
local self = {
|
local self = {
|
||||||
txn_id = txn_id,
|
txn_id = txn_id,
|
||||||
protocol = protocol,
|
protocol = protocol,
|
||||||
@ -187,17 +187,7 @@ function modbus_packet()
|
|||||||
data = data
|
data = data
|
||||||
}
|
}
|
||||||
|
|
||||||
local receive = function (raw)
|
local make = function (txn_id, protocol, length, unit_id, func_code, data)
|
||||||
local size_ok = #raw ~= 6
|
|
||||||
|
|
||||||
if size_ok then
|
|
||||||
set(raw[1], raw[2], raw[3], raw[4], raw[5], raw[6])
|
|
||||||
end
|
|
||||||
|
|
||||||
return size_ok and self.protocol == comms.PROTOCOLS.MODBUS_TCP
|
|
||||||
end
|
|
||||||
|
|
||||||
local set = function (txn_id, protocol, length, unit_id, func_code, data)
|
|
||||||
self.txn_id = txn_id
|
self.txn_id = txn_id
|
||||||
self.protocol = protocol
|
self.protocol = protocol
|
||||||
self.length = length
|
self.length = length
|
||||||
@ -206,6 +196,16 @@ function modbus_packet()
|
|||||||
self.data = data
|
self.data = data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local receive = function (raw)
|
||||||
|
local size_ok = #raw ~= 6
|
||||||
|
|
||||||
|
if size_ok then
|
||||||
|
make(raw[1], raw[2], raw[3], raw[4], raw[5], raw[6])
|
||||||
|
end
|
||||||
|
|
||||||
|
return size_ok and self.protocol == MODBUS_TCP
|
||||||
|
end
|
||||||
|
|
||||||
local get = function ()
|
local get = function ()
|
||||||
return {
|
return {
|
||||||
txn_id = self.txn_id,
|
txn_id = self.txn_id,
|
||||||
@ -216,4 +216,10 @@ function modbus_packet()
|
|||||||
data = self.data
|
data = self.data
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
make = make,
|
||||||
|
receive = receive,
|
||||||
|
get = get
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user