Hi,
I am currently trying to create a DIA project which grabs MODBUS data and pushes it onto DeviceCloud. I’ve been able to successfully read all analogue values (16 bit integers) and push them to the cloud without a problem. i.e.
- name: mbus
driver: devices.modbus.mbus_udp_device:MBusUDPDevice
settings:
poll_rate_sec: 15
udp_peer: “(‘127.0.0.1’,502)”
trace: “debug”
round: 2
poll_list:
- poll: “PLC_AI”
pollinfo:
uid: 1
fnc: 3
ofs: 1
cnt: 4
channels:
- parse:
nam: “Blade_angle”
ofs: 0
frm: “H”
The problem I am having is that digital values have been coded into a 16 bit integer (i.e. 1000 0010 0101 1111). I can read the value fine as a single integer, But how do I split out these individual bits as individual boolean channels?
I’ve tried the following but it doesn’t quite work:
- poll: “PLC_DI”
pollinfo:
uid: 1
fnc: 3
ofs: 0
cnt: 1
- parse:
nam: “0”
ofs: 0
frm: “H”
typ: “bool”
expr: “bool(%d&1)”
- parse:
nam: “1”
ofs: 0
frm: “H”
typ: “bool”
expr: “bool(%d&2)”
- parse:
nam: “2”
ofs: 0
frm: “H”
typ: “bool”
expr: “bool(%d&4)”
Any help would be greatly appreciated.