The free CAN Software API (Application Programming Interface) for Windows®
-
Bourass
- Posts: 13
- Joined: Mon 28. Jan 2019, 18:31
Post
by Bourass » Tue 29. Jan 2019, 10:27
Hi,
i want to use this script for the sake of writing a data in CAN ,but i got many problems as outcome hence i will be happy if you could help to use this script for writing a data , i think pcanbasic.h is not working, should i add just pcanbasic.h to my headers in VS or another files?
Thansks
Code: Select all
#include <stdio.h>
#include <windows.h>
#include "PCANBasic.h"
int main(int argc, const char* argv[])
{
TPCANStatus gStatus;
tagTPCANMsg MessageBuffer;
printf("Init CAN USB-C1\n");
gStatus = CAN_Initialize(PCAN_USBBUS1, PCAN_BAUD_1M);
if (gStatus != PCAN_ERROR_OK)
{
printf("Error Init USB-C1\n");
return -1;
}
MessageBuffer.MSGTYPE = PCAN_MESSAGE_EXTENDED;
MessageBuffer.ID = 0x100;
MessageBuffer.LEN = 8;
for (int i = 0; i < 8; i++)
MessageBuffer.DATA[i] = i*i;
printf("Send Data on CAN USB-C1\n");
gStatus = CAN_Write(PCAN_USBBUS1, &MessageBuffer);
if (gStatus != PCAN_ERROR_OK)
{
printf("Error sending CAN Frame");
return -1;
}
Sleep(1000);
/
printf("Close CAN USB-C1\n");
gStatus = CAN_Uninitialize(PCAN_USBBUS1);
if (gStatus != PCAN_ERROR_OK)
{
printf("Error close USB-C1");
return -1;
}
return 0;
}
-
K.Wagner
- Software Development

- Posts: 1082
- Joined: Wed 22. Sep 2010, 13:36
Post
by K.Wagner » Tue 29. Jan 2019, 11:16
Hello,
You say
Bourass wrote:i got many problems as outcome
but, what for problems? can you initialize the channel? can you send over the channel? How are the return values of that functions?
Bourass wrote: i think pcanbasic.h is not working
before saying this it work would be better to check some things, like the return values. Note that PCAN-Basic comes together with several "well documented" project samples. Also binaries are available so that you can test the environment even before you start programming. Try using these first and check if you can communicate data.
Note also that for communicating data you need at least two participants (your application and another CAN node). You can also use the PCAN-View (CAN monitor tool - it is installed with the drivers) to tests that the communication works.
Best regards,
Keneth
-
Bourass
- Posts: 13
- Joined: Mon 28. Jan 2019, 18:31
Post
by Bourass » Tue 29. Jan 2019, 12:53
Thanks for your reply!
I understood that i should start with PCAN example or my script with PcanView to verify first the connectivity. i have question, how can i test or verify my connectivity using CAN Node and c++(script or API example c++).
i forgot , When i use pcanview+CANthe communication works,then,i have verified the communication.
thanks!
-
K.Wagner
- Software Development

- Posts: 1082
- Joined: Wed 22. Sep 2010, 13:36
Post
by K.Wagner » Tue 29. Jan 2019, 12:58
Just use the PCAN-View to send/receive messages in your CAN network. There are some videos on this that can help you:
Youtube PCAN-View Tutorials
Best regards,
Keneth
-
Bourass
- Posts: 13
- Joined: Mon 28. Jan 2019, 18:31
Post
by Bourass » Tue 29. Jan 2019, 15:23
Thanks , i have already used , i can send and recieve the data, now i want to create my script , my program
i used the programe above but still not working, how can i use it ? can you give same steps for starting programing my own program to control my PCAN.
Thanks!!
-
K.Wagner
- Software Development

- Posts: 1082
- Joined: Wed 22. Sep 2010, 13:36
Post
by K.Wagner » Tue 29. Jan 2019, 16:36
As I said in my first post,
K.Wagner wrote:what problems? can you initialize the channel? can you send over the channel? How are the return values of that functions?
Just to say that it not works doesn't help
Bourass wrote:can you give same steps for starting programing my own program to control my PCAN.
- Initialize your channel using CAN_Initialize
- Send messages using CAN_Write
- Receive messages using CAN_Read
- Close the channel when it is not needed anymore with CAN_Uninitialize
You can see how to use these functions in the sample projects, and also in the help documentation (you have a minimalistic sample of each function)
REMARK: It is just a hint but since you are using static linking (due to the name of the functions CAN_*), remember that you have to include the rith PCANBasic.lib file, according to the platform used (32/64 bit).
Best regards,
Keneth
-
Bourass
- Posts: 13
- Joined: Mon 28. Jan 2019, 18:31
Post
by Bourass » Wed 30. Jan 2019, 17:45
i got it ,i have done all steps , thanks for your relevant help!
i need now your help in how can i write a frame in hexadecimal for instance i have frame with ID=0x100
and Data=0x0400020000000000;
how can i send it , another question i need function for the sake of sending some data periodically?
many thanks
-
PEAK-Support
- Sales & Support

- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Post
by PEAK-Support » Wed 30. Jan 2019, 18:07
in your first post you wrote:
Code: Select all
MessageBuffer.MSGTYPE = PCAN_MESSAGE_EXTENDED;
MessageBuffer.ID = 0x100;
MessageBuffer.LEN = 8;
for (int i = 0; i < 8; i++)
MessageBuffer.DATA[i] = //put the Data to write in DataByte [i]//;
So what exact is your problem how to send 8 Data Bytes? It´s there
For sending in periodic time slices you need to use a timer. But this have nothing to do with our API that programming skills in Windows (MultiMedia Timer for example - search and you will find )
This Forum is for CAN related questions - if you need C/C++ programming tipps, you need to check in a C/C++ Forum.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
-
Bourass
- Posts: 13
- Joined: Mon 28. Jan 2019, 18:31
Post
by Bourass » Thu 30. May 2019, 11:16
Hi,
just i want to understand the issue that i got from my codes using pcan, i have created an application for recieving the data from my device which are connected to pcan , i got the error when i used the application but when i used the application and pcanview ( i send the data in pcanview ) the application worked perfectly

i think the isssue is related to the how should i send the data in my app , should i send it as pcanview ....i want to know how pcanview are sending data is it periodically.
i strive to enhance my app to be like pcan view
thanks and regards

-
PEAK-Support
- Sales & Support

- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Post
by PEAK-Support » Mon 3. Jun 2019, 10:10
use Windows Multimedia Timer - works fine with a sending Resolution up to 1ms
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------