User Manual PCI-1680U 2-Port CAN Interface Universal PCI Communication Card w/ Isolation PCI-1682U 2-port CAN Interface Universal PCI Communication Card w/ CANopen
Copyright The documentation and the software included with this product are copyrighted 2010 by Advantech Co., Ltd. All rights are reserved. Advantech Co., Ltd. reserves the right to make improvements in the products described in this manual at any time without notice. No part of this manual may be reproduced, copied, translated or transmitted in any form or by any means without the prior written permission of Advantech Co., Ltd. Information provided in this manual is intended to be accurate and reliable.
Declaration of Conformity CE This product has passed the CE test for environmental specifications when shielded cables are used for external wiring. We recommend the use of shielded cables. This kind of cable is available from Advantech. Please contact your local supplier for ordering information. FCC Class A Note: This equipment has been tested and found to comply with the limits for a Class A digital device, pursuant to part 15 of the FCC Rules.
Safety Precaution - Static Electricity Follow these simple precautions to protect yourself from harm and the products from damage. To avoid electrical shock, always disconnect the power from your PC chassis before you work on it. Don't touch any components on the CPU card or other cards while the PC is on. Disconnect power before making any configuration changes. The sudden rush of power as you connect a jumper or install a card may damage sensitive electronic components.
Contents Chapter Chapter Chapter Chapter 1 Introduction..........................................1 1.1 1.2 1.3 1.4 Description ................................................................................................ 2 Features .................................................................................................... 2 Specifications ............................................................................................ 3 Ordering Information ....................................
4.11 4.5.4 How to dispose received messages. .......................................... 55 Acceptance filtering................................................................................. 57 Advantech CAN Windows WDM&CE Driver application development guide ................................................................................................................ 59 4.7.1 Guide for Visual C++ development............................................. 59 4.7.2 Guide for Visual Basic development......
Chapter 1 1 Introduction This chapter provides a general description of the PCI-1680U and PCI-1682U.
1.1 Description PCI-1680U/1682U is special purpose communication card that offers connectivity to Controller Area Networks (CAN) on your PC. With its built-in CAN controllers, the PCI-1680U/1682U provides bus arbitration and error detection with an automatic transmission repetition function. This drastically reduces the chance of data loss and ensures system reliability. You can run both CAN controllers independently at the same time.
Bus Interface: PCI bus spec. 2.2 compliant Ports: 2 Protocol: CAN 2.
PCI-1680U/1682U User Manual 4
Chapter 2 2 Install WDM driver This chapter shows how to install WDM driver.
2.1 Begin to use Advantech CAN device driver The following chart shows procedures of developing applications with Advantech CAN Driver. There are different installation procedures for PCI device driver and ISA device driver, please respectively refer to: PCI device installation procedures ISA device installation procedures Note! Default installation path for Advantech CAN WDM Driver is C:\Program Files\Advantech\AdvCAN.
The following installation procedures are for PCI devices. Take PCI-1680 as example: 1. First make sure hardware can be installed normally, then turn on the computer and enter operating system. You will see the following screen. Chapter 2 2.1.1 PCI device setup Install WDM driver 2. Click "Next" as the following.
3. Click "Finish" as the following. 2.1.2 ISA device setup The following installation procedures are for ISA devices. Take PCM-3680 as an example. 1. Follow the instructions in the manual to install the device, then turn on the computer to enter operating system. 2. Enter Control Panel, then select "Add Hardware".
4. Click "Next" as the following. Install WDM driver Click "Next" as the following. Chapter 2 3.
5. Click "Next" as the following. 6. Click "Next" as the following.
Click "Have Disk...". 8. Suppose inf file is installed under C:\Program Files\Advantech\AdvCAN\inf, click "Next" as the following. Chapter 2 7.
9. Click "Next" as the following. 10. When the installation is complete, click "View or change resources for this hard ware (Advanced)" to configure resources of the device. Users can also directly click "Finish" and configure it in Device Manager.
Chapter 2 11. Select "Set Configuration Manually". Install WDM driver 12. Configure according to your hardware. 13. Restart the computer to finish the installation.
2.1.3 Port setup When bus driver is installed, users can install port driver AdvCanPort.sys according to the instructions. The installation file is AdvCanPort.inf. When the installation is finished, users can find the device in Device Manager and set ports in properties page.
2. Click the eAutomation CAN port that you want to configure, and select "Properties" to open properties page of the port. Users can set the device in PORT_INFO. 15 PCI-1680U/1682U User Manual Install WDM driver Users can set the device in "Windows Device Manager". 1.
PCI-1680U/1682U User Manual 16
Chapter 3 3 Hardware Installation This chapter covers inspection and installation of hardware and drivers.
3.1 Initial Inspection You should find the following items inside the shipping package: PCI communication interface card Industrial Communication Driver, Utility and PCI communication card user's manual in ICOM CD-ROM PCI-1680U/1682U was carefully inspected mechanically and electrically before it was shipped. It should be free of marks and scratches and in perfect working order when received. As you unpack the PCI-1680U/1682U, check for signs of shipping damage (damaged box, scratches, dents, etc.).
Chapter 3 3.2 Jumper Locations & Setting Hardware Installation Figure 3.
Figure 3.
You configure your card to match the needs of your application by setting jumpers. A jumper is the simplest kind of electric switch. It consists of two metal pins and a small metal clip (often protected by a plastic cover) that slides over the pins to connect them. To "close" a jumper you connect the pins with the clip. To "open" a jumper you remove the clip. 3.2.2 Terminator Resistor Setup You can set the terminator resistor if necessary to match impedance. Each port has a separate resistor. Table 3.
12. 13. 14. 15. 16. 17. Press the board firmly into the socket. Replace the screw in the expansion slot's retaining bracket. Replace anti-vibration cardholder. Replace the PC's cover. Connect the cables you removed in step 3. Turn the computer power on. The board is now installed in the computer. See Chapter 5 for information on cabling.
Chapter 4 4 Software Requirements This chapter has information on the software of PCI-1680U/1682U.
4.1 Introduction PCI-1680U/1682U and PCL-841 are Isolated Dual-port CAN communication cards. Each provides two isolated CAN ports for communication applications in difficult environments. The chip on the CAN cards is SJA1000. The SJA1000 is a single chip solution for PC-based CAN port and parallel expansion add-in cards. This chapter outlines the CAN card's windows DLL driver software requirement specifications. Including functionality, performance, and user interface requirements.
System Requirements Windows 2000, 32-bit Windows XP, 32-bit Windows Vista, 32-bit Windows 7, 64-bit Windows XP, 64-bit Windows Vista, 64-bit Windows 7, Windows CE. The usage of WDM is different from that of CE in the following aspects: Driver Installation – WDM: The user should refer to Install WDM Driver to install the driver. – CE: The driver has been pre-built in Platform image, so the user doesn't need to install the driver.
Hardware Support Table 4.1: Hardware Support HardWare Description WDM PCM-3680 2 port Isolated ISA CAN bus Card. Yes Yes PCL-841 2 port Isolated ISA CAN bus Card. Yes Yes TPC-662G 1 port Isolated ISA CAN bus Device on TPC-662G. Yes Yes PCI-1680 2 port Isolated PCI CAN bus Card. Yes Yes UNO-2052(E) 2 port Isolated PCI CAN bus Device on UNO-2052(E). Yes Yes EAMB-PH07 1 port Isolated PCI CAN bus Card. Yes Yes TPC-68T 1 port Isolated ISA CAN bus Device on TPC-68T.
Main API used in current development are: CreateFile Open specified Can port. CloseHandle Close specified Can port. DeviceIoControl Send commands to drivers, including configuration, management and getting status, etc. Read data. WriteFile Send data. GetOverLappedResult Wait until asynchronous operation is finished. SetCommMask Set mask. GetCommMask Get mask. WaitCommEvent Wait specified event. ClearCommError Get error code with this function when receiving error event.
Parameters Name Direction Description lpFileName Input Name of device which was opened, such as \\\\.\\CAN1. *Note In WINDOWS CE,use CAN1:. ldwDesiredAccess Input Ways of opening the port, which is usually GENERIC_READ | GENERIC_WRITE. dwShareMode Input Does not support share open. It must be set to 0. lpSecurityAttributes Input NULL. dwCreationDisposition Input OPEN_EXISTING. dwFlagsAndAttributes Input Synchronous open: FILE_ATTRIBUTE_NORMAL.
Close the port by calling this function when operation is completed. Syntax BOOL CloseHandle( HANDLE hDevice ); Name Direction Description hDevice Input Handle of the device which was opened. Return Value Successful: return non-zero values. Unsuccessful: return zero value. Please call GetLastError function. Example //close BOOL bRet = CloseHandle(hDevice); See Also CreateFile 4.3.
Parameters Name Direction Description hDevice Input Handle of the device which was opened. dwIoControlCode Input Control code, shows the specific operation mode. lpInBuffer Input Start address sent to data area of driver. nInBufferSize Input Byte length sent to data area of driver. lpOutBuffer Output Address of data area which receives driver's return data. nOutBufferSize Input Byte length of data area which receives driver's return data.
Chapter 4 Software Requirements bSuccess = DeviceIoControl ( hDevice, CAN_IOCTL_CONFIG, &config, sizeof(Command_par), NULL, 0, &dwReturned, NULL ); if(!bSuccess) { //error } cmd.cmd = CMD_START; bSuccess = DeviceIoControl ( hDevice, CAN_IOCTL_COMMAND, &cmd, sizeof(Command_par), NULL, 0, &dwReturned, NULL ); if(!bSuccess) { //error } Set acceptance filter: DWORD dwReturned; Command_par_t cmd; Config_par_t config; cmd.
//error } config.target = CONF_ACC_FILTER; config.val1 = 1; //1: set single filter mode; 0: set dual filter mode bSuccess = DeviceIoControl ( hDevice, CAN_IOCTL_CONFIG, &config, sizeof(Command_par), NULL, 0, &dwReturned, NULL ); if(!bSuccess) { //error } config.target = CONF_ACC; config.val1 = 0xffffffff; config.val2 = 0xffffffff; bSuccess = DeviceIoControl ( hDevice, CAN_IOCTL_CONFIG, &config, sizeof(Command_par), NULL, 0, &dwReturned, NULL ); if(!bSuccess) { //error } cmd.
Chapter 4 Software Requirements ); if(!bSuccess) { //error } Set listen only mode: DWORD dwReturned; Command_par_t cmd; Config_par_t config; cmd.cmd = CMD_STOP; BOOL bSuccess = DeviceIoControl ( hDevice, CAN_IOCTL_COMMAND, &cmd, sizeof(Command_par), NULL, 0, &dwReturned, NULL ); if(!bSuccess) { //error } config.target = CONF_LISTEN_ONLY_MODE; config.
sizeof(Command_par), NULL, 0, &dwReturned, NULL ); if(!bSuccess) { //error } Reset chip: DWORD dwReturned; Command_par_t cmd; cmd.cmd = CMD_RESET; BOOL bSuccess = DeviceIoControl ( hDevice, CAN_IOCTL_COMMAND, &cmd, sizeof(Command_par), NULL, 0, &dwReturned, NULL ); if(!bSuccess) { //error } cmd.
Clear receive buffer: DWORD dwReturned; Command_par_t cmd; cmd.
4.3.4 ReadFile Users can use this interface to read data from CAN port which was opened. One or more frames can be selected each time. Note! The third and fourth parameters of ReadFile are defined as byte length in MSDN, but stand for the number of frames in Advantech CAN Windows WDM&CE Driver.
Example Read one frame data in synchronous mode. DWORD dwRead; canmsg_t ReadBuffer; ZeroMemory(&ReadBuffer, sizeof(canmsg_t)); BOOL bSuccess = ReadFile(hDevice, &ReadBuffer, 1, &dwRead, 0); if(bSuccess) { if(dwRead == 1) { //SUCCESS if(ReadBuffer.flags & MSG_EXT) { //Extended frame } else{ //Standard frame } if(ReadBuffer.flags & MSG_RTR) { //Remote frame } if(ReadBuffer.flags & MSG_SELF) { //self reception } if(ReadBuffer.
{ //receive buffer overflow } if(ReadBuffer.flags & { //CAN controller } if(ReadBuffer.flags & { //CAN controller } if(ReadBuffer.
Users can use this interface to send data to CAN port which was opened. One or more frames can be selected each time. Note! The third and fourth parameters of WriteFile are defined as byte length in MSDN, but stand for the number of frames here. Parameters Name Direction Description hDevice Input Handle of the device which was opened. lpBuffer Input Start address of send buffer. nNmberOfFramesToWrite Input Number of frames to be sent to drivers.
In asynchronous mode, operation will be pending if drivers cannot complete user's write request at present, and GetLastError will be called to return ERROR_IO_PENDING. See MSDN for more information. Example Write one frame data in synchronous mode. DWORD dwWrite; canmsg_t WriteBuffer; ZeroMemory(&WriteBuffer, sizeof(canmsg_t)); //WriteBuffer.flags = 0; //Standard frame WriteBuffer.flags = MSG_EXT; //Extended frame //WriteBuffer.flags |= MSG_RTR; //Remote frame WriteBuffer.id = 0; WriteBuffer.
Users can use this interface to set event for CAN port. Users have to call WaitCommEvent function to wait event. Users can call GetCommMask to get the current event set before. If users do not set any of the supported event types, the real event type will be zero. In this case, if WaitCommEvent is called, the call will be returned and the event type returned will be zero.
4.3.7 GetCommMask Users can call GetCommMask to get event type set in SetCommMask. Syntax BOOL GetCommMask( HANDLE hDevice, LPDWORD lpEvtMask ); Parameters Name Direction Description hDevice Input Handle of the device which was opened. lpEvtMask Output Store event type which return from drivers. Return Value Successful: return non-zero values. Unsuccessful: return zero value. Please call GetLastError function.
BOOL bSuccess = SetCommMask(hDevice, EV_ERR | EV_RXCHAR); if(!bSuccess) { //error } DWORD dwMask = 0; bSuccess = WaitCommEvent(hDevice, &dwMask, NULL); if(bSuccess) { if(dwMask & EV_ERR) { //to do DWORD dwError; ClearCommError(hDevice, &dwError, NULL); } if(dwMask & EV_RXCHAR) { //to do } } See Also SetCommMask ClearCommError 43 PCI-1680U/1682U User Manual Software Requirements Example Wait event in synchronous mode. Chapter 4 Return Value Successful: return non-zero values.
4.3.9 ClearCommError When error occurs, users can use ClearCommError to get the specific type of error. Note! Definitions of error codes supported are as below: Name Description CE_RXOVER Receive Queue overflow. CE_OVERRUN Receive Overrun Error. CE_FRAME Passive error. CE_BREAK Busoff . Note! The third parameter is unused, please set it to NULL.
See Also WaitCommEvent DeviceIoControl 45 PCI-1680U/1682U User Manual Software Requirements DWORD dwMask; BOOL bSuccess = WaitCommEvent(hDevice, &dwMask, NULL); if(bSuccess) { if(dwMask & EV_ERR) { //to do DWORD dwError; bSuccess = ClearCommError(hDevice, &dwError, NULL); if(bSuccess) { //to do if(dwError& CE_FRAME || dwError& CE_BREAK) { CanStatusPar_t status; DWORD dwReturned; DeviceIoControl (hDevice, CAN_IOCTL_STATUS, NULL, 0, &status, sizeof(CanStatusPar_t), &dwReturned, NULL ); } } } Chapter 4 E
4.3.10 GetOverlappedResult When user's operation cannot be finished immediately in asynchronous mode, this function should be called to wait operation to be completed. Syntax BOOL GetOverlappedResult( HANDLE hDevice, LPOVERLAPPED lpOverlapped, LPDWORD lpNumberOfFramesTransferred, BOOL bWait ); Parameters Name Direction Description hDevice Input Handle of the device which was opened. lpOverlapped Input Events need to be waited are included. Refer to MSDN for more information.
bSuccess = SetCommMask(hDevice, EV_ERR | EV_RXCHAR); if (!bSuccess) { // Handle the error. printf("SetCommMask failed with error %d.\n", GetLastError()); return; } // Create an event object for use by WaitCommEvent. ov.hEvent = CreateEvent( NULL, // default security attributes FALSE, // auto reset event FALSE, // not signaled NULL // no name ); // Intialize the rest of the OVERLAPPED structure to zero. ov.Internal = 0; ov.InternalHigh = 0; ov.Offset = 0; ov.
} } else { DWORD dwRet = GetLastError(); if( ERROR_IO_PENDING == dwRet) { printf("I/O is pending...\n"); if(GetOverlappedResult(hDevice, &ov, &dwLength, TRUE)) { //To do } else { //To do } } else printf("Wait failed with error %d.\n", GetLastError()); } } See Also ReadFile WriteFile WaitCommEvent 4.4 Structure List The table below is a list of structures needed by Advantech CAN WDM Driver. Methods: canmsg_t Received/Sent message structure. CanStatusPar_t Port status structure.
When users directly use ReadFile or WriteFile interface of Windows Native API to call drivers, this structure is needed. Member Description Name Description flags Types of messages. cob Reserved. id ID of message. length of messages (0~8). data Data transferred (Made up of 0°´8 Byte data). Remarks 8-bit flags are used to record types of messages during sending or receiving.
4.4.2 CanStatusPar_t DeviceIOControl's parameter dwIoControlCode (0x222554). It uses this structure.
When users directly use DeviceIOControl interface of Windows Native API to call drivers, this structure is needed. If DeviceIOControl's parameter dwIoControlCode is CAN_IOCTL_COMMAND (0x222540), this means command operation. If dwIoControlCode is CAN_IOCTL_CONFIG (0x222544), it means configuration operation. (Please refer to MSDN for related information about DeviceIOControl). Note 1. The two modes of configuring Baud Rate are standard mode and custom mode.
The following code is the example to custom baud rate by setting BTR0 and BTR1 device register. AdvCANIO.h Line:269 / ************************************************************** *************** * * acSetBaudRegister * * Purpose: * Configures baud rate by custom mode. * * * Arguments: * hDevice - handle of device * Btr0 - BTR0 register value. * Btr1 - BTR1 register value.
BTR0 BTR1 Setting value 5K 0xBF 0xFF 0xFFBF 40K 0x87 0xFF 0xFF87 80K 0x83 0xFF 0xFF83 200K 0x81 0xFA 0xFA81 400K 0x80 0xFA 0xFA80 Please refer to acceptance filtering for setting acceptance code and acceptance mask. Self reception is not supported on windows CE. Member Description Name Description cmd Send start or stop command to drivers. target Send configure command to drivers. val1 Parameter 1. val2 Parameter 2. error Reserved. retval Reserved. Remarks 1.
2. While configuring target, the following commands are supported: Optional configures Corresponding value of target Description 0 Acceptance code regisAcceptance mask ter and acceptance register.default setmask register. Need to ting: 0xFFFFFFFF enter reset mode. Acceptance code register default setting: 0xFFFFFFFF CONF_ACCM 1 Acceptance mask only. Need to enter reset mode. Acceptance mask register default setting: 0xFFFFFFFF Reserved CONF_ACCC 2 Acceptance code only.
4.5.3 How to send RTR frame. DWORD dwWrite=0; canmsg_t WriteBuffer; ZeroMemory(&WriteBuffer, sizeof(canmsg_t)); WriteBuffer.flags = 0; //Standard frame //WriteBuffer.flags = MSG_EXT; //Extended frame WriteBuffer.flags |= MSG_RTR; //Remote frame WriteBuffer.id = 0; WriteBuffer.length = 0; WriteFile(hDevice, &WriteBuffer, 1, &dwWrite, 0); 4.5.4How to dispose received messages.
//self reception } if(ReadBuffer.flags & { //receive buffer } if(ReadBuffer.flags & { //CAN controller } if(ReadBuffer.flags & { //CAN controller } if(ReadBuffer.
Acceptance code corresponds to 4 registers: ACR0, ACR1, ACR2, ACR3.Acceptance mask corresponds to 4 registers: AMR0, AMR1, AMR2, AMR3.ACR works with AMR. Only when the acceptance filtering of the Standard frame or the Extended frame is confirmed, will the filter save the data of the frame into FIFO. Single mode For Standard frame, 11 identifiers and the RTR bit correspond to ACR0, ACR1, AMR0 and AMR1 with unused lower 4 bits of ACR1 and AMR1.
Dual Mode Dual filtering is more complicated than single filtering. In Dual filtering mode, 4 ACRs and 4 AMRs form two filters; the received information frame could be accepted by either filter. For Standard frame, filter1 is composed of ACR0, ACR1, AMR0, AMR1 and the lower four bits of ACR3 and AMR3. It corresponds to 20 bits, including 11 identifiers, the RTR bit and the first byte; all of 20 bits are used for the filtering.
Users can directly access drivers with WINDOWS Native API. In the following, we will provide an example by opening a CAN port and reading its current status to explain how to write basic applications in VC, VB, VB.NET and C# environment.Necessary files for developing applications are listed below. Suppose installation paths of all header files in the example are C:\Program Files\ADVANTECH\AdvCAN\Include. Description AdvCan.h Header file for VC AdvCan.cs Header file for C# AdvCan.vb Header file for VB.
4.7.1.2 Add necessary files 1. Add Include header files (AdvCan.h) in Advantech CAN Windows WDM&CE Driver. In VC++ work area, right click "Header Files", then select "Add Files to Folder" to add header files to the project. 4.7.1.3 Write code 1. “Select "Add to Project->New" from "Project"£¨ then select "C++ Source File".
// Get Can port status. flag = DeviceIoControl( hDevice, CAN_IOCTL_STATUS, NULL, 0, &CanStatus, sizeof(CanStatusPar_t), &dwReturned, 0 ); if ( !flag ) { printf( "GetStatus Error!"); return; } printf( "Acceptance code = 0x%x\n" , CanStatus.acceptancecode ); printf( "Acceptance mask = 0x%x\n" , CanStatus.acceptancemask ); printf( printf( printf( printf( "Baud = %u\n", CanStatus.baud ); "Self reception = %u\n" , CanStatus.selfreception ); "Read time out = %u\n" , CanStatus.
4.7.1.4 Test application Run the application, the following result will be displayed. 4.7.2 Guide for Visual Basic development We will give an example by opening a CAN port and reading its current status so as to simply explain how to write base applications in Visual Basic environment. 4.7.2.1 Create a new VB project Related header files must be used before using Advantech CAN Windows WDM&CE Driver interface function. Make sure the driver had been installed correctly.
Chapter 4 4.7.2.2 Add files and design graphical interfaces 1. Add Include header files (AdvCan.bas) in AdvCAN Windows WDM&CE Driver. Right click the project and select Add->Module Item,then select Existing Item to add AdvCan.bas.(Installation path\AdvCan\Include\AdvCan.
2. Design graphical interfaces. Add one Button and six Text controls to Form1. 4.7.2.3 Write code 1. Write corresponding code for Button1. Private Sub Button1_Click() Dim hDevice As Long Dim Status As CanStatusPar_t Dim result As Boolean Dim dwOutLen As Long Dim ov As OVERLAPPED 'Open Can Port "CAN1". 'You can also change "CAN1" to a port's name which you have installed. hDevice = CreateFile("\\.
65 PCI-1680U/1682U User Manual Software Requirements 4.7.2.4 Test application Run the application, the following result will be displayed. Chapter 4 End If TextBox1.Text = "Baud rate= " + CStr(Status.baud) TextBox2.Text = "Accept code = " + Hex(Status.acceptancecode) TextBox3.Text = "Mask code = " + Hex(Status.acceptancemask) TextBox4.Text = "Self recevie = " + CStr(Status.selfreception) TextBox5.Text = "Read TimeOut = " + CStr(Status.ReadTimeOut) TextBox6.Text = "Write TimeOut: = " + CStr(Status.
4.7.3 Guide for VC.NET development We will give an example by opening a CAN port and reading its current status so as to simply explain how to write base applications in VC.NET environment. 4.7.3.1 Create a new VC.NET project Related header files must be used before using Advantech CAN Windows WDM&CE Driver interface function. Make sure the driver had been installed correctly. (Please refer to relevant books and documentations regarding detailed information about VC.NET development.
Chapter 4 Design graphical interfaces. Add one Button and six Text controls to Form1. 67 PCI-1680U/1682U User Manual Software Requirements 2.
4.7.3.3 Write code Write code in source file. #include #include "../../../Include/AdvCan.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { HANDLE hDevice = 0; BOOL result; int dwOutLen=0; int lpSecurityAttributes=0; OVERLAPPED ov ; CanStatusPar_t CanStatus; Command_par_t cmd ; //Open Can Port "CAN1". //You can also change "CAN1" to a port's name which you have installed. System::String^ CanPortName = "\\\\.
Chapter 4 4.7.3.4 Test application Run the application, the following result will be displayed. Software Requirements 4.7.4 Guide for for VB.NET development We will give an example by opening a CAN port and reading its current status so as to simply explain how to write base applications in VB.NET environment. 4.7.4.1 Create a new VB.NET project Related header files must be used before using Advantech CAN Windows WDM&CE Driver interface function. Make sure the driver had been installed correctly.
Please follow the following procedures to create a new VB.NET project: 1. Select "File"->"New"->"Project" from the main menu. For Project Types, select Visual Basic Projects. Templates is Windows Application. A new VB.NET project is created. 4.7.4.2 Add files and design graphical interfaces 1. Add Include header files (AdvCan.vb) in AdvCAN Windows WDM&CE Driver. Right click the project, then select Add->Add Existing Item to add AdvCan.vb. (Installation path\AdvCan\Include\AdvCan.
Design graphical interfaces. Add one Button and six Text controls to Form1. 'Open Can Port "CAN1". 'You can also change "CAN1" to a port's name which you have installed. hDevice = CreateFile("\\.\can1", GENERIC_READ + GENERIC_WRITE, 0, Nothing, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL + FILE_FLAG_OVERLAPPED, 0) If hDevice.ToInt32 = &HFFFFFFFF Then MsgBox("Open Error!") Exit Sub End If 'Get Can port status.
TextBox2.Text = "Accept code = " & Hex(status.acceptancecode) TextBox3.Text = "Mask code = " & Hex(status.acceptancemask) TextBox4.Text = "Self recevie = " & status.selfreception TextBox5.Text = "Read TimeOut = " & status.readtimeout TextBox6.Text = "Write TimeOut: = " & status.writetimeout result = CloseHandle(hDevice) 'Close the CAN port If Not result Then MsgBox("Failed to close the CAN port!") End If End Sub 4.7.4.4 Test application Run the application, the following result will be displayed.
We will give an example by opening a CAN port and reading its current status so as to simply explain how to write base applications in C# environment. 2. Type the name and saving path of the project according to instructions on the screen, and click "OK". A new C# project is created. 73 PCI-1680U/1682U User Manual Software Requirements 4.7.5.1 Create a new C# project Related header files must be used before using Advantech CAN Windows WDM&CE Driver interface function.
4.7.5.2 Add files and design graphical interfaces 1. Add Include header files (AdvCan.cs) in Advantech CAN Windows WDM&CE Driver. Right click the project, then select Add->Add Existing Item to add AdvCan.cs. (Installation path\AdvCan\Include\AdvCan.
Design graphical interfaces. Add one Button and six TextBox controls to Form1. Chapter 4 2.
4.7.5.3 Write code 1. Add the following code to Button: private void button1_Click(object sender, System.EventArgs e) { uint hDevice = 0; bool result; int dwOutLen=0; int lpSecurityAttributes=0; AdvCan.OVERLAPPED ov =new AdvCan.OVERLAPPED(); AdvCan.CanStatusPar_t CanStatus = new AdvCan.CanStatusPar_t(); AdvCan.Command_par_t cmd =new AdvCan.Command_par_t (); //Open Can Port "CAN1". //You can also change "CAN1" to a port's name which you have installed. hDevice = AdvCan.CreateFile("\\\\.\\can1",AdvCan.
Chapter 4 4.7.5.4 Test application Run the application, the following result will be displayed. Advantech CAN Windows WDM&CE Driver package contains examples of VC, VB, VB.NET, C#.NET, VC.NET, eVC. Users can refer to these examples to develop applications. WDM: Example Name Description VC VB VB.NET C#.NET VC.NET Can Configure This example shows how to configure each item of CAN port. Yes Yes Yes Yes Yes Can Send This example shows how to send data to CAN port.
CE: VB.NE T Example Name Description C#.NET VC.NET eVC Can Configure This example shows how to configure Yes each item of CAN port. Yes Yes Yes Can Send This example shows how to send data to CAN port. Yes Yes Yes Yes Can Receive This example shows how to receive data from CAN port. Yes Yes Yes Yes Can Event This example shows how to receive/ send data from/to CAN port through Yes events in the way similar to serial port communication. Yes Yes Yes 4.8.1 Interface 4.8.1.
CE Software Requirements WDM Chapter 4 79 PCI-1680U/1682U User Manual
4.8.1.2 Receive Data is received. Values of Baud Rate and timeout of the port can be set. Please refer to Receive flow chart for function calling. Before you begin, please enter the name of the port you have installed in combobox of CAN Port, such as can0, can1, etc. The user can choose either Standard or Custom to set Baud Rate. If Standard is chosen, you should select the Baud Rate needs to be set from the dropdown list of Baud Rate.
This is only used to change configuration of the application which is currently running. Once "Configure" item is closed, all changes made in it will not be retained. WDM 81 PCI-1680U/1682U User Manual Software Requirements Note! Chapter 4 4.8.1.3 Configure Users can set values of Baud Rate, Timeout of sending and receiving data, mask of receive register and filter. Meanwhile, status of the port can be displayed. Please refer to Configure flow chart for function calling.
CE 4.8.1.4 Event This function is similar to serial port communication, which send/receive data through events. Baud Rate and timeout values in the example are fixed. The application realizes duplex communication. Please refer to Event flow chart for function calling. Before you begin, please select the name of the port you have installed in combobox of CAN Port, such as can0, can1, etc. Value of Baud Rate is fixed at 125 k, and Value of timeout is fixed at 3000 ms.
CE Chapter 4 Software Requirements 4.8.2 Flow Chart 4.8.2.
4.8.2.
Chapter 4 4.8.2.
4.8.2.
System Requirements Windows 2000, 32-bit Windows XP, 32-bit Windows Vista, 32-bit Windows 7, 64-bit Windows XP, 64-bit Windows Vista, 64-bit Windows 7. 87 PCI-1680U/1682U User Manual Software Requirements An Utility is provided for users to test whether hardware is working normally. It's installed under C:\Program Files\Advantech\AdvCAN\Utility directory by default. This Utility can be divided into four parts: In Part 1, users can select which port to open in the choice box at top.
4.10 CANMonitor CANMonitor can be used to monitor the messages in CAN network and to show the messages according to different message types. CANMonitor can show messages in the formats of CAN and CANopen. System Requirements Windows 2000, 32-bit Windows XP, 32-bit Windows Vista, 32-bit Windows 7, 64-bit Windows XP, 64-bit Windows Vista, 64-bit Windows 7.
This section introduces the functions that CANMonitor supports. Base function: Open Device Opens a device and make basic configuration. Close Device Closes a device and clear all the data. Load from file Loads data from the file. Save to file Saves data to the specified file. Restarts communication based on the configuration . Stop Communication Stops communication, which is used to view data when the refresh is frequent. Show Message Shows messages. Hide Message Hides messages.
4.10.
Chapter 4 Data Format Data Format has following setting: Function Hex The monitor data which includes "ID" and "Data" will be displayed as Hex format. Dec The monitor data which includes "ID" and "Data" will be displayed as Dec format.
CANopen CANopen has the following functions: Name Function List Node List all CANopen nodes Change Node State Change CANopen node state Read Object Read CANopen node data Write Object Write CANopen node data Node Guard All Get all CANopen nodes Filter Filter has CAN Filter setting and CANopen Filter setting.
Name Function New Open device Chapter 4 Toolbar Introduction Close Device Load Load data from file Save Save data to file Run Start communication Stop Stop communication Show Show the message Hide Hide the message Auto Scroll Whether to scroll automatically Clear Clear all the messages Status Bar Introduction Name Function S1 Show the load; the two formats - Kbit/s and bit/s will be selected automatically S2 Show the current status of the device: Normal, Passive, Bus off S3 Sh
4.11 COTI.DLL for CANopen Conformance Test The COTI DLL allows users to use the CANopen Conformance Test Tool of CiA(CAN in Automation) with Advantech CAN WDM Driver.This file has to be copied into the directory of the CANopen Conformance Test.More detailed presentation about CANopen Conformance Test Tool, please refer to: http://www.can-cia.org/index.php?id=141. The default installation path for COTI.DLL is C:\Program Files\Advantech\AdvCAN\COTI.
Chapter 5 5 Pin Assignments and Wiring This chapter covers the pin assignment for the CAN connector, and the wiring of the two transmission wires.
5.1 Pin Assignments Figure 5.1 shows the pin assignment for the card's DB-9 connectors: Figure 5.1 PCI-1680U/1682U DB-9 pin assignment 5.2 Wiring The CAN standard supports half-duplex communication. This means that just two wires are used to transmit and receive data. Table 5.
Chapter 5 Pin Assignments and Wiring PCI-1680U/1682U User Manual 97
www.advantech.com.cn Please verify specifications before quoting. This guide is intended for reference purposes only. All product specifications are subject to change without notice. No part of this publication may be reproduced in any form or by any means, electronic, photocopying, recording or otherwise, without prior written permission of the publisher. All brand and product names are trademarks or registered trademarks of their respective companies. © Advantech Co., Ltd.