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++)
Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
-
- Posts: 59
- Joined: Tue 3. Aug 2021, 23:34
-
- 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?
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
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
Marvin Heidemann
PEAK-Support Team
-
- Posts: 59
- Joined: Tue 3. Aug 2021, 23:34
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
clear answer,
Thanks Marvin
Thanks Marvin
-
- Posts: 59
- Joined: Tue 3. Aug 2021, 23:34
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
tested with a buffer (moteus_rx_msg_copy), works perfectly !!!
Marvin, A question, however, i should add a function who empty each port (after needed reads). how to do that ?
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;
}
-
- 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?
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):
Best Regards
Marvin
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):
You will also find examples of the usage in PCANBasic parameter documentation.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
Best Regards
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
-
- Posts: 59
- Joined: Tue 3. Aug 2021, 23:34
-
- 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?
You're welcome!
- closed -
- closed -
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team