I used PCANBasic API both on Windows and Ubuntu, and PCAN_RECEIVE_EVENT works in Windows to reduce CPU Occupancy rate. BUT I didn't find a way to impletement the same result in Ubuntu.
Could someone help me?
How to use PCAN_RECEIVE_EVENT in linux with PCANBasic API
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: How to use PCAN_RECEIVE_EVENT in linux with PCANBasic AP
It is part of the PCAN-Basic for Linux package:
Code: Select all
// pcaneventread.cpp
//
// ~~~~~~~~~~~~
//
// PCANBasic Example: Event Read
//
// ~~~~~~~~~~~~
//
// ------------------------------------------------------------------
// Author : Thomas Haber (thomas@toem.de)
// Last change: 18.06.2010
//
// Language: C++
// ------------------------------------------------------------------
//
// Copyright (C) 1999-2010 PEAK-System Technik GmbH, Darmstadt
// more Info at http://www.peak-system.com
// ------------------------------------------------------------------
//
// linux@peak-system.com
// www.peak-system.com
//
// ------------------------------------------------------------------
// History:
// 07-11-2013 Stephane Grosjean
// - Move DWORD definition from "unsigned long" to "__u32" to run on 64-bits
// Kernel
// - Change initital bitrate from 250K to 500K (default pcan driver bitrate)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stdio.h>
#include <sys/time.h>
#include <asm/types.h>
#include <unistd.h>
/*
#define DWORD __u32
#define WORD unsigned short
#define BYTE unsigned char
#define LPSTR char*
*/
#include "../pcanbasic/PCANBasic.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> Main entry-point for this application. </summary>
///
/// <remarks> </remarks>
///
/// <param name="argc"> The argc. </param>
/// <param name="argv"> [in,out] If non-null, the argv. </param>
///
/// <returns> . </returns>
////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
TPCANMsg Message;
TPCANStatus Status;
unsigned long ulIndex = 0;
fd_set Fds;
Status = CAN_Initialize(PCAN_USBBUS1, PCAN_BAUD_500K, 0, 0, 0);
printf("Initialize CAN: %i\n", (int) Status);
int fd;
CAN_GetValue(PCAN_USBBUS1, PCAN_RECEIVE_EVENT, &fd,sizeof(int));
/* Watch stdin (fd 0) to see when it has input. */
FD_ZERO(&Fds);
FD_SET(fd, &Fds);
while (select(fd+1, &Fds, NULL, NULL, NULL) > 0) {
Status = CAN_Read(PCAN_USBBUS1, &Message, NULL);
if (Status != PCAN_ERROR_OK) {
printf("Error 0x%x\n", (int) Status);
break;
}
printf(" - R ID:%4x LEN:%1x DATA:%02x %02x %02x %02x %02x %02x %02x %02x\n",
(int) Message.ID, (int) Message.LEN, (int) Message.DATA[0],
(int) Message.DATA[1], (int) Message.DATA[2],
(int) Message.DATA[3], (int) Message.DATA[4],
(int) Message.DATA[5], (int) Message.DATA[6],
(int) Message.DATA[7]);
}
return 0;
}
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
Re: How to use PCAN_RECEIVE_EVENT in linux with PCANBasic AP
Hi all.
My question is (more probably refers to the test coverage):
CAN Conformance test prepares that the CAN-2.0 CAN block should work with any combination of spare fields in the frame.
This was before the era of the CAN FD.
Interest in particular is the mode of coexistence on the CAN 2.0 bus and CAN FD
How should / should / can be:
1. Can CAN frames of the CAN FD be processed by DUT CAN 2.0? Those. At the very least, it is necessary to monitor the end of the frame in order to know when arbitration begins to transfer a new frame; and here - so that the frames of the CAN FD do not cause the increment of the reception error counter in DUTe CAN 2.0.
2. Do I give out ACK with DUT CAN 2.0 after the CAN FD frame?
Maybe these things are described somewhere, but I did not read carefully - then, please, specify the source.
Sorry for my english
My question is (more probably refers to the test coverage):
CAN Conformance test prepares that the CAN-2.0 CAN block should work with any combination of spare fields in the frame.
This was before the era of the CAN FD.
Interest in particular is the mode of coexistence on the CAN 2.0 bus and CAN FD
How should / should / can be:
1. Can CAN frames of the CAN FD be processed by DUT CAN 2.0? Those. At the very least, it is necessary to monitor the end of the frame in order to know when arbitration begins to transfer a new frame; and here - so that the frames of the CAN FD do not cause the increment of the reception error counter in DUTe CAN 2.0.
2. Do I give out ACK with DUT CAN 2.0 after the CAN FD frame?
Maybe these things are described somewhere, but I did not read carefully - then, please, specify the source.
Sorry for my english
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: How to use PCAN_RECEIVE_EVENT in linux with PCANBasic AP
Your question do not fit into this category and also have nothing to do with this thread..
Please post in relevant category. But best way is to google the CAN FD specification - it is free available an all your needed info is part of the specification.
Thread closed
Please post in relevant category. But best way is to google the CAN FD specification - it is free available an all your needed info is part of the specification.
Thread closed
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------