Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Mihini/modbus
< Mihini
Revision as of 10:03, 10 March 2015 by Niranjan.babu.in.bosch.com (Talk | contribs) (Created page with "== MODBUS == '''Variables''' local sched = require 'sched' local log = require 'log' local modbus=require 'modbus' local MODBUS_PORT="/dev/ttyACM0" local MODBUS_CONF={ b...")
MODBUS
Variables
local sched = require 'sched' local log = require 'log' local modbus=require 'modbus' local MODBUS_PORT="/dev/ttyACM0" local MODBUS_CONF={ baudRate = 9600 } local modbus_client
modbus.new(port, cfg, mode) : Creates a new modbus connection.
local function configModbus() modbus_client=modbus.new(MODBUS_PORT,MODBUS_CONF,"ASCII") end
modbusdev:readHoldingRegisters(sid, address, length) Read a sequence of consecutive holding registers'
local function readModbusData() local data=modbus_client:readHoldingRegisters(1,0,5) if(data~=nil) then local _, Sensor1, Sensor2 = string.unpack(buffer, "h2") print(Sensor1..Sensor2) end end
modbusdev:close()
Main Function
local function main() configModbus() while(true) do sched.wait(3) readModbusData() sched.wait(3) end end sched.run(main) sched.loop()
sched.run(main) sched.loop()