PCBUSB-Library icon indicating copy to clipboard operation
PCBUSB-Library copied to clipboard

Reciving frames working sporadictly on macOS Tahoe

Open tlbdk opened this issue 3 months ago • 2 comments

Hi,

First off, thanks for the macOS support for PCAN.

I'm trying to use the library but ran into some issues with reading frames so isolate the issues i tried running the samples, pcbusb_recv and pcbusb_send.

The only changes i did was change the baud rate to 500kbit, get the both to use PCAN_USBBUS1 and add some extra printf.

I'm using two PCAN FD USB connected together, one shared with a Parallels VM running Windows with PCAN View and the other on macOS. I have set PCAN View to send a frame every second and I can see some frames once in a while when starting pcbusb_recv.

tlb@mac C++ % make && ./pcbusb_recv
make: Nothing to be done for `all'.
Initialize CAN: 0x0
Read
Read done: 0x20
Select
^CError: Interrupted system call
tlb@mac C++ % make && ./pcbusb_recv
make: Nothing to be done for `all'.
Initialize CAN: 0x0
Read
Read done: 0x20
Select
^CError: Interrupted system call
tlb@mac C++ % make && ./pcbusb_recv
make: Nothing to be done for `all'.
Initialize CAN: 0x0
Read
Read done: 0x20
Select
Read
Read done: 0x0
  - R ID: 200 LEN:6 DATA:11 22 cc dd ee ff 00 00
Read
Read done: 0x0
  - R ID: 200 LEN:6 DATA:11 22 cc dd ee ff 00 00
Read
Read done: 0x20
Select

pcbusb_send works without issue an I can see the frames in PCAN View in the Windows VM.

tlbdk avatar Oct 06 '25 15:10 tlbdk

Thanks for your detailed report and for testing the examples.

The messages you see (Error: Interrupted system call) are expected when stopping the tool with Ctrl+C – this is just perror() printing the EINTR result from select().

The value 0x20 returned from read() means no data available at that moment, which is normal when only a single CAN frame per second is present on the bus.

The sample tools (pcbusb_recv, pcbusb_send) are minimal demonstrations of the API. They do not include polling, buffering, or continuous monitoring logic – they simply read frames when the driver reports an event.

Since you are sending one frame per second from the VM, it is expected that pcbusb_recv only prints data occasionally.

The fact that pcbusb_send works and that you receive correct frames confirms that the library is working correctly.

If you need a continuous stream for testing, try increasing the transmit rate in PCAN-View or send frames from macOS at a higher frequency.

mac-can avatar Nov 18 '25 09:11 mac-can

Sorry, maybe i was not clear with the timing between invocations of "pcbusb_recv", each is running for 10-30 seconds and as you can see on the first and the second it is stuck on the select call and never returns any frames even if it should have printed at least 10 frames. The third invocation of "pcbusb_recv" gives a couple of frames and the hangs again.

Also looking at the code the CAN_Read should have returned a frame when I started "pcbusb_recv" as the interface would have buffered the last couple of frames, this is at least what I'm seeing when using the PCANBasic dll on Windows.

 while (running) {
        printf("Read\n");
        status = CAN_Read(PCAN_CHANNEL, &message, NULL);
        printf("Read done: 0x%x\n", status);
        if (status == PCAN_ERROR_OK) {
            if (!(message.MSGTYPE & PCAN_MESSAGE_STATUS))
                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]);
        } else if (status == PCAN_ERROR_QRCVEMPTY) {
            // block until at least one CAN message has been received
            printf("Select\n");
            if (select(fdes+1, &rdfs, NULL, NULL, NULL) < 0)
                perror("Error");
        } else {
            printf("Error 0x%x\n", status);
            break;
        }
    }

My own code is running on Linux using socketcan with epool and the PCANBasic dll on Windows with WaitForSingleObject, on mac I have implemented your library with kevent and I'm seeing the same issues as with "pcbusb_recv" of only once in a while getting some frames.

tlbdk avatar Nov 18 '25 10:11 tlbdk