We are using PCAN-UDS.dll to UDS message process and ISOTP message to concurrent communication.
It works well but sometimes "SafetyHandle closed" exception occur WaitAny function in waitHandle.cs when we release device.
I am guessing it related with device release process and our device release function is below
please advise us
Best Regards,
MH
Code: Select all
private static bool ReleaseUDSPCANDev()
{
cantp_status rtnTP = cantp_status.PCANTP_STATUS_OK;
// Close receive event
if (IntPtr.Size == 4)
{
UInt32 iBuffer = 0;
rtnTP = CanTpApi.SetValue_2016(deviceInfo.UDSDeviceHandle, cantp_parameter.PCANTP_PARAMETER_RECEIVE_EVENT, ref iBuffer, sizeof(UInt32));
}
else if (IntPtr.Size == 8)
{
Int64 buffer = 0;
byte[] byteArray = BitConverter.GetBytes(buffer);
rtnTP = CanTpApi.SetValue_2016(deviceInfo.UDSDeviceHandle, cantp_parameter.PCANTP_PARAMETER_RECEIVE_EVENT, byteArray, sizeof(UInt64));
}
if (rtnTP != cantp_status.PCANTP_STATUS_OK)
{
Log.LogStr("FAULT", "Error in set receive event.");
return false;
}
RawCANThread_UDSChk = false;
if (RawCANThread_UDS != null)
{
RawCANThread_UDS.Abort();
RawCANThread_UDS.Join();
RawCANThread_UDS = null;
Log.LogStr("Release", "Raw CAN write thread in UDS is aborted.");
}
RawCANReadEventThreadChk_UDS = false;
if (RawCANReadEventThread_UDS != null)
{
RawCANReadEventThread_UDS.Abort();
RawCANReadEventThread_UDS.Join();
RawCANReadEventThread_UDS = null;
Log.LogStr("Release", "Raw CAN receive thread in UDS is aborted.");
}
recvEvent2RawCAN_UDS.Close();
Log.LogStr("Release", "Close raw CAN receive event.");
rawCANRecvQueue_UDS.Clear();
uds_status rtn = UDSApi.Uninitialize_2013(deviceInfo.UDSDeviceHandle);
if (rtn != uds_status.PUDS_STATUS_OK)
{
Log.LogStr("FAULT", "Error in PCAN device release.");
return false;
}
deviceInfo.UDSDeviceOpened = false;
return true;
}