background image

 

 

 

DS-MPE-CAN2L User Manual Rev A.1 

www.diamondsystems.com

  

 

    

 

Page 16 

9.  CONFIGURE AND MANAGE THE PORTS IN LINUX 

The CANLib library provides the set of APIs to configure and manage the CAN ports. The CANLib library can be 
used to build the CAN  user application.  It is  a shared library  built on top of Linux platform and using the driver 
provided functionality. To compile the CANLib shared library, use the below command  

 

cd CANLib 

make 

 

 

All the CAN APIs prototypes are defined in the can.h file. This file is located in the CANLib directory. Include the 
can.h file in the user application to use all these APIs. 

9.1 

API to Configure and Manage CAN Ports 

init_can0()

  & 

init_can1() 

: These function will initialize the CAN#0 & CAN#1 ports respectively. 

Both these functions return the CAN file descriptor (fd). The return value of these functions should be retained 
for  all  subsequent  APIs.  Its  prototypes  are  defined  in  the  can.h  file.  Declare  two  CAN  file  descriptors  and 
retains its return values. 

 

#include “can.h” 

 

 

int  can0_fd; 

int  can1_fd; 

 

can0_fd

 = init_can0() ; 

if ( can0_fd < 0 ) 

printf("Error while initializing the CAN#0\n") ; 

exit(0) ; 

 

can1_fd

 = init_can1() ; 

if ( can1_fd < 0 ) 

printf("Error while initializing the CAN#1\n") ; 

      exit(0) ; 

 

Содержание Diamond Systems DS-MPE-CAN2L

Страница 1: ......

Страница 2: ...onsequential resulting from the use of the information provided herein Our products are not intended for use in systems in which failures of product could result in personal injury All trademarks mentioned herein are property of their respective owners All specifications are subject to change without notice Manual Diamond Systems DS MPE CAN2L PCIe MiniCardI O Expansion Module with Dual CANbus Port...

Страница 3: ...A 0 4 25 2014 Initial release A 1 4 09 2015 Updated Windows installation procedure Copyright 2015 FOR TECHNICAL SUPPORT Diamond Systems Corporation PLEASE CONTACT 555 Ellis Street Mountain View CA 94043 USA support diamondsystems com Tel 1 650 810 2500 Fax 1 650 810 2525 www diamondsystems com ...

Страница 4: ...6 2 CAN Ports J4 J7 8 7 Jumper Configuration 9 8 Linux Driver installation 10 8 1 Installing the Software 10 8 2 Setting the Baud Rate 11 8 3 Setting the CAN ID and Message Length 12 8 4 Writing a Message 13 8 5 Viewing Messages 14 9 Configure and Manage the Ports in Linux 16 9 1 API to Configure and Manage CAN Ports 16 9 2 Compiling User Application using CANLib Library 19 10 Driver installation ...

Страница 5: ...mage However these design rules are not sufficient to prevent damage in all situations A third cause of failure is when a metal screwdriver tip slips or a screw drops onto the board while it is powered on causing a short between a power pin and a signal pin on a component This can cause overvoltage power supply problems described below To avoid this type of failure only perform assembly operations...

Страница 6: ...grammable acceptance filters 11 bit and 29 bit identifiers 500V port to port and input to output isolation Driver supports dual independent and dual redundant modes Latching connectors for increased ruggedness 2 3 Operating System Support Linux 2 6 16 2 6 27 2 6 31 and 2 6 32 Windows 7 2 4 Mechanical Electrical Environmental PCIe MiniCard full size format Dimensions 50 95mm x 30mm 2 x 1 18 40 C to...

Страница 7: ...DS MPE CAN2L User Manual Rev A 1 www diamondsystems com Page 5 4 FUNCTIONAL OVERVIEW 4 1 Functional Block Diagram The DS MPE CAN2L block diagram is shown below ...

Страница 8: ...llowing key features Conforms to the ISO 11898 1 CAN 2 0A and CAN 2 0B standards Supports both standard 11 bit identifier and extended 29 bit identifier frames Supports bit rates up to 1Mbps Transmit message FIFO with a user configurable depth of up to 64 messages Transmit prioritization through one High Priority Transmit buffer Automatic re transmission on errors or arbitration loss Receive messa...

Страница 9: ...ver grounds and the host ground 4 6 Power Supply The module is powered by 3 3V from the PCIe MiniCard socket It provides all other required voltages on board including 5V for the CAN transceivers and the FPGA core voltages 5 INSTALLATION The DS MPE CAN2L plugs in to any socket meeting the PCIe MiniCard specifications It has two connectors one for each pair of serial ports a protocol configuration ...

