PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
manju
Posts: 27
Joined: Mon 24. Jun 2024, 16:09

PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API

Post by manju » Thu 30. Jan 2025, 07:51

Hello,
I am currently working with the PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API. However, I am encountering the error "Error with initializing CAN interface: 0x1400".
I have also reviewed the configuration and ensured that both the nominal and data bitrates are set correctly in PCAN-View.

I have attached the code and screenshot,
PFA the error screenshot
PFA the error screenshot
Image (5).png (181.43 KiB) Viewed 5230 times

Code: Select all


#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <stdbool.h>
#include "PCANBasic.h"
int LoadDLL();
int UnloadDLL();
bool GetFunctionAdress(HINSTANCE h_module);
typedef TPCANStatus (__stdcall *PCAN_Initialize)(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt);
typedef TPCANStatus (__stdcall *PCAN_Uninitialize)(TPCANHandle Channel);
typedef TPCANStatus (__stdcall *PCAN_Read)(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer);
typedef TPCANStatus (__stdcall *PCAN_Write)(TPCANHandle Channel, TPCANMsg* MessageBuffer);
PCAN_Initialize g_CAN_Initialize;
PCAN_Uninitialize g_CAN_Uninitialize;
PCAN_Read g_CAN_Read;
PCAN_Write g_CAN_Write;
HINSTANCE g_i_DLL;
TPCANHandle g_hChannel;
TPCANBaudrate g_Baudrate;
char g_LibFileName[] = "PCANBasic";
int LoadDLL()
{
   if(g_i_DLL == NULL)
   {
       g_i_DLL = LoadLibrary("PCANBasic.dll");
       if(g_i_DLL == NULL)
       {
           printf("ERROR: can not load pcanbasic.dll\n");
           return -1;
       }
       else
       {
           if(GetFunctionAdress(g_i_DLL) == true)
           {
               printf("Loaded functions from PCANBasic.dll\n");
           }
           else
           {
               printf("ERROR: cannot load function addresses\n");
               return -2;
           }
       }
   }
   return 0;
}
bool GetFunctionAdress(HINSTANCE h_module)
{
   g_CAN_Initialize = (PCAN_Initialize)GetProcAddress(h_module, "CAN_Initialize");
   g_CAN_Uninitialize = (PCAN_Uninitialize)GetProcAddress(h_module, "CAN_Uninitialize");
   g_CAN_Read = (PCAN_Read)GetProcAddress(h_module, "CAN_Read");
   g_CAN_Write = (PCAN_Write)GetProcAddress(h_module, "CAN_Write");
   return g_CAN_Initialize && g_CAN_Uninitialize && g_CAN_Read && g_CAN_Write;
}
int UnloadDLL()
{
   if(g_i_DLL)
   {
       FreeLibrary(g_i_DLL);
       g_CAN_Initialize = NULL;
       g_CAN_Uninitialize = NULL;
       g_CAN_Read = NULL;
       g_CAN_Write = NULL;
       return 0;
   }
   return -1;
}
int main()
{
   int ret;
   TPCANStatus CANStatus;
   TPCANMsg SendMessageBuffer;
   TPCANTimestamp TimestampBuffer;
   printf("PCAN-Basic Example\n");
   printf("Using 500k baud rate\n");
   printf("...........CAN Status - 0x%x  \n",CANStatus);
   printf("............CAN PCAN Eroor - %d \n",PCAN_ERROR_OK);

   g_hChannel = PCAN_USBBUS1;
   g_Baudrate = PCAN_BAUD_500K;
   ret = LoadDLL();
   if(ret != 0)
   {
       printf("Error loading DLL: %i\n", ret);
       return -1;
   }
   printf("status = 0%x\n",CANStatus);
   CANStatus = g_CAN_Initialize(g_hChannel, g_Baudrate, 0, 0, 0);
   if(CANStatus != PCAN_ERROR_OK)
   {
       printf("Error with initializing CAN interface: 0x%x\n", CANStatus);
       printf("%x\n",CANStatus);
       UnloadDLL();
       return -1;
   }
   printf("CAN interface initialized\n");
   printf("Sending CAN frames...\n");
   SendMessageBuffer.ID = 0x00100;
   SendMessageBuffer.LEN = 8;    
   SendMessageBuffer.MSGTYPE = PCAN_MESSAGE_STANDARD;
   SendMessageBuffer.DATA[0] = 0x01;
   SendMessageBuffer.DATA[1] = 0x02;
   SendMessageBuffer.DATA[2] = 0x03;
   SendMessageBuffer.DATA[3] = 0x04;
   SendMessageBuffer.DATA[4] = 0x05;
   SendMessageBuffer.DATA[5] = 0x06;
   SendMessageBuffer.DATA[6] = 0x07;
   SendMessageBuffer.DATA[7] = 0x08;

   CANStatus = g_CAN_Write(g_hChannel, &SendMessageBuffer);
   if (CANStatus != PCAN_ERROR_OK)
   {
       printf("Error  in sending CAN frame: 0x%x\n", CANStatus);
   }
   else
   {
       printf("CAN frame sent successfully\n");
   }
   printf("Reading CAN messages...\n");
   CANStatus = g_CAN_Read(g_hChannel, &SendMessageBuffer, &TimestampBuffer);
   if(CANStatus == PCAN_ERROR_OK)
   {
       printf("Received CAN frame with ID: 0x%x\n", SendMessageBuffer.ID);
   }
   else
   {
       printf("Error receiving CAN frame: 0x%x\n", CANStatus);
   }
   CANStatus = g_CAN_Uninitialize(g_hChannel);
   if(CANStatus != PCAN_ERROR_OK)
   {
       printf("Error uninitializing CAN channel\n");
   }

   printf("Press any key to exit...\n");
   _getch();

   UnloadDLL();
   return 0;
Thanks

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API

Post by M.Heidemann » Thu 30. Jan 2025, 08:35

Hello,

you want to use FD, however i see no FD related functions,
please refer to the documentation and use the FD related functions:
2025-01-30 08_45_16-PCAN-Basic Documentation.png
2025-01-30 08_45_16-PCAN-Basic Documentation.png (68.38 KiB) Viewed 5225 times
this error (0x1400) means that the handle is invalid, which device are you currently using?

BR
---
Marvin Heidemann
PEAK-Support Team

manju
Posts: 27
Joined: Mon 24. Jun 2024, 16:09

Re: PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API

Post by manju » Thu 30. Jan 2025, 09:57

Hello,

Currently we are using PEAK USB and it supports CAN-FD

Thanks
Thanks

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API

Post by M.Heidemann » Thu 30. Jan 2025, 10:01

Hello,

A regular PCAN-USB (IPEH-002021) would not support CAN FD,
can you show us a picture of the device?
---
Marvin Heidemann
PEAK-Support Team

manju
Posts: 27
Joined: Mon 24. Jun 2024, 16:09

Re: PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API

Post by manju » Thu 30. Jan 2025, 10:06

Hello,
We have been using that device for several other applications as well and it does support CAN-FD
https://www.peak-system.com/PCAN-USB-FD.365.0.html?&L=1

Thanks
Thanks

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: PCAN-USB FD device and trying to initialize CAN-FD communication using the PCAN Basic API

Post by M.Heidemann » Thu 30. Jan 2025, 10:10

Hello,

Ah! Okay, yes IPEH-004022 does indeed support CAN-FD.

In this case, as mentioned, please use the FD-rlated functions for InitializeFD, UninitializeFD, etc...


BR
---
Marvin Heidemann
PEAK-Support Team

Post Reply