a Python script is reading frames per event using win32.event according to the PCANBasicExample.py example. The function works properly according to the following scheme: Several PCANs are connected to the PC and a PEAK with a certain ID is searched and selected.
Code: Select all
...
match = False
result = self.m_objPCANBasic.GetValue(PCAN_NONEBUS, PCAN_ATTACHED_CHANNELS)
if(result[0] == PCAN_ERROR_OK):
for channel in result[1]:
if channel.channel_condition & PCAN_CHANNEL_OCCUPIED: continue
elif channel.channel_condition & PCAN_CHANNEL_AVAILABLE:
if channel.channel_handle < 0x100:
devDevice = TPCANDevice(channel.channel_handle >> 4)
byChannel = channel.channel_handle & 0xF
else:
devDevice = TPCANDevice(channel.channel_handle >> 8)
byChannel = channel.channel_handle & 0xFF
if channel.device_id == self.device_id:
self.m_PcanHandle_write = channel.channel_handle
self.m_PcanHandle_read = self.m_PcanHandle_write + 1
match = True
break
if not match: return False
self.m_ReceiveEvent = win32event.CreateEvent(None, 0, 0, None)
...
Code: Select all
...
self.m_ReadThread = threading.Thread(None, self.CANReadThreadFunc)
self.m_ReadThread.start()
...
Code: Select all
...
stsResult = self.m_objPCANBasic.SetValue(self.m_PcanHandle_read, PCAN_RECEIVE_EVENT, self.m_ReceiveEvent)
if stsResult != PCAN_ERROR_OK:
print ("Error: " + self.GetFormatedError(stsResult))
else:
self.event_start_write.set()
endTimestamp = millis() + self.test.delay
self.count = 0
while True:
if win32event.WaitForSingleObject(self.m_ReceiveEvent, self.test.delay) == win32event.WAIT_OBJECT_0:
if not self.max_delay:
if self.ReadMessages(): break
else:
self.ReadMessages()
if millis() > endTimestamp: break
self.m_objPCANBasic.SetValue(self.m_PcanHandle_read, PCAN_RECEIVE_EVENT, 0)
...
returns the error code PCAN_ERROR_ILLPARAMVAL 0x08000stsResult = self.m_objPCANBasic.SetValue(self.m_PcanHandle_read, PCAN_RECEIVE_EVENT, self.m_ReceiveEvent)
Do the events in the different processes influence each other?
(At first I did not use an event handler for reading, i.e. I used polling. So the parallel operation worked. Only after switching to the event handler does the problem occur)
Thanks,
Martin