Страница 10: ...UIM_C8 17 18 GND10 RSVD UIM_C4 19 20 W_DISABLE GND3 21 22 PERST PERN0 23 24 3 3VAUX_4 PERP0 25 26 GND11 GND4 27 28 1 5V_2 GND5 29 30 SMB_CLK PETN0 31 32 SMB_DATA PETP0 33 34 GND12 GND6 35 36 USB_D GND7 37 38 USB_D 3 3VAUX_1 39 40 GND13 3 3VAUX_2 41 42 LED_WWAN GND8 43 44 LED_WLAN RSVD1 45 46 LED_WPAN RSVD2 47 48 1 5V_3 RSVD3 49 50 GND14 RSVD4 51 52 3 3VAUX_5 6 2 CAN Ports J4 J7 Each of the two CAN...

Страница 11: ...cks one for each port Jumper block J3 is for port J4 and jumper block J6 is for port J7 Jumper blocks J3 and J6 are identical The default is no jumpers installed To add termination for a port s bias line jumper position B CAN H line jumper position H or CAN L line jumper position L add a jumper at B H or L location respectively B H L O O O O O O ...

Страница 12: ...dsc_can2_pci_driver Linux CAN driver 4 qt opensource linux x86 5 2 1 run Qt Installer which is required by the PCI CAN Interface utility Step 2 Install the Qt shared libraries using the Qt Installer Execute the command below and follow the Qt Installer instructions Use the command below to install the Qt shared libraries Install Qt at the default locations cd DSC_CAN2L_PCI_LINUX_V1 7 qt opensource...

Страница 13: ...ly 8 2 Setting the Baud Rate Using the CAN interface utility software the baud rate for each port can be selected On the desired CAN port select the baud rate from the Baud Rate drop down menu After selecting the desired baud rate press Connect to connect with specified baud rate as shown in below figure To change the baud rate click on Disconnect and select a new baud rate ...

Страница 14: ...l Rev A 1 www diamondsystems com Page 12 8 3 Setting the CAN ID and Message Length Set the CAN ID and CAN message length for each CAN port by entering the desired numbers into the ID and Len fields respectively for that port ...

Страница 15: ...the below figure To transmit to a different CAN ID change the data in the CAN ID field enter the desired data into the Data Hex fields and click on Write Message To change the message length change the CAN message length to the new length enter the desired data into the Data Hex fields and click on Write Message To transmit a different CAN message to the same CAN ID change the CAN message to the d...

Страница 16: ...DS MPE CAN2L User Manual Rev A 1 www diamondsystems com Page 14 8 5 Viewing Messages Transmitted messages are listed in the CAN message box for the sending CAN port as shown in below figure ...

Страница 17: ...DS MPE CAN2L User Manual Rev A 1 www diamondsystems com Page 15 Received CAN messages are listed in the CAN message box for the CAN port receiving the message as shown in below figure ...

Страница 18: ...This file is located in the CANLib directory Include the can h file in the user application to use all these APIs 9 1 API to Configure and Manage CAN Ports init_can0 init_can1 These function will initialize the CAN 0 CAN 1 ports respectively Both these functions return the CAN file descriptor fd The return value of these functions should be retained for all subsequent APIs Its prototypes are defin...

Страница 19: ...d rate n exit 0 Set 500k Baud rate for CAN 1 ret_val set_baudrate can1_fd CAN_SPEED_500K if ret_val 0 printf Error while setting the baud rate n exit 0 In the above code can0_fd and can1_fd should contain the values returned by init_can0 and init_can1 function Use below macros for setting the different baud rates These macros can also be found in can h file CAN_SPEED_1M CAN_SPEED_800K CAN_SPEED_50...

Страница 20: ...the msgType is MSG_EXTENDED then can_id value should be in the range 0x0 to 0x1FFFFFFF 29 bit value len 4 This field can be of 0 to 8 CAN Transmit Data Length DLC data This field depends on the above CAN Data length len field In this case len is 4 then the CAN message data will be of 4 bytes long and each byte can have values from 0x0 to 0xFF 8 bits data 0 0x1A data 1 0xAB data 2 0x22 data 3 0x4D ...

Страница 21: ...G_EXTENDED Received message is CAN Extended Message dlc Received CAN Data Length can_id Will contain the CAN Message ID Data of dlc length printf ID x DLC d Data can_id dlc for i 0 i dlc i printf x data i printf n The sample example programs for both transmit and receive can be found in the CANLib directory for the reference 9 2 Compiling User Application using CANLib Library Export the library pa...

Страница 22: ...s Unzip DSC_CAN2L_PCI_WIN_V1 0 3 zip The DSC_CAN2_PCI_WIN_V1 0 3 directory contains the CAN application library and driver for testing the 2 CAN interfaces 1 App CAN Monitor demo application directory 2 dsc_can2_pci_src Demo application source code directory 3 dsc_can2_pci_driver Windows CAN driver 10 1 Installing the PCI CAN Driver Step 1 Open Windows command prompt with Administrator privileges ...

