failure to read from PCAN USB
failure to read from PCAN USB
I am using a PCAN USB interface under Linux for communication with an external device. I have written a small test program based on the c++ code (pcanread.cpp) that comes with the PCAN_Basic_Linux-2.0.2 API. Whereas init and write calls always report PCAN_ERROR_OK (i.e. no error), my attempts to read via CAN_read always give PCAN_ERROR_QRCVEMPTY.
I have tested the interface with the Windows-based PCAN monitor program, so I know my interface is working and that I can both write and read. Sending the same message via my Linux c++ program in order to read the same answer fails on the read, because of an empty queue. I attach the code I am using. the Any suggestions what could be wrong?
I have tested the interface with the Windows-based PCAN monitor program, so I know my interface is working and that I can both write and read. Sending the same message via my Linux c++ program in order to read the same answer fails on the read, because of an empty queue. I attach the code I am using. the Any suggestions what could be wrong?
- Attachments
-
- pcanwrite.cpp
- (1.84 KiB) Downloaded 881 times
Re: failure to read from PCAN USB
Hi,
please send the output of cat /proc/pcan
regards
Michael
please send the output of cat /proc/pcan
regards
Michael
Re: failure to read from PCAN USB
OK, I will do that. But it will have to wait until Wednesday this week, that's when I will have access to the hardware and test environment again. Thanks!
Re: failure to read from PCAN USB
Ok, so here is my output from dmesg and /proc/pcan:
$ dmesg
[48411.774544] pcan: Release_20140723_n (le)
[48411.774550] pcan: driver config [mod] [isa] [pci] [dng] [par] [usb] [pcc] [net]
[48411.778081] pcan: new usb adapter with 1 CAN controller(s) detected
[48411.778097] pcan: usb hardware revision = 28
[48411.836101] pcan: registered netdevice can0 for usb hw (major,minor 180,0)
[48411.836105] pcan: usb device minor 0 found
[48411.836769] usbcore: registered new interface driver pcan
[48411.837120] pcan: major 249.
$ cat /proc/pcan
*------------- PEAK-System CAN interfaces (http://www.peak-system.com) -------------
*------------- Release_20140723_n (7.12.0) Oct 16 2014 14:08:06 --------------
*------------- [mod] [isa] [pci] [dng] [par] [usb] [pcc] [net] --------------
*--------------------- 1 interfaces @ major 249 found -----------------------
*n -type- ndev --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32 usb can0 ffffffff 001 0x0014 000076e6 00016599 0000443c 00000000 0x0000
Note added: in the meantime I have rebuilt the driver with 'make NET=NO' see below. Problem persists...
$ dmesg
[48411.774544] pcan: Release_20140723_n (le)
[48411.774550] pcan: driver config [mod] [isa] [pci] [dng] [par] [usb] [pcc] [net]
[48411.778081] pcan: new usb adapter with 1 CAN controller(s) detected
[48411.778097] pcan: usb hardware revision = 28
[48411.836101] pcan: registered netdevice can0 for usb hw (major,minor 180,0)
[48411.836105] pcan: usb device minor 0 found
[48411.836769] usbcore: registered new interface driver pcan
[48411.837120] pcan: major 249.
$ cat /proc/pcan
*------------- PEAK-System CAN interfaces (http://www.peak-system.com) -------------
*------------- Release_20140723_n (7.12.0) Oct 16 2014 14:08:06 --------------
*------------- [mod] [isa] [pci] [dng] [par] [usb] [pcc] [net] --------------
*--------------------- 1 interfaces @ major 249 found -----------------------
*n -type- ndev --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32 usb can0 ffffffff 001 0x0014 000076e6 00016599 0000443c 00000000 0x0000
Note added: in the meantime I have rebuilt the driver with 'make NET=NO' see below. Problem persists...
Last edited by molberg on Wed 12. Nov 2014, 11:28, edited 1 time in total.
Re: failure to read from PCAN USB
So I can see from /proc/pcan that I have carried out reads, and the read counter increases by one every time I run my little test application, just as expected.
So why can't I retrieve the byte I am reading, but keep getting PCAN_ERROR_QRCVEMPTY errors?
So why can't I retrieve the byte I am reading, but keep getting PCAN_ERROR_QRCVEMPTY errors?
Re: failure to read from PCAN USB
I re-compiled my small test program with logging enabled, here is the output:
$ cat PCANBasic.log
Wed Nov 12 10:42:51 2014 - «____________________________________»
Wed Nov 12 10:42:51 2014 - « PCAN-Basic Log »
Wed Nov 12 10:42:51 2014 - «____________________________________»
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_GetErrorText' - RESULT: 0x00
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Initialize'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Initialize: Channel: 0x51, Btr0Btr1: 20, HwType: 0x00000000, IOPort: 0x00000000, Interrupt: 0x00000000
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Initialize' - RESULT: 0x00
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Write'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Write: Channel: 0x51, MessageBuffer: 0x0xbf955434
Wed Nov 12 10:42:51 2014 - CHANNEL 0x51 (OUT) ID=0x520001 Len=0, Data=0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Write' - RESULT: 0x00
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Read'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Read: Channel: 0x51, MessageBuffer: 0x0xbf955434, TimestampBuffer: 0x(nil)
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Read' - RESULT: 0x20
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Write'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Write: Channel: 0x51, MessageBuffer: 0x0xbf955434
Wed Nov 12 10:42:51 2014 - CHANNEL 0x51 (OUT) ID=0x514100 Len=1, Data=0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Write' - RESULT: 0x00
Wed Nov 12 10:42:52 2014 - ENTRY 'CAN_Write'
Wed Nov 12 10:42:52 2014 - PARAMETERS of CAN_Write: Channel: 0x51, MessageBuffer: 0x0xbf955434
Wed Nov 12 10:42:52 2014 - CHANNEL 0x51 (OUT) ID=0x514100 Len=1, Data=0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Wed Nov 12 10:42:52 2014 - EXIT 'CAN_Write' - RESULT: 0x00
$ cat PCANBasic.log
Wed Nov 12 10:42:51 2014 - «____________________________________»
Wed Nov 12 10:42:51 2014 - « PCAN-Basic Log »
Wed Nov 12 10:42:51 2014 - «____________________________________»
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_GetErrorText' - RESULT: 0x00
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Initialize'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Initialize: Channel: 0x51, Btr0Btr1: 20, HwType: 0x00000000, IOPort: 0x00000000, Interrupt: 0x00000000
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Initialize' - RESULT: 0x00
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Write'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Write: Channel: 0x51, MessageBuffer: 0x0xbf955434
Wed Nov 12 10:42:51 2014 - CHANNEL 0x51 (OUT) ID=0x520001 Len=0, Data=0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Write' - RESULT: 0x00
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Read'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Read: Channel: 0x51, MessageBuffer: 0x0xbf955434, TimestampBuffer: 0x(nil)
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Read' - RESULT: 0x20
Wed Nov 12 10:42:51 2014 - ENTRY 'CAN_Write'
Wed Nov 12 10:42:51 2014 - PARAMETERS of CAN_Write: Channel: 0x51, MessageBuffer: 0x0xbf955434
Wed Nov 12 10:42:51 2014 - CHANNEL 0x51 (OUT) ID=0x514100 Len=1, Data=0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Wed Nov 12 10:42:51 2014 - EXIT 'CAN_Write' - RESULT: 0x00
Wed Nov 12 10:42:52 2014 - ENTRY 'CAN_Write'
Wed Nov 12 10:42:52 2014 - PARAMETERS of CAN_Write: Channel: 0x51, MessageBuffer: 0x0xbf955434
Wed Nov 12 10:42:52 2014 - CHANNEL 0x51 (OUT) ID=0x514100 Len=1, Data=0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Wed Nov 12 10:42:52 2014 - EXIT 'CAN_Write' - RESULT: 0x00
Re: failure to read from PCAN USB
I rebuilt the driver with "make NET=NO", here is the new output from /proc/pcan
$ cat /proc/pcan
*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20140723_n (7.12.0) Nov 12 2014 11:18:03 --------------
*---------------- [mod] [isa] [pci] [dng] [par] [usb] [pcc] -----------------
*--------------------- 1 interfaces @ major 249 found -----------------------
*n -type- ndev --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32 usb -NA- ffffffff 001 0x0014 00000001 00000001 00000c13 00000000 0x0000
but still my CAN_read's return empty buffer codes, i.e. 0x20.
$ cat /proc/pcan
*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20140723_n (7.12.0) Nov 12 2014 11:18:03 --------------
*---------------- [mod] [isa] [pci] [dng] [par] [usb] [pcc] -----------------
*--------------------- 1 interfaces @ major 249 found -----------------------
*n -type- ndev --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32 usb -NA- ffffffff 001 0x0014 00000001 00000001 00000c13 00000000 0x0000
but still my CAN_read's return empty buffer codes, i.e. 0x20.
Re: failure to read from PCAN USB
Some more info:
If I put the reading part in a separate program and start this before I do the write from my test program, I can see the expected resonses being dumped in my terminal. So does this mean that CAN_write and CAN_read calls need to be run in different programs/threads? All I want is to do sequential write-read-write-read-...
If I put the reading part in a separate program and start this before I do the write from my test program, I can see the expected resonses being dumped in my terminal. So does this mean that CAN_write and CAN_read calls need to be run in different programs/threads? All I want is to do sequential write-read-write-read-...
Re: failure to read from PCAN USB
Seems to work now, don't ask why 

Re: failure to read from PCAN USB
HI,
when using the chardev driver, you cannot use different applications at the same time for the same device, because there is no "dispatcher" there like in Netdev, which will provide the received data to all connected applications. A read in chardev mode will remove the data from the driver, so no other application will receive it anymore than!
That`s chardev!
Please use the SocketCAN/Netdev driver to be able to run several apps on the same device
regards
Michael
when using the chardev driver, you cannot use different applications at the same time for the same device, because there is no "dispatcher" there like in Netdev, which will provide the received data to all connected applications. A read in chardev mode will remove the data from the driver, so no other application will receive it anymore than!
That`s chardev!
Please use the SocketCAN/Netdev driver to be able to run several apps on the same device
regards
Michael