CAN lib not duplex in FlexCAN driver for VF61

CAN lib not duplex in FlexCAN driver for VF61

The driver does not support transmitting while waiting for read to timeout.
Also, the send function does not distinguish between error and timeout.
I use the following construct:

void CANThread(LPVOID lpVoid){

   tCanMsg  canmsg;
   
   while(!g_fExitApp){
      canmsg.dataLen = 8;
      if(VybCan_Read(g_hCAN, &canmsg)){
         // process msg
      }
   }
}

BOOL SendCAN(DWORD dwMsgID, DWORD dwLen, BYTE* bData){

   tCanMsg canmsg;

   canmsg.id          = dwMsgID;
   canmsg.canMsgFlags = 0;
   canmsg.dataLen     = dwLen;
   memcpy(canmsg.data, bData, dwLen);

   return VybCan_Write(g_hCAN, &canmsg);
}

VybCan_Write() is a blocking call, and returns when VybCan_Read() times out. I have to set the timeout to a very short time, say 50ms, to give the appearance of duplex. Is this the best work around?

@ebba,

Please refer this page : https://www.toradex.com/community/questions/15847/can-library-from-tdxalllibrariesdll-for-apalis-t30.html, it is relevant to your implementation.

Please use debug library, it will print debug messages on the console if there is any error.

CAN library doesn’t support thread-safe. Please implement it in your application code.

Let me know if you need further assistance on this.

Thank you Raja. If the library function uses WaitForSingleObject(), I then assume it’s safe to use a timeout as low as a few ms – similar to what the other poster did – without degrading performance.

@ebba,

There is an IST thread to read CAN packets from controller push into MsgQueue. Can_Read will read it from MsgQueue and then returning to the application layer with timeout input parameter.