“can_handler” Module Documentation¶
This is the documenation for the can handler.
Terms and conditions¶
Copywrite 2009 Jim Nilsson. PyCAN is distributed under the terms of the GNU Lesser General Public License.
This file is part of the PyCAN Libary.
PyCAN is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
PyCAN is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License and GNU Lesser General Public License along with PyCAN. If not, see <http://www.gnu.org/licenses/>.
-
class
can_handler.
CanHw
[source]¶ Description: This is the CANHW class that handles all the CAN communication for the library BeeJay. The class can be used stand alone to send an receive CAN messages on CAN.
It uses the Vector GmbH XL Driver Library to interface with all of Vectors supported hardware.
-
create
()[source]¶ Description: The methods is called automatically when a instance of the class is created by being called from the __init__ method. It creates and initilizes all the global variables for the class.
-
printHardware
(channelsIn=None)[source]¶ Description: This method prints the connected hardware.
INPUT: Parameters: channelIn (Int) – Number of channels to print starts at zero i.e. the first channel. Detailed Description: If no channel is given the method the driver scans the ports for connected hardware and prints all avalible hardware onto the standard output.
-
readCanMsg
(msgId=None, outPutInfo=False)[source]¶ Description: This method is used to read CAN MSG’s form a specific MSG ID’s msg-buffer.
INPUT: Parameters: - msgId (Hex) – The specific MSG ID to fetch CAN MSG from.
- outPutInfo (Bool) – Displays information text to the standards output if put to true.
Detailed Description: The msg retreived from the msg buffer of the specific CAN MSG ID is always the first stored CAN MSG from the CAN Network. This is because the msg que in the CanMsgHolder object is designed as a FIFO-Que see image bellow. Once the msg is retrieved from the buffer it is removed from the que and can’t be retrieved again. Running the method again will retrieve the next message in the que and so forth until the que is empty.
OUTPUT: Parameters: tmpMsg (XLevent) – Retrieved message from the msg buffer.
-
reciveCanMsg
()[source]¶ Description: This method is used to grab all messaged that are in the hardware messaged buffer in the CAN hardware.
The following code takes the messages grabbed from the HW messaged buffer and adds it to the appropriate msg holder object’s msg buffer. If no msg holder object exists for that specific msg ID one is created and the messaged is added to it’s msg buffer. This ensourse that each msg sent on CAN has its own msg holder object and its own msg buffer the size of MAX_MSG_BUFFER_SIZE.
for msg in self.__msgBufferListRx: try: oFrameHolder = self.__msgHolderList[msg.tagData.msg.id] except: oFrameHolder = CanMsgHolder() self.__msgHolderList[msg.tagData.msg.id] = oFrameHolder oFrameHolder.addMsgToBuffer(msg)
This method is also called by the thread “rxListenerThread” periodically according to the “threadFrequency” defined in the create method.
-
request
()[source]¶ Description: The request method opens a selected channel and activates it.
Detailed Description: The request class needs to be called after the setup method and takes the requested channel opens and activates it for sending and receiving messages onto CAN. It will exit if no channel is availeble.
Once the channel is open and activated the listener thread is started and it in it’s turn starts to collect CAN messages from CAN. The thread is executed periodically according to the “threadFrequency” that is setup in the create method.
-
sendOneCanMsg
(msgId, msgIn)[source]¶ Description: Sends a CAN msg out on the CAN network.
INPUT: Parameters: - msgId (Hex) – The MSG ID of the msg to send out onto CAN.
- msgIn (List of Hex) – The MSG to send out on to the CAN network.
Detailed Description: The CAN msg need to be formated as below illustrated for this method to work. First byte is always reserved for the number of bytes in the CAN msg. The method returns true of successful otherwise returns false.
msgListIn = [0x02, 0xF1, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00]
OUTPUT: Parameters: return (Bool) – Returns true if successful otherwise returns false
-
setup
(fileIn=None, canLoggingOnOff=False, hardwareType=None, interactive=False)[source]¶ Description: The setup method is used to setup the CAN Hardware with a available channel to send and receive from.
INPUT: Parameters: - fileIn (string) – The file location of the vxlapi.dll file for the vectors XL Library.
- canLoggingOnOff (Bool) – Turn on or off logging of the CAN traffic.
Detailed Description: N/A
-
-
class
can_handler.
CanHwChannel
[source]¶ **Description this is the generall hardware CAN channel class. It contains all information about the used hardware to be able to open a channel for commuication over CAN.
-
class
can_handler.
CanMsgHolder
[source]¶ Description: The Can Msg Holder class is used to hold CAN frames from a specific CAN ID. The CAN ID correlates to the MSG ID in the DBC-file that can be viewed and used together with vectors CANAlyzer. It has a frame buffer that is the size of SIZE_MSG_BUFFER same as that the HW buffer is initialized to.
-
addMsgToBuffer
(msgIn)[source]¶ Description: Adds a CAN message to the messaged buffer.
INPUT: Parameters: msgIn (XLevent) – The CAN msg that will be added to the buffer Detailed Description: The msg buffer is a list and each candrivers a new msg is added to the msg buffer its added to the end of the list. If the msg buffer is full the last entry of the msg buffer is disregarded and the new msg is added in its place.
-
getLatestMsgFromBuffer
()[source]¶ Description: Retrieves the latest added msg in the msg buffer.
OUTPUT: Parameters: msg (XLevent) – The latest msg in the msg buffer
-