Question

I am working on a large scale embedded system built using Python and we are using ZeroMQ to make everything modular. I have sensor data being sent across a ZeroMQ serial port in the form of the python Dictionary as shown here:

accel_com.publish_message({"ACL_X": ACL_1_X_val})

Where accel_com is a Communicator class we built that wraps the ZeroMQ logic that publishes messages across a port. Here you can see we are sending Dictionaries across.
However, on the other side of the communication port, I have another module that grabs this data using this code:

accel_msg = san.get_last_message("sensor/accelerometer")
accel.ax = accel_msg.get('ACL_X')
accel.ay = accel_msg.get('ACL_Y')
accel.az = accel_msg.get('ACL_Z')

The problem is when I try to treat accel_msg as a Python Dictionary, I get an Error:

'NoneType' object does not have a method 'get()'.  

So my guess is the dictionary is not going across the wire correctly. I am not very familiar with Python so I am not sure how to solve this problem.

Was it helpful?

Solution

Expanding on @JoranBeasley's comment:

accel_msg is sometimes None, such as while it's waiting for a message. The solution is to skip over None messages

while True:              # waiting indefinitely for messages
    accel_msg = san.get_last_message("sensor/accelerometer")
    if accel_msg:        # or more explicitly, if accel_msg is not None:
        accel.ax = accel_msg.get('ACL_X')
        accel.ay = accel_msg.get('ACL_Y')
        accel.az = accel_msg.get('ACL_Z')
        break            # if you only want one message. otherwise remove this
    else:
        print accel_msg  # which is almost certainly None
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top