Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

This forum covers PCAN-Linux and Linux development issues concerning our products
Locked
elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

Post by elpimous12 » Tue 2. Apr 2024, 09:50

Hello, using 3 ID's on each (CanFD M2 4 can board) port.
I'd like to read specific ID until it queue is empty, without erasing queues for others ID on same port.
Any idea ?? (C++)

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

Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

Post by M.Heidemann » Tue 2. Apr 2024, 10:17

Hello,

That's not possible on a hardware level, you either read a message from the buffer or your don't.

You can use filters to only receive certain IDs but that would not work in your case, i suppose, as this
will discard any message that is not in the filter range.

You could establish a secondary buffer in software for your use-case, however you need to make sure
that you read every incoming message on the bus into this buffer, this would prevent your buffer from being full (which will lead to lost messages)
and gives you the opportunity to be more selective with how you work with the messages received.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

Post by elpimous12 » Thu 4. Apr 2024, 18:09

clear answer,
Thanks Marvin

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

Post by elpimous12 » Thu 4. Apr 2024, 23:38

tested with a buffer (moteus_rx_msg_copy), works perfectly !!!

Code: Select all

bool YloTwoPcanToMoteus::read_moteus_RX_queue(int id, int port, float& position, float& velocity, float& torque, float& voltage, float& temperature, float& fault){
    moteus_rx_msg.ID = 0x8000 | id;

    // Créer une copie du message RX
    moteus_rx_msg_copy = moteus_rx_msg;

    do{ Status = CAN_ReadFD(port,&moteus_rx_msg_copy, NULL); 
        usleep(20);
    }

    while(Status != PCAN_ERROR_OK && Status != PCAN_ERROR_QRCVEMPTY); // is return frame received ?
        usleep(150);
        memcpy(&_position, &moteus_rx_msg_copy.DATA[MSGRX_ADDR_POSITION], sizeof(float));
        memcpy(&_velocity, &moteus_rx_msg_copy.DATA[MSGRX_ADDR_VELOCITY], sizeof(float));
        memcpy(&_torque,   &moteus_rx_msg_copy.DATA[MSGRX_ADDR_TORQUE],   sizeof(float));
        memcpy(&_voltage, &moteus_rx_msg_copy.DATA[MSGRX_ADDR_VOLTAGE], sizeof(float));
        memcpy(&_temperature, &moteus_rx_msg_copy.DATA[MSGRX_ADDR_TEMPERATURE], sizeof(float));
        memcpy(&_fault,   &moteus_rx_msg_copy.DATA[MSGRX_ADDR_FAULT],   sizeof(float));
        position    = _position;   
        velocity    = _velocity;
        torque      = _torque;
        voltage     = _voltage;
        temperature = _temperature;
        fault       = _fault;
        return true;
}
Marvin, A question, however, i should add a function who empty each port (after needed reads). how to do that ?

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

Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

Post by M.Heidemann » Fri 5. Apr 2024, 09:07

Hi,

Happy to hear that it works as expected!

You could use the parameter 'PCAN_HARD_RESET_STATUS' and set it whenever you want to clear the queues and restart the controller.
Here a excerpt from the PCANBasic parameter documentation (Page 49):
PCAN_HARD_RESET_STATUS
This parameter allows changing the behavior of the function CAN_Reset. Normally, calling
this function causes the receive and send message queues for a PCAN-Channel to be
emptied. The hardware being represented by the channel is not reset. Activating this
parameter, allows the function to additionally perform a hardware reset after discarding the
messages from the channel’s queues.
Note: Performing a hardware reset causes the CAN transceiver to go bus off for a while. This
can disturb the CAN communication for a short time, generating error frames by other
nodes, and avoiding sending/receiving messages
You will also find examples of the usage in PCANBasic parameter documentation.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

elpimous12
Posts: 59
Joined: Tue 3. Aug 2021, 23:34

Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

Post by elpimous12 » Fri 5. Apr 2024, 14:14

Thanks a lot Marvin.

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

Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?

Post by M.Heidemann » Fri 5. Apr 2024, 14:16

You're welcome!

- closed -
---
Marvin Heidemann
PEAK-Support Team

Locked