5. cc_pcan_can
5.1. Can Communication Channel using PCAN hardware
- module
cc_pcan_can
- synopsis
CChannel implementation for CAN(fd) using PCAN API from python-can
- class pykiso.lib.connectors.cc_pcan_can.CCPCanCan(interface='pcan', channel='PCAN_USBBUS1', state='ACTIVE', bitrate=500000, is_fd=True, enable_brs=False, f_clock_mhz=80, nom_brp=2, nom_tseg1=63, nom_tseg2=16, nom_sjw=16, data_brp=4, data_tseg1=7, data_tseg2=2, data_sjw=2, is_extended_id=False, remote_id=None, can_filters=None, logging_activated=True, **kwargs)[source]
CAN FD channel-adapter.
Initialize can channel settings.
- Parameters
interface (
str
) – python-can interface modules usedchannel (
str
) – the can interface namestate (
str
) – BusState of the channelbitrate (
int
) – Bitrate of channel in bit/s,ignored if using CanFDis_fd (
bool
) – Should the Bus be initialized in CAN-FD modeenable_brs (
bool
) – sets the bitrate_switch flag to use higher transmission speedf_clock_mhz (
int
) – Clock rate in MHznom_brp (
int
) – Clock prescaler for nominal time quantumnom_tseg1 (
int
) – Time segment 1 for nominal bit rate, that is, the number of quanta from the Sync Segment to the sampling pointnom_tseg2 (
int
) – Time segment 2 for nominal bit rate, that is, the number of quanta from the sampling point to the end of the bitnom_sjw (
int
) – Synchronization Jump Width for nominal bit rate. Decides the maximum number of time quanta that the controller can resynchronize every bitdata_brp (
int
) – Clock prescaler for fast data time quantumdata_tseg1 (
int
) – Time segment 1 for fast data bit rate, that is, the number of quanta from the Sync Segment to the sampling pointdata_tseg2 (
int
) – Time segment 2 for fast data bit rate, that is, the number of quanta from the sampling point to the end of the bit. In the range (1..16)data_sjw (
int
) – Synchronization Jump Width for fast data bit rateis_extended_id (
bool
) – This flag controls the size of the arbitration_id fieldremote_id (
Optional
[int
]) – id used for transmissioncan_filters (
Optional
[list
]) – iterable used to filter can id on receptionlogging_activated (
bool
) – boolean used to disable logfile creation
- _cc_close()[source]
Close the current can bus channel and uninitialize PCAN handle.
- Return type
None
- _cc_open()[source]
Open a can bus channel, set filters for reception and activate PCAN log.
- Return type
None
- _cc_receive(timeout=0.0001, raw=False)[source]
Receive a can message using configured filters.
If raw parameter is set to True return received message as it is (bytes) otherwise test entity protocol format is used and Message class type is returned.
- Parameters
timeout (
float
) – timeout applied on receptionraw (
bool
) – boolean use to select test entity protocol format
- Return type
Union
[Message
,bytes
,None
]- Returns
tuple containing the received data and the source can id
- _cc_send(msg, remote_id=None, raw=False)[source]
Send a CAN message at the configured id.
If remote_id parameter is not given take configured ones, in addition if raw is set to True take the msg parameter as it is otherwise parse it using test entity protocol format.
- Parameters
msg (
Union
[Message
,bytes
]) – data to sendremote_id (
Optional
[int
]) – destination can id usedraw (
bool
) – boolean use to select test entity protocol format
- Return type
None
- _pcan_configure_trace()[source]
Configure PCAN dongle to create a trace file.
If self.logging_path is set, this path will be created, if it does not exist and the logfile will be placed there. Otherwise it will be logged to the current working directory if a default filename, which will be overwritten in successive calls. If an error occurs, the trace will not be started and the error logged. No exception is thrown in this case.
- Return type
None
- _pcan_set_value(channel, parameter, buffer)[source]
Set a value in the PCAN api.
If this is not successful, a RuntimeError is returned, as well as the PCAN error text is logged, if possible.
- Parameters
channel – Channel for PCANBasic.SetValue
parameter – Parameter for PCANBasic.SetValue
buffer – Buffer for PCANBasic.SetValue
- Raises
RuntimeError – Raised if the function is not successful
- Return type
None
- timeout
Extract the base logging directory from the logging module, so we can create our logging folder in the correct place. logging_path will be set to the parent directory of the logfile which is set in the logging module + /raw/PCAN If an AttributeError occurs, the logging module is not set to log into a file. In this case we set the logging_path to None and will just log into a generic logfile in the current working directory, which will be overwritten every time, a log is initiated.