Page 1 of 1
Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
Posted: Tue 2. Apr 2024, 09:50
by elpimous12
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++)
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
Posted: Tue 2. Apr 2024, 10:17
by M.Heidemann
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
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
Posted: Thu 4. Apr 2024, 18:09
by elpimous12
clear answer,
Thanks Marvin
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
Posted: Thu 4. Apr 2024, 23:38
by elpimous12
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 ?
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
Posted: Fri 5. Apr 2024, 09:07
by M.Heidemann
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
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
Posted: Fri 5. Apr 2024, 14:14
by elpimous12
Thanks a lot Marvin.
Re: Linux (CharDev) PCANBasic: Only read specific ID from queue? Also: How to reset Interface?
Posted: Fri 5. Apr 2024, 14:16
by M.Heidemann
You're welcome!
- closed -