Страница 23: ...rking directory from the command prompt to the DSC_CAN2_PCI_WIN_V1 0 3 dsc_can2_pci_driver directory where the software is copied Step 3 Execute install bat Please see the below screenshot for details After executing follow the next steps to install the driver Step 4 Restart the system ...

Страница 24: ...ev A 1 www diamondsystems com Page 22 Step 5 Check whether the driver is installed properly or not by opening the device manager Right Click on My Computer Click on Properties Device Manager Please refer to the screenshot below ...

Страница 25: ...N2L User Manual Rev A 1 www diamondsystems com Page 23 If the driver is installed properly then the device manager will show the device as PCIe Sample device under Sample Device as shown in the screenshot below ...

Страница 26: ...nual Rev A 1 www diamondsystems com Page 24 10 2 Run the Windows Application The application is stored in the App directory Double click on dsc_can2_pci exe The application window will open as shown in the below screenshot ...

Страница 27: ...lity software the baud rate for each port can be selected On the desired CAN port select the baud rate from the Baud Rate drop down menu After selecting the desired baud rate press Connect to connect with specified baud rate as shown in below figure To change the baud rate click on Disconnect and select a new baud rate ...

Страница 28: ...l Rev A 1 www diamondsystems com Page 26 10 4 Setting the CAN ID and Message Length Set the CAN ID and CAN message length for each CAN port by entering the desired numbers into the ID and Len fields respectively for that port ...

Страница 29: ... in the below figure To transmit a different CAN ID change data in the CAN ID field enter the desired data into the Data Hex fields and click on Write Message To change the message length change the CAN message length to the new length enter the desired data into the Data Hex fields and click on Write Message To transmit a different CAN message to the same CAN ID change the CAN message to the desi...

Страница 30: ...S MPE CAN2L User Manual Rev A 1 www diamondsystems com Page 28 10 6 Viewing Messages Transmitted and received messages are listed in the CAN message box for the sending CAN port as shown in below figure ...

Страница 31: ... code for all windows user APIs to configure and manage the CAN ports are stored in dsc_can2_pci_src directory User can include following files into their project directory These API are dependent on CAN dll User has to include these dll into their project directory common h dscud h dscud_os h mpedaq0804 h pci_fpga h public h ...

Страница 32: ...LE_FLAG_OVERLAPPED This function should be called only once during initiation It returns a valid handle if the driver detects the CAN device can_init int can_ch This API accepts the CAN interface number as an argument for the initialization This will initialize CAN 0 or CAN 1 The value of can_ch should 0 for CAN 0 and 1 for CAN 1 Example To initialize CAN 0 channel pass the argument value as 0 to ...

Страница 33: ... These function will be used to Transmit and Receive the CAN messages respectively CAN Transmit Prototype void FrameCANTxMsg int can_ch unsigned char msgType unsigned int can_id int len unsigned char data Assign the appropriate values before calling the FrameCANTxMsg function can_ch CAN port number 0 for CAN 0 and 1 for CAN 1 msgType MSG_STANDARD or MSG_EXTENDED can_id 0x12 if the msgType is MSG_S...

Страница 34: ...or calling the check_rx_msg function if check_rx_msg 0 msgType data can_id dlc If msgType MSG_STANDARD Received message is CAN Standard Message else if msgType MSG_EXTENDED Received message is CAN Extended Message dlc Received CAN Data Length can_id Will contain the received CAN Message ID Data of dlc length printf ID x DLC d Data can_id dlc for i 0 i dlc i printf x data i printf n The sample exam...

Страница 35: ...ity Acceptance filters 16 programmable 29 bit Identifiers 11 bit and 29 bit Modes Dual independent Dual redundant Isolation 500V port to port and input to output Input power 3 3VDC 5 Power consumption 0 462W 3 3V Software drivers Windows XP Linux 2 6 16 2 6 27 2 6 31 and 2 6 32 Operating temperature 40 C to 85 C MTBF 1 583 210 hours at 20 o C Dimensions 50 95mm x 30mm 2 x 1 18 Weight 8 5g 0 3oz Ro...

Страница 36: ...stec de Germany Distec GmbH Augsburger Str 2b 82110 Germering Phone 49 89 894363 0 E Mail info distec de Internet www distec de Switzerland ALTRAC AG Bahnhofstraße 3 5436 Würenlos Phone 41 44 7446111 E Mail info altrac ch Internet www altrac ch United Kingdom Display Technology Ltd Osprey House 1 Osprey Court Hichingbrooke Business Park Huntingdon Cambridgeshire PE29 6FN Phone 44 1480 411600 E Mai...

Отзывы: