Home/Support/Support Forum/Extracting bit values into DIA channels from a MODBUS value
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Extracting bit values into DIA channels from a MODBUS value

0 votes
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.
asked Feb 18, 2016 in Python by stirlsilver New to the Community (3 points)

Please log in or register to answer this question.

2 Answers

0 votes
try using the bit to hex converter options in python.
answered Feb 19, 2016 by mvut Veteran of the Digi Community (11,450 points)
0 votes
Thanks for the assistance mvut. I ended up figuring it out. I created a transform for each bit and used the following expressions:
(c[0]&(1<<8))!=0
(c[0]&(1<<9))!=0
(c[0]&(1<<10))!=0

And so on.
answered Feb 25, 2016 by stirlsilver New to the Community (3 points)
...