+function get_parameter(record)
+ return tonumber(get_file_content(record["path"])) * record["scale"] + record["correction"]
+end
+
+function string.fromhex(str)
+ return (str:gsub('..', function (cc)
+ return string.char(tonumber(cc, 16))
+ end))
+end
+
+function string.tohex(str)
+ return (str:gsub('.', function (c)
+ return string.format('%02X', string.byte(c))
+ end))
+end
+
+function get_mhz(record)
+ local p = record["rs232"]
+ p:read(9,100)
+ p:write(string.fromhex("ff0186000000000079"))
+ local e, s = p:read(9,1000)
+ if (e == 0) and (s:len() == 9) and (s:byte(1) == 255) then
+ local crc = 0
+ for i = 2, 8 do
+ crc = crc + s:byte(i)
+ if (crc>=256) then
+ crc = crc - 256
+ end
+ end
+ crc = 255 - crc
+ crc = crc + 1;
+ if crc == s:byte(9) then
+ return s:byte(3)*256+s:byte(4)
+ end
+ end
+
+ return nil
+
+end
+
+function search_rs232_const(rs232,prefix,value)
+
+ for k,v in pairs(rs232) do
+
+ if k == prefix..value:upper() then
+ return v
+ end
+
+ end
+
+ return nil
+
+end
+
+function init_serial_device(device,subsystem,parameters)
+
+ rs232 = require("luars232")
+
+ pcall(function ()
+
+ local e, port = rs232.open(device["port"])
+
+ local baud = device["baud"]; if baud == nil then baud = 9600; end
+ local bits = device["bits"]; if bits == nil then bits = 8; end
+ local stop_bits = device["stop_bits"]; if stop_bits == nil then stop_bits = 1; end
+ local parity = device["parity"]; if parity == nil then parity = "NONE"; end
+ local flowctl = device["flowctl"]; if flowctl == nil then flowctl = "OFF"; end
+
+ assert(port:set_baud_rate(search_rs232_const(rs232,"RS232_BAUD_",baud)) == rs232.RS232_ERR_NOERROR)
+ assert(port:set_data_bits(search_rs232_const(rs232,"RS232_DATA_",bits)) == rs232.RS232_ERR_NOERROR)
+ assert(port:set_parity(search_rs232_const(rs232,"RS232_PARITY_",parity)) == rs232.RS232_ERR_NOERROR)
+ assert(port:set_stop_bits(search_rs232_const(rs232,"RS232_STOP_",stop_bits)) == rs232.RS232_ERR_NOERROR)
+ assert(port:set_flow_control(search_rs232_const(rs232,"RS232_FLOW_",flowctl)) == rs232.RS232_ERR_NOERROR)
+
+ getparameter = {}
+
+ getparameter["rs232"] = port
+
+ if subsystem == "mhz" then
+
+ getparameter["function"] = get_mhz
+ getparameter["name"] = "CO2PPM"
+ getparameter["sensor"] = "MHZ19"
+ parameters[#parameters+1] = getparameter
+
+ end
+
+ parameters[#parameters+1] = getparameter
+
+ end)
+
+end
+
+function init_i2c_device(device,subsystem,parameters)