lib.DWGetEventList in Python

Arvid Arvid

Posted on 28.02.2017 11:09

I am running in to problems when I try to implement DWGetEventList in Python 2.7.11, everything else works just fine.
I am using the latest dll and python example code from the "Developer" page.

The extra code I added looks as follows:

eventCount = lib.DWGetEventListCount()
print 'Event count',eventCount
eventList = (DWEvent * eventCount)()
print [event.event_text for event in eventList]

The returned event_text/event_type/time_stamp are all a bit weird.
Here is the first few entries I get back:
['ce - Slow storing started', 'started', ' event; Simple edge on StoringTrue [Trig=0,5-; Direction=Positive]', '', '']

How can I solve this?

Arvid -

Posted on 01.03.2017 15:47

So, I sort of solved the problem in a not so pretty way.
If you change the DWEvent class in to:

class DWEvent(Structure):
_fields_ = [("event_type", c_int),("time_stamp", c_byte*8),("event_text", c_char*200)]

So "time_stamp" is changed from a c_double to c_byte*8. Both should should have a size of 8 bytes, but c_double just doesn't work.
And then you add the following lines in DWDataReaderExample:

import struct
eventCount = lib.DWGetEventListCount()
eventList = (DWEvent * eventCount)()
if lib.DWGetEventList(byref(eventList)) != DWStatus.DWSTAT_OK.value:
DWRaiseError("DWDataReader: DWGetEventList() failed")
for i,event in enumerate(eventList):
print i,event.event_type,float(struct.unpack('d',event.time_stamp)[0]), event.event_text

"event_type" and "event_text" work just as expected but "time_stamp" has to be unpacked as it is an array of 8 bytes and not a double.

I have no idea why this works and c_double doesn't, but at least this solves the problem for me. Hope it helps!

Login to reply to this topic. If you don't have account yet, you can signup for free account .
This website uses cookies to ensure you get the best experience on our website. Learn more