Welcome

Advantech CAN Windows WDM&CE Driver

User Manual V1.20

Website: http://www.advantech.com

E-mail: info@advantech.com

© Advantech Co., Ltd


BeforeBegin

Before you begin

Welcome to use Advantech series products.This manual describes how to operate Advantech data communication devices through Advantech CAN Windows WDM&CE Driver. This manual supplies information about driver interfaces of Advantech CAN device, including calling procedure of operating data communication and descriptions of functions of each function, parameter and data structure.With the help of Advantech CAN Windows WDM&CE Driver, users can develop applications with tools like VC, VB, VB.net, C#.NET, VC.NET, eVC in different Windows system platforms(Windows 2K/XP/Vista/CE). This manual also provides examples for Advantech device driver, explaining how to use Advantech with series of real examples and offering reference for users to develop their own applications.

Click the following links to enter different section in this chapter. In this document, you can also use table of contents, search and scan the content by index.

Sections include:

  • Copyright
  • Technical Support
  • Limited Warranty


Copyright Notice

Copyright

This document is copyrighted by Advantech. Co., Ltd. All rights are reserved. The original manufacturer reserves the right to make improvements to 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 the original manufacturer. Information provided in this manual is intended to be accurate and reliable. However, the original manufacturer assumes no responsibility for its use, nor for any infringements upon the rights of third parties that may result from such use.


Advantech customer services

Each and every Advantech product is built to the most exacting specifica tions to ensure reliable performance in the harsh and demanding conditions typical of industrial environments. Whether your new Advantech equipment is destined for the laboratory or the factory floor, you can be assured that your product will provide the reliability and ease of operation for which the name Advantech has come to be known.Your satisfaction is our primary concern. Here is a guide to Advantech‘s customer services. To ensure you get the full benefit of our services, please follow the instructions below carefully.

Technical Support

We want you to get the maximum performance from your products. So if you run into technical difficulties, we are here to help. For the most frequently asked questions, you can easily find answers in your product documentation. These answers are normally a lot more detailed than the ones we can give over the phone.So please consult this manual first. If you still cannot find the answer, gather all the information or questions that apply to your problem, and with the product close at hand, call your dealer. Our dealers are well trained and ready to give you the support you need to get the most from your Advantech products. In fact, most problems reported are minor and are able to be easily solved over the phone.In addition, free technical support is available from Advantech engineers every business day. We are always ready to give advice on application requirements or specific information on the installation and operation of any of our products.

Technical Support Offices

USA

USA Advantech

Advantech Corporation, Industrial Automation Group

1320 Kemper Meadow Dr., Ste. 500

Cincinnati, OH 45240

Tel: (877) 451-6868

Fax: (513) 742-4451

E-mail: info@advantech.com

Asia

Advantech Co.,Ltd
4th Floor, 108-3 Min-Chuan Road

Shing-Tien City, Taipei County, Taiwan ROC
Tel: (+886-2) 2218-4567
Fax: (+886-2) 2218-1989
E-mail: IASupport@advantech.com.tw

Europe

Germany Advantech
Karlsruherstr. 11/1
D-70771 Leinf.-Echterdingen

Germany
Tel: +49 (0) 711 797 333 60
Fax: +49 (0) 711 797 333 85

Italy

Italy Advantech

Via Don Verderio
4/B-20060 Cassina de,

Pecchi (MI), Italy
Tel: +39-2-95343054
Fax: +39-2-95343067

China Mainland

Beijing Advantech
 No.7 6th Street Shangdi Zone, Haidian District, Beijing, China

Post code: 100085

Tel: +86-10-62984345~47, 62986314~17
Fax: +86-10-62984341~42

Shanghai Advantech
 Room 701, 7F, Longfeng Building, No. 1566, Yan'an West Road, Shanghai, China

Post Code: 200232
Tel: +86-21-64696831, 64697910
Fax: +86-21-64696834


Limited warranty

Advantech Co., Ltd does not warrant that Advantech CAN Driver can work normally in any hardware/software environment. Advantech Co., Ltd does not warrant the information described in this manual, especially no warranty is made for any special purpose. Advantech Co., Ltd assumes no responsibility for its use, nor for any infringements upon the rights of third parties that may result from such use. Advantech Co., Ltd reserves the right to make improvements to the products described in this manual at any time without notice.


Overview

Advantech CAN Windows WDM&CE Driver is composed of bus drivers, ports drivers, tools and examples.Bus drivers and ports drivers, which run in PeliCAN mode, are used to drive SJA1000 chip on Advantech CAN device.Bus drivers and ports drivers are compliant with PCI and ISA bus, and provide the users with coherent operation interfaces. Users can directly write applications with windows API.Examples of VC, VB, VB.NET, C#.NET, VC.NET, eVC are supplied in the package, providing a reference for users to develop applications. When developing work is completed, users can use test tools to verify if functions of the application are correct.

Feature

  1. Supports CAN 2.0B Protocol and compatible with CAN 2.0A Protocol, which means both Standard frame and Extended frame can be dealt with.
  2. Supports single filter mode and dual filter mode.
  3. Supports Listen-Only Mode.
  4. Supports self reception mode on WDM platform.
  5. Provides API interface similar to windows standard serial port, easy to develop.
  6. Provides tools like CANTest, CANDemo to test the basic functions.
  7. Provides CANMonitor to monitor CAN/CANopen network. A maximum of 1000000 frame data can be reserved a time and meanwhile CAN/CNAopen messages can be dealt with.
  8. Provides interface COTI.DLL of CANopen Conformance Test Tool. The COTI DLL allows users to use the CANopen Conformance Test Tool of CiA(CAN in Automation) with Advantech CAN WDM Driver.

CAN 2.0A and CAN 2.0B

CAN2.0 Spec. includes CAN 2.0A and CAN 2.0B. CAN 2.0A supports standard 11 bit Identifier. CAN 2.0B supports both 11 bit Identifier and extended 29 bit Identifier. So CAN 2.0B are compatible with CAN 2.0A.

SJA1000

SJA1000 supports BasicCAN mode and PeliCAN mode. BasicCAN mode supports CAN 2.0A, while PeliCAN mode supports 2.0B. Advantech CAN Windows WDM&CE Driver runs in PeliCAN mode, thus it can support both Standard frame and Extended frame.

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.

Development Kit Installtion

WDM: none

CE: Advantech platform SDK

Function

WDM: Support all the functions listed in the manual.

CE: Not support self reception function.

Interface

The interfaces that WDM and CE support are almost the same.

The user should pay attention to the following differences:

1. The device name is different.

Here CAN1 is used as an example:

WDM: \\\\.\\CAN1

CE: CAN1:

Functions involved: CreateFile

2. Since OVERLAPPED type is not supported by CE, NULL pointers will be loaded instead of parameters using OVERLAPPED structure.

Functions involved:DeviceIoControl, ReadFile, WriteFile, WaitCommEvent.

3. OVERLAPPED type is not supported by CE, so does not support GetOverLappedResult function.

Hardware Support:

HardWare | Description | WDM | CE
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. | No | Yes
TPC-120H | 1 port Isolated ISA CAN bus Device on TPC-120H. | No | Yes
TPC-32T | 1 port Isolated ISA CAN bus Device on TPC-32T. | No | Yes
AMAX-2050 | 1 port Isolated PCI CAN bus Device on AMAX-2050. | No | Yes
ADAM-5095 | 2 port Isolated PCI CAN bus Card. | No | Yes
ADVANTECH C001 CAN card (1 PORT) | 1 port Isolated PCI CAN bus Card. | Yes | Yes
ADVANTECH C002 CAN card (2 PORT) | 2 port Isolated PCI CAN bus Card. | Yes | Yes
ADVANTECH C004 CAN card (4 PORT) | 4 port Isolated PCI CAN bus Card. | Yes | Yes
ADVANTECH C101 CAN card (1 PORT, support CANopen) | 1 port Isolated PCI CAN bus Card and support CANopen. | Yes | Yes
ADVANTECH C102 CAN card (2 PORT, support CANopen) | 2 port Isolated PCI CAN bus Card and support CANopen. | Yes | Yes
ADVANTECH C104 CAN card (4 PORT, support CANopen) | 4 port Isolated PCI CAN bus Card and support CANopen. | Yes | Yes
ADVANTECH C201 CAN card (1 PORT) | 1 port Isolated PCI CAN bus Card. | Yes | Yes
ADVANTECH C202 CAN card (2 PORT) | 2 port Isolated PCI CAN bus Card. | Yes | Yes
ADVANTECH C204 CAN card (4 PORT) | 4 port Isolated PCI CAN bus Card. | Yes | Yes
ADVANTECH C301 CAN card (1 PORT, support CANopen) | 1 port Isolated PCI CAN bus Card and support CANopen. | Yes | Yes
ADVANTECH C302 CAN card (2 PORT, support CANopen) | 2 port Isolated PCI CAN bus Card and support CANopen. | Yes | Yes
ADVANTECH C304 CAN card (4 PORT, support CANopen) | 4 port Isolated PCI CAN bus Card and support CANopen. | Yes | Yes

Users of Windows CE can refer to Guide for developing applications

References:

"SJA1000 Standard-alone CAN controller"


Install

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.


PCI Install

PCI device setup

The following installation procedures are for PCI devices.

Take PCI-1680 as example:

If you insert the PCI-1680 first and then install the driver, the driver installation will complete the driver installation automatically.

If you install the driver first, then power off and insert the PCI-1680, when you turn on the computer and enter operating system.

You will see the following screen.

  • Click "Next" as the following.

  • Click "Finish" as the following.


ISA_Install

ISA device setup

The following installation procedures are for ISA devices.

Take PCM-3680 as an example.

  • Follow the instructions in the manual to install the device, then turn on the computer to enter operating system.
  • Enter Control Panel, then select "Add Hardware".

  • Click "Next" as the following.

  • Click "Next" as the following.

  • Click "Next" as the following.

  • Click "Next" as the following.

  • Click "Have Disk...".

  • Suppose inf file is installed under C:\Program Files\Advantech\AdvCAN\Driver, click "Next" as the following.

  • Click "Next" as the following.

  • 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.

  • Select "Set Configuration Manually".

  • Configure according to your hardware.

  • Restart the computer to finish the installation.


Port Install

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.


DeviceManager

Device setup

Users can set the device in "Windows Device Manager".

  • When driver is installed, users can open "Windows Device Manager" to set Advantech CAN device;

" Windows Device Manager" can be opened in the following two ways:

  1. Control Panel->Administrative Tools->Computer Management, then select "Device Manager";
  2. Right click icon of "My Computer" and click "Manage", then select "Device Manager".

  • 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.


CanStatusPar_t

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.

Function Introduction

Interface Introduction


CAN_MSG

Function Introduction

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.
Start Communication | 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.
Clear Data | Clears all data.
Auto Scroll | Supports auto scroll function.
Goto | Goes to the specified message line.
Listen only mode | Supports Listen Only mode.
CAN Message Filter | Configures CAN message filter modes.
CAN Message View | Shows CAN format message.

CANopen function:

List Node | Lists CANopen nodes detected and the node state.
Change Node State | Changes the specified CANopen node state.
Read Data from Node | Reads data from the specified CANopen node .
Write Data to Node | Writes data to the specified CANopen node.
Detect All Nodes in CANopen | Detects all the possible CANopen nodes, from 1 to 127.
CAN Message Filter | Configures CAN message filter modes.
CANopen Message Filter | Configures CANopen message filter modes.
CAN Message View | Shows CAN format message.
CANopen Message View | Shows CANopen format message.


Command_par

Introduction of Main Items in Menu Screen

Menu Introduction

File

File has the following functions:

Name | Function
New | Open device
Close | Close device
Load | Load data from File
Save | Save data to File
Exit | Exit the program

View

View has the following functions:

Name | Function
Toolbar | Whether to show the toolbar
Status Bar | Whether to show the status bar
Auto Scroll | Whether to scroll automatically
Clear | Clear all the messages
Goto | Go to the specified line

  Data Format has following setting:

Name | Function
Hex | The monitor data which is include "ID" and "Data" will be displayed as Hex format.
Dec | The monitor data which is include "ID" and "Data" will be displayed as Dec format.
Ascii | The monitor "Data" will be displayed as Dec format but "ID" will be displayed as Hex format

Function

Function has the following functions:

Name | Function
Run | Start communication
Stop | Stop communication
Show | Show the message
Hide | Hide the message
Listen Only | Whether to open Listen Only mode

CAN has a submenu:

Name | Function
Send CAN Message | Send CAN Message

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.

Toolbar Introduction

Name | Function
New | Open device
Close | 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 | Show the number of the messages sent
S4 | Show the number of the messages received
S5 | Show the number of Overrun
S6 | Show the number of lines of the data; the maximum number will not exceed the number configured when the device is open


Utility

Use Utility to test hardware

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.Set "Baud Rate", "acceptance filter mode", "acceptance code", "acceptance Mask", and choose if you want to receive "Self Reception" or send "RTR". Users can select "Listen Only" if you want use listen only mode.can also set "Cycle" of data transfer by entering the interval time (ms). Users can select "Auto Increase" if you want the data increase automatically. When setting is finished, users can choose to Open/Close the port, Start Tx/Stop Tx and Start Rx/Stop Rx.

In Part 2, detail information of received data will be shown when communication is built.

In Part 3, the following items will be shown: Numbers of sent frames, timeout sent frames, received frames and timeout received frames. Times of entering PASSIVE error mode, times of entering BUS OFF mode, times of hardware OVERRUN and times of software OVERRUN (BOVERRUN) .Users can select ASCII mode. As a result, ASCII format of the data will be shown in Part 2.

In Part 4, ID, Flag (SFF: Standard Frame; EFF: Extended Frame), length and data of messages will be configured before being sent.

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.


COTI.DLL for CANopen Conformance Test

CAN_DEMO for CE

Users on CE platform can examine whether the device is working normally through CAN_DEMO program.

First, this utility supports the basic configuration programs, including setting up baud rate; acceptance code and acceptance mask. Listen only Mode is also available.

Moreover, this utility can achieve the basic “Send and Receive”. Users can configure the sending data, as well as displaying the receiving data.

System Requirements:

Windows CE.


Command_par

How to dispose message

CAN2.0 Spec. includes CAN 2.0A and CAN 2.0B. CAN 2.0A supports standard 11 bit Identifier. CAN 2.0B supports both 11 bit Identifier and extended 29 bit Identifier. So CAN 2.0B are compatible with CAN 2.0A. SJA1000 supports BasicCAN mode and PeliCAN mode. BasicCAN mode supports CAN 2.0A, while PeliCAN mode supports 2.0B. Advantech CAN Windows WDM&CE Driver runs in PeliCAN mode, thus it can support both Standard frame and Extended frame.

While sending and receiving messages, the user can set or tell the message type via canmsg_t.flags. For detailed information, please refer to here.

The following part introduces how to send and receive CAN messages.

How to send Standard frame, compatible with CAN 2.0A.

DWORD    dwWrite=0;
canmsg_t WriteBuffer;
ZeroMemory(&WriteBuffer, sizeof(canmsg_t));
WriteBuffer.flags = 0; //Standard frame
WriteBuffer.id = 0;
WriteBuffer.length = 8;
for(int i=0; i<8; i++)

{
    WriteBuffer.data[i] = i;

}
WriteFile(hDevice, &WriteBuffer, 1, &dwWrite, 0);

How to send Extended frame, compatible with CAN 2.0B.

DWORD    dwWrite=0;
canmsg_t WriteBuffer;
ZeroMemory(&WriteBuffer, sizeof(canmsg_t));
WriteBuffer.flags = MSG_EXT; //Extended frame
WriteBuffer.id = 0;
WriteBuffer.length = 8;
for(int i=0; i<8; i++)

{
    WriteBuffer.data[i] = i;

}
WriteFile(hDevice, &WriteBuffer, 1, &dwWrite, 0);

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);

How to dispose received messages.

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.flags & MSG_BOVR)
        {
             //receive buffer overflow
        }
        if(ReadBuffer.flags & MSG_BUSOFF)
        {
             //CAN controller bus off
        }
        if(ReadBuffer.flags & MSG_OVR)
        {
             //CAN controller Msg overflow error
        }
        if(ReadBuffer.flags & MSG_PASSIVE)
        {
             //CAN controller in error passive
        }
    }
    else{
        //Timeout
    }
}
else{
    DWORD dwError = GetLastError();

    if (dwError == ERROR_IO_PENDING)
    {
        //pengding
    }
    else if(dwError == ERROR_INVALID_PARAMETER)
    {
        //parameter error
    }
    else if(dwError == ERROR_OPERATION_ABORTED)
    {
        //cancelled
    }
    else if(dwError == ERROR_GEN_FAILURE)
    {
        //bus off
    }
}

See Also

canmsg_t

WriteFile

ReadFile


Command_par

Acceptance filtering

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.

For AMR bits,

  • 0: the corresponding bits of ACR and CAN information frames should be the same in order to be accepted.

  • 1: the acceptance filtering function of the corresponding ACR bits is disabled and the corresponding bits of the CAN information frame are independent of the acceptance result.

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. Since the Standard frame has 11 identifiers only, the first 2 bytes of the data field are also included for filtering.Data1 corresponds to ACR2, AMR2; Data2 corresponds to ACR3, AMR3. If the received Standard frame is a Remote frame and the RTR bit is 1, then only the identifier will be used for filtering.If the received Standard frame is a data frame and the data field is less than 2 bytes, then the missed data will not be used for filtering. For Extended frame, 29 identifiers and the RTR bit correspond to 4 ACRs and 4 AMRs. Please note that the lower 2 bits of ACR3 and AMR3 are reserved.

  • Example of Standard frame:

 | 0 | 1(lower 4 bits) | 2 | 3
ACR | 11XXX010 | XXXX | XXXXXXXX | XXXXXXXX
ACM | 00111000 | 1111 | 11111111 | 11111111
accepted ID(ID.10``ID.0) | 11XXX010 | XXX |  |

In this example, Data1, Data2 and RTR are not considered and the accepted IDs include: 0x7D7(11111010111), 0x610(11000010000), etc.

  • Example of Extended frame:

 | 0 | 1 | 2 | 3
ACR | 10010100 | 1011000X | 1100XXXX | 00110XXX
ACM | 00000000 | 00000001 | 00001111 | 00000111
accepted ID(ID.28``ID.0) | 10010100 | 1011000X | 1100XXXX | 00110XXX

In this example, RTR is not considered and the accepted IDs include: 0x12961806(10010100101100001100000000110), 0x129639E6(10010100101100011100111100110), etc.

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. filter2 is composed of ACR2, AMR2 and the higher four bits of ACR3 and AMR3, while only 11 identifiers and the RTR bit are used for the filtering. For Extended frame, filter1 is composed of ACR0, ACR1, AMR0 and AMR1, not including ACR3 and AMR3. What’s more, there are only 16 bits out of 29 bits used for the filtering.Filter2 is composed of ACR2, ACR3, AMR2 and AMR3. The higher 16 bits out of 29 bits are used for the filtering.

  • Example of Standard frame:

Filter1:

 | 0 | 1 | 3 (lower 4 bits)
ACR | 00000000 | 001XXXXX | XXXX
ACM | 00000000 | 00011111 | 1111
accepted ID(ID.10``ID.0) | 00000000 | 001 |

In this example, Data1 and RTR are not considered and the accepted ID: 0x1.

Filter2:

 | 2 | 3 (upper 4 bits)
ACR0-ACR3 | 00000000 | 001X
ACM0-ACM3 | 00000000 | 0001
accepted ID(ID.10``ID.0) | 00000000 | 001

In this example, RTR are not considered and the accepted ID: 0x1.

  • Example of Extended frame:

Filter1:

 | 0 | 1
ACR | 00000000 | 00000001
ACM | 00000000 | 00000000
accepted ID(ID.28``ID.13) | 00000000 | 00000001

In this example, the accepted IDs include: 0x2000(10000000000000), 0x3FFF(11111111111111), etc.

Filter2:

 | 2 | 3
ACR | 00000000 | 00000001
ACM | 00000000 | 00000000
accepted ID(ID.28``ID.13) | 00000000 | 00000001

In this example, the accepted IDs include: 0x2000(10000000000000), 0x3FFF(11111111111111), etc.


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 here.

The default installation path for COTI.DLL is C:\Program Files\Advantech\AdvCAN\COTI.

System Requirements:

Windows 2000, 32-bit Windows XP, 32-bit Windows Vista.


Copyright Notice

Advantech CAN Windows WDM&CE Driver application development guide

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.

File name | Description
AdvCan.h | Header file for VC
AdvCan.cs | Header file for C#
AdvCan.vb | Header file for VB.NET
AdvCan.bas | Header file for VB

Note:

Users who use CAN driver on windows CE can directly refer to Structure list and Introduction to API (GetOverlappedResult is not included).


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.
Command_par | Command/Configure operation structure.


CAN_MSG

canmsg_t

When users directly use ReadFile or WriteFile interface of Windows Native API to call drivers, this structure is needed.

typedef struct {
   int       flags;
   int       cob;
   ULONG     id;
   short int length;
   UCHAR     data[ 8 ];
} canmsg_t;

Member Description

Name | Description
flags | Types of messages.
cob | Reserved.
id | ID of message.
length | 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. The meanings of these bits are:

Bit | Declaration | Meaning | Description
0 | MSG_RTR | RTR | 1 means Remote frame, 0 means data frame.
1 | MSG_OVR | Hardware OVERRUN | 1 means receive buffer overrun of hardware.
2 | MSG_EXT | Extension | 1 means Extended frame(29 bit identifier), 0 means Standard frame(11 bit identifier).
3 | MSG_SELF | Self Reception | 1 means self sending and receiving frame, 0 means receiving frame from other ports.
4 | MSG_PASSIVE | Error | 1 means bus error.
5 | MSG_BUSOFF | BUSOFF | 1 means busoff.
6 | Reserved | Reserved |
7 | MSG_BOVR | Software OVERRUN | 1 means receive buffer overrun of software.

ID shows type of CAN. When ID is 0xFFFFFFFF, it means error frame, which implies that hardware overrun, error and busoff occur in drivers. Users can get the specific type from flags.

If ID does not equal 0xFFFFFFFF, flags may be Remote frame, Extended frame, Standard frame, Self Reception or software overrun.


CanStatusPar_t

DeviceIOControl's parameter dwIoControlCode is CAN_IOCTL_STATUS (0x222554). It uses this structure.

typedef struct {
   unsigned int baud;
   unsigned int status;
   unsigned int error_warning_limit;
   unsigned int rx_errors;
   unsigned int tx_errors;
   unsigned int error_code;
   unsigned int rx_buffer_size;
   unsigned int rx_buffer_used;
   unsigned int tx_buffer_size;
   unsigned int tx_buffer_used;
   ULONG        retval;
   unsigned int type;
   unsigned int acceptancecode;
   unsigned int acceptancemask;
   unsigned int acceptancemode;
   unsigned int selfreception;
   unsigned int readtimeout;
   unsigned int writetimeout;
} CanStatusPar_t, *PCcanStatusPar_t;

Member Description

Name | Description
baud | Actual bit rate.
status | The status register (SR); CAN address 2.
error_warning_limit | The error warning limit register (EWLR); CAN address 13.
rx_errors | The RX error counter register (RXERR); CAN address 14.
tx_errors | The TX error counter register (TXERR); CAN address 15.
error_code | The error code capture register (ECC); CAN address 12.
rx_buffer_size | Size of rx buffer.
rx_buffer_used | Number of received messages.
tx_buffer_size | Size of tx buffer for wince.
tx_buffer_used | Number of messages of tx buffer for wince.
retval | Return Value. 0, SUCCESS; 0xFFFFFFFF, FAIL.
type | CAN controller type. 1, SJA1000; 0 other device.
acceptancecode | Acceptance code.
acceptancemask | Acceptance mask.
acceptancemode | Acceptance Filter Mode: 1:Single 0:Dual.
selfreception | Self reception.
ReadTimeout | Read timeout.
WriteTimeout | Write timeout.


Command_par

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).

struct Command_par {
   int   cmd;
   int   target;
   ULONG val1;
   ULONG val2;
   int   error;
   ULONG retval;
};

Note

1.The two modes of configuring Baud Rate are standard mode and custom mode.

  • Standard mode

The standard mode includes the recommended Baud Rate value. If the setting value is 10, then the Baud Rate will be 10k.

Target value | BTR0 | BTR1 | Setting value
10K | 0x31 | 0x1c | 10
20K | 0x18 | 0x1c | 20
50K | 0x09 | 0x1c | 50
100K | 0x04 | 0x1c | 100
125K | 0x03 | 0x1c | 125
250K | 0x01 | 0x1c | 250
500K | 0x00 | 0x1c | 500
800K | 0x00 | 0x16 | 800
1000K | 0x00 | 0x14 | 1000

  • Custom mode

If user need the baud rate is not in above table, user can use the custom mode to set the custom baud rate.

The CAN port's baud rate is determine by CAN clock, BTR0 and BTR1 .

The Advantech CAN devices use 8MHZ clock and oscillator frequency is 16M, The internal clock is divided by two from
the oscillator frequency.

BTR0 and BTR1 Timing Registers are used for:
– defining the bit-rate on the bus.
– defining the sample point in a bit period (bit sample point).
– defining the number of samples taken in a bit period.

we provide API function to set BTR0 and BTR1, The function will write the low 8 bits of setting value to BTR0 and high 8 bits of setting value to BTR1 of CAN device register.

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.
* Returns:
* =0 SUCCESS; or <0 failure
*
*****************************************************************************/
int acSetBaudRegister(HANDLE hDevice, unsigned char Btr0, unsigned char Btr1)
{
   unsigned int BaudRateValue = Btr0 * 256;
   BaudRateValue += Btr1;
   return acSetBaud(hDevice, BaudRateValue);
}

can_receive.cpp Line:105

nRet = acSetBaudRegister( hDevice, byBtr0, byBtr1 ); //Set baud rate
if ( nRet < 0 )
{
   SetDlgItemText( hwnd, IDC_SHOW_RESULT, "Failed to set Baud Rate!" );
   return FALSE;
}

User can also refer to receive and send examples for details usage.

How to calculate BTR0 and BTR1, please refer to SJA1000 datasheet for details.

Here we show some value of BTR0 and BTR1 for some custom baud rate.

Target 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
  2. Please refer to acceptance filtering for setting acceptance code and acceptance mask.
  3. 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. While configuring cmd, the following commands are supported:

Optional commands | Corresponding value of cmd | Description | val1 | val2
CMD_START | 1 | Start chip and enter work mode. | Reserved | Reserved
CMD_STOP | 2 | Stop chip and enter reset mode. | Reserved | Reserved
CMD_RESET | 3 | Stop chip by canceling current send/receive operation and enter reset mode. | Reserved | Reserved
CMD_CLEARBUFFERS | 4 | Clear receive buffer. | Reserved | Reserved

2. While configuring target, the following commands are supported:

Optional configures | Corresponding value of target | Description | val1 | val2
CONF_ACC | 0 | Acceptance code register and acceptance mask register. Need to enter reset mode. | Acceptance mask register. default setting: 0xFFFFFFFF | 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. Need to enter reset mode. | Acceptance code register default setting: 0xFFFFFFFF | Reserved
CONF_TIMING | 3 | Bit timing. Need to enter reset mode. | Baud Rate default setting: 125k | Reserved
CONF_LISTEN_ONLY_MODE | 8 | Listen only mode.Need to enter reset mode. | 1: ON; 0: OFF default setting: 0 | Reserved
CONF_SELF_RECEPTIOM | 9 | Self reception. | 1: ON; 0: OFF default setting: 0 | Reserved
CONF_TIMEOUT | 13 | Configure read and write timeout. | Write timeout (ms) default setting: 5s | Read timeout (ms) default setting: 3s
CONF_ACC_FILTER | 20 | Acceptance filter mode: 1-Single, 0-Dual.Need to enter reset mode. | 1: Single; 0: Dual default setting: Single | Reserved


NativeAPI

Introduction to API

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.
ReadFile | 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.

Only brief introduction is given in this manual regarding detailed usage of each function.Notes are made to notify users of important operation.For more detailed information about the usage, please see MSDN.


CreateFile

Users can use this interface to open CAN port device.

Close the port by calling CloseHandle when operation is completed.

Note

This driver does not support share open function, so the third parameter must be set to 0.

Syntax

HANDLE CreateFile(
  LPCTSTR lpFileName,
  DWORD dwDesiredAccess,
  DWORD dwShareMode,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD dwCreationDisposition,
  DWORD dwFlagsAndAttributes,
  HANDLE hTemplateFile
);

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. Asynchronous open: FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED.
hTemplateFile | Input | NULL.

Return Value

Successful, return effective HANDLE. Unsuccessful, return INVALID_HANLDLE_VALUE.

Example

Synchronous open CAN1:
HANDLE hDevice = CreateFile(
    "\\\\.\\CAN1",
    GENERIC_READ | GENERIC_WRITE,
    0,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL,
    NULL);

Asynchronous open CAN1：
HANDLE hDevice = CreateFile(
    "\\\\.\\CAN1",
    GENERIC_READ | GENERIC_WRITE,
    0,
    NULL,
    OPEN_EXISTING,
    FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
    NULL);


CloseHandle

Close the port by calling this function when operation is completed.

Syntax

BOOL CloseHandle(
  HANDLE hDevice
);

Parameters

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


DeviceIoControl

Users can use this interface to send commands, configure ports, like stop device, start device, configure Baud Rate, etc.

See Command_par, CanStatusPar_t for detailed configuration.

Syntax

BOOL DeviceIoControl(
  HANDLE hDevice,
  DWORD dwIoControlCode,
  LPVOID lpInBuffer,
  DWORD nInBufferSize,
  LPVOID lpOutBuffer,
  DWORD nOutBufferSize,
  LPDWORD lpBytesReturned,
  LPOVERLAPPED lpOverlapped
);

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.
lpBytesReturned | Output | Real byte length of data received from driver.
lpOverlapped | Input | If CreateFile uses asynchronous open, asynchronous operation must be supported here. Please refer to MSDN for detailed instruction to asynchronous open. *Note In WINDOWS CE,set to NULL.

Return Value

Successful: return non-zero values. Unsuccessful: return zero value. Please call GetLastError function.

It will be considered unsuccessful if zero values are returned in the following situation. Please call GetLastError.

In work mode, drivers can not complete some of the requests, GetLastError will be called to return ERROR_GEN_FAILURE.

Example

  • Set baud rate:
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_TIMING;
config.val1 = 1000; //set 1000K

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.cmd = CMD_STOP;

BOOL bSuccess = DeviceIoControl (
    hDevice,
    CAN_IOCTL_COMMAND,
    &cmd,
    sizeof(Command_par),
    NULL,
    0,
    &dwReturned,
    NULL
    );
if(!bSuccess)
{
    //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.cmd = CMD_START;
bSuccess = DeviceIoControl (
    hDevice,
    CAN_IOCTL_COMMAND,
    &cmd,
    sizeof(Command_par),
    NULL,
    0,
    &dwReturned,
    NULL
);
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.val1 = 1; //1: ON; 0: OFF

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
}
  • 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.cmd = CMD_START;
bSuccess = DeviceIoControl (
    hDevice,
    CAN_IOCTL_COMMAND,
    &cmd,
    sizeof(Command_par),
    NULL,
    0,
    &dwReturned,
    NULL
);
if(!bSuccess)
{
    //error
}
  • Clear receive buffer:
DWORD dwReturned;
Command_par_t cmd;
cmd.cmd = CMD_CLEARBUFFERS;

BOOL bSuccess = DeviceIoControl (
    hDevice,
    CAN_IOCTL_COMMAND,
    &cmd,
    sizeof(Command_par),
    NULL,
    0,
    &dwReturned,
    NULL
);
if(!bSuccess)
{
//error
}

  • Get status of device:
DWORD dwReturned;
CanStatusPar_t status;

BOOL bSuccess = DeviceIoControl (
    hDevice,
    CAN_IOCTL_STATUS,
    NULL,
    0,
    &status,
    sizeof(CanStatusPar_t),
    &dwReturned,
    NULL
);

See Also

Command_par

CanStatusPar_t


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.

Syntax

BOOL ReadFile(
  HANDLE hDevice,
  LPVOID lpBuffer,
  DWORD nNumberOfFramesToRead,
  LPDWORD lpNumberOfFramesRead,
  LPOVERLAPPED lpOverlapped
);

Parameters

Name | Direction | Description
hDevice | Input | Handle of the device which was opened.
lpBuffer | Output | Start address of receive buffer.
nNmberOfFramesToRead | Input | Number of frames to be received from drivers. The definition here is different from that in MSDN.
lpNumberOfFramesRead | Output | Real number of frames received from driver. The definition here is different from that in MSDN.
lpOverlapped | Input | If CreateFile uses asynchronous open, asynchronous operation must be supported here. Please refer to MSDN for detailed instruction to asynchronous open. *Note In WINDOWS CE,set to NULL.

Return Value

It will be considered successful if non-zero values are returned in the following situations:

1. The driver reads data and there is no data in the receive buffer. At this time, the data received is less than the requested data.

2. The driver reads all the requested data.

3. The driver can not read any data and time is out.

It will be considered unsuccessful if zero values are returned in the following situations. Please call GetLastError.

If users cancel the operation or reset chip while drivers are receiving data, GetLastError will be called to return ERROR_OPERATION_ABORTED.

If busoff of device is discovered before drivers read any frames, GetLastError will be called to return ERROR_GEN_FAILURE.

If drivers cannot allocate resources according to the number defined by the third parameter frame, GetLastError will be called to return ERROR_INVALID_PARAMETER.

In asynchronous mode, operation will be pending if drivers cannot complete user's read request, and GetLastError will be called to return ERROR_IO_PENDING.

See MSDN for more information.

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.flags & MSG_BOVR)
        {
             //receive buffer overflow
        }
        if(ReadBuffer.flags & MSG_BUSOFF)
        {
             //CAN controller bus off
        }
        if(ReadBuffer.flags & MSG_OVR)
        {
             //CAN controller Msg overflow error
        }
        if(ReadBuffer.flags & MSG_PASSIVE)
        {
             //CAN controller in error passive
        }
    }
    else{
        //Timeout
    }
}
else{
    DWORD dwError = GetLastError();

    if (dwError == ERROR_IO_PENDING)
    {
        //pengding
    }
    else if(dwError == ERROR_INVALID_PARAMETER)
    {
        //parameter error
    }
    else if(dwError == ERROR_OPERATION_ABORTED)
    {
        //cancelled
    }
    else if(dwError == ERROR_GEN_FAILURE)
    {
        //bus off
    }
}


WriteFile

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.

Syntax

BOOL WriteFile(
  HANDLE hDevice,
  LPCVOID lpBuffer,
  DWORD nNumberOfFramesToWrite,
  LPDWORD lpNumberOfFramesWritten,
  LPOVERLAPPED lpOverlapped
);

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. The definition here is different from that in MSDN.
lpNumberOfFramesWritten | Output | Real number of frames sent to driver. The definition here is different from that in MSDN.
lpOverlapped | Input | If CreateFile uses asynchronous open, asynchronous operation must be supported here. Please refer to MSDN for detailed instruction to asynchronous open. *Note In WINDOWS CE,set to NULL.

Return Value

It will be considered successful if non-zero values are returned in the following situations:

Driver send all the requested data.

Timeout occur when driver only send part of the data or no data.

It will be considered unsuccessful if zero values are returned in the following situations. Please call GetLastError.

If user cancel the operation or reset chip while drivers are sending data, GetLastError will be called to return ERROR_OPERATION_ABORTED.

If busoff of device is discovered before drivers send any frames, GetLastError will be called to return ERROR_GEN_FAILURE.

If drivers cannot allocate resources according to the number defined by the third parameter frame, GetLastError will be called to return ERROR_INVALID_PARAMETER.

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.length = DATALENGTH;

for(int i=0; i<DATALENGTH; i++)
{
    WriteBuffer.data[i] = i;
}
BOOL bSuccess = WriteFile(hDevice, &WriteBuffer, 1, &dwWrite, 0);
if(bSuccess)
{
    if(dwWrite == 1)
    {
        //SUCCESS
    }
    else{
        //Timeout
    }
}
else{
    DWORD dwError = GetLastError();

    if (dwError == ERROR_IO_PENDING)
    {
        //pengding
    }
    else if(dwError == ERROR_INVALID_PARAMETER)
    {
        //parameter error
    }
    else if(dwError == ERROR_OPERATION_ABORTED)
    {
        //cancelled
    }
    else if(dwError == ERROR_GEN_FAILURE)
    {
        //bus off
    }
}


SetCommMask

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.

Note

Events supported at present are only:

Type | Direction
EV_ERR | Error
EV_RXCHAR | Receive one frame data

Syntax

BOOL SetCommMask(
  HANDLE hDevice,
  DWORD dwEvtMask
);

Parameters

Name | Direction | Description
hDevice | Input | Handle of the device which was opened.
dwEvtMask | Input | Event type.

Return Value

Successful: return non-zero values. Unsuccessful: return zero value. Please call GetLastError function.

Example

BOOL bSuccess = SetCommMask(hDevice, EV_ERR | EV_RXCHAR);

See Also

WaitCommEvent

GetCommMask


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.

Example

DWORD dwMask = 0;
BOOL bSuccess = GetCommMask(hDevice, &dwMask);

See Also

SetCommMask


WaitCommEvent

After calling SetCommMask to set event, users should also call WaitCommEvent function to wait event.

Syntax

BOOL WaitCommEvent(
  HANDLE hDevice,
  LPDWORD lpEvtMask,
  LPOVERLAPPED lpOverlapped
);

Parameters

Name | Direction | Description
hDevice | Input | Handle of the device which was opened.
lpEvtMask | Output | Event type.
lpOvelapped | Output | If CreateFile uses asynchronous open, asynchronous operation must be supported here. Please refer to MSDN for detailed instruction to asynchronous open. *Note In WINDOWS CE,set to NULL.

Return Value

Successful: return non-zero values. Unsuccessful: return zero value. Please call GetLastError function.

If users cancel the operation or reset chip, GetLastError will be called to return ERROR_OPERATION_ABORTED.

In asynchronous mode, operation will be pending if drivers cannot complete user's request, and GetLastError will be called to return ERROR_IO_PENDING.

See MSDN for more information.

Example

Wait event in synchronous mode.

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


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 .

The third parameter is unused, please set it to NULL.

Syntax

BOOL ClearCommError(
  HANDLE hDevice,
  LPDWORD lpErrors,
  LPCOMSTAT lpStat
);

Parameters

Name | Direction | Description
hDevice | Input | Handle of the device which was opened.
lpErrors | Output | Store error codes which return from drivers.
lpStat | Output | Empty. If users want to know specific information about error register, please call DeviceIoControl to get status of the device.

Return Value

Successful: return non-zero values. Unsuccessful: return zero value. Please call GetLastError function.

Example

Wait event in synchronous mode.

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
            );
       }
   }
}

See Also

WaitCommEvent

DeviceIoControl


WaitCommEvent

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.
lpNumberOfFramesTransferred | Output | ReadFile and WriteFile are real numbers of data written and read; WaitCommEvent is not defined.
bWait | Input | TRUE, will not return until read/write operation is finished. FALSE, return immediately no matter the operation is finished or not. Call GetLastError to return ERROR_IO_INCOMPLETE. Refer to MSDN for detailed information.

Return Value

Successful: return non-zero values. Unsuccessful: return zero value. Please call GetLastError function.

Example

#include <windows.h>
#include <stdio.h>

void main( )
{
    HANDLE hDevice;
    OVERLAPPED ov;
    BOOL bSuccess;
    DWORD dwEvtMask;
    DWORD dwLength;

    hDevice = CreateFile( "\\\\.\\CAN1",
        GENERIC_READ | GENERIC_WRITE,
        0, // exclusive access
        NULL, // default security attributes
        OPEN_EXISTING,
        FILE_FLAG_OVERLAPPED,
        NULL
    );

    if (hDevice == INVALID_HANDLE_VALUE)
    {
        // Handle the error.
        printf("CreateFile failed with error %d.\n", GetLastError());
        return;
    }

    // Set the event mask.

    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.OffsetHigh = 0;

    if (WaitCommEvent(hDevice, &dwEvtMask, &ov))
    {
        if (dwEvtMask & EV_ERR)
        {
            // To do.
        }

        if (dwEvtMask & EV_RXCHAR)
        {
            // To do.
        }
    }
    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


Program_VC

Guide for Visual C++ 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 C++ environment.


Create a new VC 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 development.)

Please follow the following procedures to create a new VC++ project:

1. Select "File/New" from the main menu to create a new application project and source file. Define the type pf the new project as "Win32 Console Application", define the platform as "Win32" and select a path for files of the project.

2. Click "OK"->"Finish"->"OK" according to the instructions on the screen.

A new VC project is created.


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.


Write code

1、Select "Add to Project->New" from "Project"， then select "C++ Source File".

Write code in empty source file.

#include <stdio.h>
#include <windows.h>
#include "C:\Program Files\Advantech\AdvCan\Include\AdvCan.h"

void main()
{
HANDLE hDevice = NULL;
CanStatusPar_t CanStatus;
BOOL flag;
ULONG dwReturned;
//Open Can Port "CAN1".
//You can also change "CAN1" to a port name which you have installed.
hDevice = CreateFile("\\\\.\\can1",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,OPEN_EXISTING,
0,
NULL);
if ( hDevice == INVALID_HANDLE_VALUE )
{
printf( "Open Can Port Error!" );
return;
}

// 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( "Baud = %u\n", CanStatus.baud );
printf( "Self reception = %u\n" , CanStatus.selfreception );
printf( "Read time out = %u\n" , CanStatus.readtimeout );
printf( "Write time out = %u\n" , CanStatus.writetimeout );

//Close port handle
flag =CloseHandle(hDevice);
if ( !flag )
{
printf( "Close Error!");
return;
}
}


Test application

Run the application, the following result will be displayed.


Program_VB

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.


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.

(Please refer to relevant books and documentations regarding detailed information about VB development.)

Please follow the following procedures to create a new VB project:

  1. Select "File"->"New Project" from the main menu. For Project Types, select Standard EXE.

A new VB project is created.


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.bas)

2. Design graphical interfaces. Add one Button and six Text controls to Form1.


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("\\.\can1", GENERIC_READ + GENERIC_WRITE, 0&, 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL + FILE_FLAG_OVERLAPPED, 0&) 'Open the CAN port in synchronous mode
   If hDevice = &HFFFFFFFF Then
      MsgBox ("Open Error!")
      Exit Sub
   End If
   'Get Can port status.
   result = DeviceIoControl(hDevice, CAN_IOCTL_STATUS, Nothing, 0&, Status, Len(Status), dwOutLen, 0&)
   If Not result Then
      MsgBox ("GetStauts Error!")
      Exit Sub
   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.WriteTimeOut)
   result = CloseHandle(hDevice) 'Close the CAN port
   If Not result Then
      MsgBox ("Failed to close the CAN port!")
   End If
End Sub


Program_VC

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.


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.)

Please follow the following procedures to create a new VC.NET project:

1. Select "File/New->Project" from the main menu to create a new application project and source file. Define the type of the new project as "Windows Forms Application", and select a path for files of the project.

2. Click "OK" according to the instructions on the screen.

A new VC.NET project is created.


Add necessary files

1. Add Include header files (AdvCan.h) in Advantech CAN Windows WDM&CE Driver. In VC.NET work area, right click "Header Files" and select "Add

->Existing Item" to add header files to the project in the "Add Existing Item - Test" file list.

2. Design graphical interfaces. Add one Button and six Text controls to Form1.


Write code

Write code in source file.

#include <windows.h>
#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 = "\\\\.\\" + "can1";
TCHAR* LWCanPortName= static_cast<TCHAR*>(System::Runtime::InteropServices::Marshal::StringToCoTaskMemAuto( CanPortName).ToPointer());
hDevice = CreateFile( LWCanPortName,GENERIC_READ | GENERIC_WRITE,0,(LPSECURITY_ATTRIBUTES)lpSecurityAttributes,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,NULL);
if( (unsigned int)hDevice == 0xffffffff )
{
MessageBox::Show("Open CAN port Error!");
return;
}

//Get Can port status.
result = DeviceIoControl( hDevice,(ULONG)CAN_IOCTL_STATUS,&cmd,0,&CanStatus,sizeof(CanStatusPar_t),(LPDWORD)&dwOutLen,&ov);
if( !result )
{
MessageBox::Show("GetStauts Error!");
return;
}

this->textBox1->Text = "Baud rate = " + CanStatus.baud.ToString();
this->textBox2->Text = "Accept code = " + CanStatus.acceptancecode .ToString("X2");
this->textBox3->Text = "Mask code = " + CanStatus.acceptancemask .ToString("X2");
this->textBox4->Text = "Self recevie = " + CanStatus.selfreception .ToString();
this->textBox5->Text = "Read TimeOut = " + CanStatus.readtimeout .ToString();
this->textBox6->Text = "Write TimeOut= " + CanStatus.writetimeout .ToString();
result = CloseHandle( hDevice ); //Close the CAN port
if (! result )
{
MessageBox::Show ("GetStauts Error!");
return;
}
}


Program_VB

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.


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 refer to relevant books and documentations regarding detailed information about VB.NET development.)

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.


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.vb)

2. Design graphical interfaces. Add one Button and six Text controls to Form1.


Write code

1. Write corresponding code for Button1.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim hDevice As IntPtr
   Dim status As CanStatusPar_t
   Dim result As Boolean
   Dim dwOutLen As Integer
   Dim ov As New OVERLAPPED

   '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.
   result = DeviceIoControl(hDevice, CAN_IOCTL_STATUS, Nothing, 0, status, Len(status), dwOutLen, ov)
   If Not result Then
      MsgBox("GetStauts Error!")
      Exit Sub
   End If
   TextBox1.Text = "Baud rate= " & status.baud
   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


Program_CSharp

Guide for C# 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 C# environment.


Create a new C# 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 C# development.)

Please follow the following procedures to create a new C# project:

  1. Select "File"->"New"->"Project" from the main menu. For Project Types, select Visual C# Projects. Templates is Windows Application.

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.


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.cs)

2. Design graphical interfaces. Add one Button and six TextBox controls to Form1.


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.GENERIC_READ + AdvCan.GENERIC_WRITE, 0, lpSecurityAttributes, AdvCan.OPEN_EXISTING, AdvCan.FILE_ATTRIBUTE_NORMAL + AdvCan.FILE_FLAG_OVERLAPPED, 0);
   if( hDevice == 0xffffffff )
   {
      MessageBox.Show("Open CAN port Error!");
      return;
   }

   //Get Can port status.
   result = AdvCan.DeviceIoControl(hDevice, AdvCan.CAN_IOCTL_STATUS,ref cmd, 0,ref CanStatus,Marshal.SizeOf (CanStatus),ref dwOutLen,ref ov);
   if( !result )
   {
      MessageBox.Show("GetStauts Error!");
      return;
   }

   textBox1.Text = "Baud rate = " + CanStatus.baud .ToString();
   textBox2.Text = "Accept code = " + CanStatus.acceptancecode .ToString("X2");
   textBox3.Text = "Mask code = " + CanStatus.acceptancemask .ToString("X2");
   textBox4.Text = "Self recevie = " + CanStatus.selfreception .ToString();
   textBox5.Text = "Read TimeOut = " + CanStatus.readtimeout .ToString();
   textBox6.Text = "Write TimeOut= " + CanStatus.writetimeout .ToString();
   result = AdvCan.CloseHandle( hDevice ); //Close the CAN port
   if (! result )
   {
      MessageBox.Show ("GetStauts Error!");
      return;
   }
}


Program_VC

Guide for LabVIEW development

We will introduce the LabVIEW VIs which use "Call Library Function Node" function to call Advantech CAN driver API and describe the format, purpose, and parameters for each VI. In addition, we also introduce how to create a new VI and use can_configure.vi as an example to describe how to design the actual program step by step.


CanStatusPar_t

Data Type

Describe the data type of each object.

Object | Description
 | Boolean ( TRUE or FALSE).
 | String.
 | Cluster of mixed data type.
 | Cluster of numerics.
 | 1-D array of cluster of mixed data type.
 | 1-D array of unsigned byte.
 | 32-bit integer.
 | Unsigned byte [ 8-bit integer ].
 | Unsigned word [ 16-bit integer ].
 | Unsigned long [ 32-bit integer ].


NativeAPI

Introduction to VI

All VIs used in current development are:

acCanOpen.vi | Open CAN port by name.
acCanClose.vi | Close CAN port.
acEnterResetMode.vi | Enter reset mode.
acEnterWorkMode.vi | Enter work mode.
acClearRxFifo.vi | Clear CAN port receive buffer.
acSetBaud.vi | Set baud rate of the CAN Controller..
acSetBaudRegister.vi | Configure baud rate by custom mode..
acSetTimeOut.vi | Set timeout for read and write.
acSetSelfReception.vi | Set support for self reception.
acSetListenOnlyMode.vi | Set listen only mode of the CAN Controller.
acSetAcceptanceFilterMode.vi | Set acceptance filter mode of the CAN Controller.
acSetAcceptanceFilter.vi | Set acceptance filter code and mask of the CAN Controller.
acGetStatus.vi | Get the current status of the driver and the CAN Controller.
acCanWrite.vi | Write CAN message by unsigned char array.
acCanWriteCluster.vi | Write CAN message by structure array.
acCanRead.vi | Read CAN message.
acSetCommMask.vi | Execute SetCommMask of the CAN Controller.
acGetCommMask.vi | Execute GetCommMask of the CAN Controller.
acWaitEvent.vi | Wait CAN message or error to occur.

We list the Advantech CAN driver VIs and describes the format, purpose and parameters for each VI.

All VIs use "Call Library Function Node" to call Advantech CAN driver API at AdvCanVI.dll. The default path is "C:\WINDOWS\system32"; user also can find it at "C:\Program Files\Advantech\AdvCAN\LabVIEW\Bin".


acCanOpen

acCanOpen.vi

Purpose

Open CAN port by name.

Format

Input

CANPort

CANPort is the name of the CAN Port to open.

This name uses the syntax "CANx", where x is a decimal number.

Synchronization

The function will not return until the I/O function call is completed in synchronous mode, while an asynchronous file handle makes it possible for the fnction to return immediately, no matter the I/O operation is completed or not. TRUE, synchronous ; FALSE, asynchronous. Refer to CreateFile.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurred before this VI was called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do any thing.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle

An open handle to the specified CANport for all subsequent Advantech CAN VIs for this object, including the final call to acCanClose.vi.

Overlapped

0 Asynchronous

Overlapped will be clearn and use the CreateEvent API to create a Handle to hEvent of Overlapped.

1 Synchronous (default)

Overlapped will be clearn.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acCanClose.vi

Purpose

Close CAN port by handle.

Format

Input

Handle in

Handle in is the name of the CAN port to close. Refer to CloseHandle.

Overlapped

Close the hEvent handle of Overlapped.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs. If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicated an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acEnterResetMode.vi

Purpose

Stop chip and enter Reset Mode. When users want to configure the SJA1000 chip, use this VI first.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs. If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicated an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acEnterWorkMode.vi

Purpose

Start chip and enter Work Mode. Use this VI after configuring the SJA1000 chip.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurred before this VI was called, this VI will not to execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs. If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicated an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acClearRxFifo.vi

Purpose

Clear CAN port receive buffer by handle in.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acSetBaud.vi

Purpose

Set the baud rate for CAN bus communication.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

Baudrate (K)

This is the standard mode to set baud rate, and the value is in units of K. Refer to Command_par.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acSetBaudRegister.vi

Purpose

This is the custom mode to set the baud rate register for CAN bus communication.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

BTR 0

BTR 0 Timing Registers are used to define the bit-rate on CAN bus. Refer to Command_par.

BTR 1

BTR 1 Timing Registers are used to define the bit-rate on CAN bus. Refer to Command_par.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acSetTimeOut.vi

Purpose

Configure the m aximum waiting time in milliseconds between two messages on the bus.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

ReadTimeOut(ms)

ReadTimeOut is the maximum number of milliseconds to wait to receive messages.

WriteTimeOut(ms)

WriteTimeOut is the maximum number of milliseconds to wait to transmit messages.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acSetSelfReception.vi

Purpose

Configure the CAN bus into Self Reception Mode.

Note, before entering the Self Reception Mode the Reset Mode has to be entered.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

SelfReception

0 Off (default)

Self Reception Mode is disabled. Transmitted frames do not appear in receive buffer.

1 On

Self Reception Mode is enabled. When the message transmitted on the bus, it also entered in the receive buffer.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicated an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acSetListenOnlyMode.vi

Purpose

Configure the CAN bus into Listen Only Mode.

Note: Before entering the Listen Only Mode, you have to enter the Reset Mode first.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

ListenOnly

0 Off (default)

Listen Only Mode is disabled. CAN port can transmit message or receive message.

1 On

Listen Only Mode is enabled. CAN port can only receive frames.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acSetAcceptanceFilterMode.vi

Purpose

Configure the Acceptance Filter Mode of CAN port.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

FilterMode

0 Dual

Refer to Acceptance filtering.

1 Single (default)

Refer to Acceptance filtering.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurred, the value specifies error code that returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs.

2. code - When error occurred, the value specifies error code that returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

buacSetAcceptanceFilter.vi

Purpose

Set the Acceptance code and Acceptance Mask.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

FilterCode

Refer to Acceptance filtering.

FilterMask

Refer to Acceptance filtering.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurred.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acGetStatus.vi

Purpose

Get the CAN port current status.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Status

Return value is structure of CanStatusPar_t. Refer to CanStatusPar_t.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurred.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acCanWrite.vi

Purpose

Write multiple frames to a CAN bus.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

MSG

MSG is an array of frames. Each frame uses the typedef canmsg_t. 4 byes for flags, 4 bytes for cob (In MSDN, this is reserved to set to zero), 4 bytes for id, 2 bytes for length, 8 bytes for data.

And this VI divide MSG array by the size of canmsg_t to calculate how many number of frames to write.

Overlapped

If user uses the synchronous mode at acCanOpen.vi, this parameter can be ignored.

In the other mode, hEvent of Overlapped is the handle from acCanOpen.vi.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs. If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

NumberOfWritten

NumberOfWritten describes how many frames have send.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicated an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acCanWriteCluster.vi

Purpose

Write multiple frames to CAN bus.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

MSG

MSG is an array of clusters. Each cluster represents a CAN frame which uses the typedef canmsg_t.

The dimsize of MSG array represents number of frames to write at one time.

Overlapped

If user use the synchronous mode at acCanOpen.vi, this parameter can be ignored.

In the other mode, hEvent of Overlapped is the handle from acCanOpen.vi.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurred before this VI was called, this VI will not to execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs. If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

NumberOfWritten

NumberOfWritten described how many frames have send.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicated an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acCanRead.vi

Purpose

Read multiple frames from CAN bus.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

Overlapped

If user uses the synchronous mode at acCanOpen.vi, this parameter can be ignored.

In the other mode, hEvent of Overlapped is the handle from acCanOpen.vi.

ReadCount

Indicates the number of frames to read at one time from the CAN bus.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurred before this VI was called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs. If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

MSG

MSG returns an array of frames. Each frame in the array uses the typedef canmsg_t.

NumberOfRead

Specifies the number of frames returned in MSG.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicated an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurs.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acSetCommMask.vi

Purpose

Set the Event flags for CAN port.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

EventMask

This parameter fixes the value of "EV_ERR | EV_RXCHAR". Refer to SetCommMask.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acGetCommMask.vi

Purpose

Get event type set in acSetCommMask.vi.

Format

Input

Handle in

Handle in is the handle which originates from acCanOpen.vi.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

GetEventMask

Return the Event type. Refer to GetCommMask.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occurred.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


acCanOpen

acWaitEvent.vi

Purpose

Wait for one state to occur in this VI.

If state is EX_CHAR, it will read one or more frames from CAN bus. Or if status is EX_ERR, it will return error code. Refer to acSetCommMask.vi.

Format

Input

Handle in

Handle in is the handle originates from acCanOpen.vi.

Overlapped

If user use the synchronous mode at acCanOpen.vi, this parameter can be ignored.

In the other mode, hEvent of Overlapped is the handle from acCanOpen.vi.

ReadCount

Indicates the number of frames to read at one time from the CAN bus.

Error in

Error in is a cluster of 3 elements that describes the error status before this VI executes. If error in indicates that an error occurs before this VI is called, this VI will not execute its function, and pass the error through to its error out cluster.

1. status - Status is true when error occurs; If status is true, this VI will not do anything.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.

Output

Handle out

Handle out is the handle for the next Advantech CAN driver VI.

MSG

MSG returns an array of frames. Each frame in the array uses the typedef canmsg_t.

NumberOfRead

Specifies the number of frames returned in MSG.

ErrorCode

Return error code when the CAN Controller has error.

Error out

Error out is a cluster of 3 elements that describes error conditions. If the Error in cluster indicates an error, this VI will not do anything, and the Error out cluster contains the same error information of error in. Otherwise, Error out describes the error status of this VI.

1. status - Status is true when error occur s.

2. code - When error occurs, the value specifies error code returned by the GetLastError function of Windows API.

3. source - This string describes the origin of the error.


Program_CSharp

Guide for LabVIEW 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 LabVIEW environment.


Create a new LabVIEW VI

Please follow the following procedures to create a new LabVIEW VI:

   1. Select "File"->"New VI" from the main menu.

2.You will have two screens available now. One is the "front panel" and the other one is called "Block Diagram". Front Panel will always have the "controls" and "indicators" required by the program to show the input and output parameters. "Block diagram" will have the detailed graphical representation of the actual program.


Add the can_configure.vi each vi will be used.

We use example "can_configure.vi" to describe how to design the function on block Diagram. Please refer to ConfigureFlowChart for the design flow chart.

1. Right click on block diagram and select Select a VI....

2. Use the advcanvi.llb or common.llb to open VI, and then select a VI added to the block panel. The default path of *.llb file is "C:\WINDOWS\system32"; user can also find it at "C:\Program Files\Advantech\AdvCAN\LabVIEW".

  3. Repeat steps one and two, then your block diagram should look like the diagram below.


Create & Wiring

1.Right click on input side of the VI and create control by selecting Create»Control or create constant by selecting Create»Constant.

Right click on output side of the VI and create indicator by selecting Create»Indicator.

Then wiring each VI as the following figure.

2. You can modify indicator of Status by "Unbundle By Name"function and "Bundle" function.

Right click on block diagram to search LabVIEW VI to use. "Unbundle By Name" used to capture elements of Status that you want. Refer to acGetStatus.vi.

'Bundle' is used to bundle elements in an existing cluster.

3.The block diagram will then show the following graphical program on the screen.


Run

Run the VI at front panel, and the following result will be displayed.


Example_Receive

Examples

Advantech CAN Windows WDM&CE Driver package contains examples of VC, VB, VB.NET, C#.NET, VC.NET, LabVIEW, eVC. Users can refer to these examples to develop applications.

WDM:

Example Name | Description | VC | VB | VB.NET | C#.NET | VC.NET | LabVIEW
Can Configure | This example shows how to configure each item of CAN port. | Yes | Yes | Yes | Yes | Yes | Yes
Can Send | This example shows how to send data to CAN port. | Yes | Yes | Yes | Yes | Yes | Yes
Can Receive | This example shows how to receive data from CAN port. | Yes | Yes | Yes | Yes | Yes | Yes
Can Event | This example shows how to receive/send data from/to CAN port through events in the way similar to serial port communication. | Yes | Yes | Yes | Yes | Yes | Yes

CE:

Example Name | Description | VB.NET | C#.NET | VC.NET | eVC
Can Configure | This example shows how to configure each item of CAN port. | Yes | 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 events in the way similar to serial port communication. | Yes | Yes | Yes | Yes


Example_Receive

Send

Data is sent. Values of Baud Rate and timeout of the port can be set.

Please refer to Send 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. If the user chooses Custom, you should write values of BTR0 and BTR1 manually in the textbox. Type value of timeout in Timeout filed (The default value is 3000 ms). Selecting RTR check box can realize RTR function. On Windows platform, the user can select either synchronous mode or asynchronous mode. While on WinCE platform, only synchronous mode is supported. After configuring the above items, users can click "Start" button to send data .

After clicking "Start" button, the name of the button will change into "Stop". At the same time, results of sent frames will be shown in the textbox on the right. Users can click "Stop" button to stop sending frames during the process, then the name of the button will return to "Start" for the next send operation.

Advantech CAN driver API can send one or more frames each time. In this examples (except for VB6), it send 100 frames each time, please refer to example's source code for further details.

  • Windows

  • WinCE

  • LabVIEW

This example send 100 frames of MSG each time. If user wants to add a frame in MSG, to push the MSG index button up then enter the data, or user wants to delete a frame of MSG, right click the element of MSG to select the "Data Operations" -> "Delete Element". Other settings as mentioned above.

This VI sends the MSG formed by the unsigned char, user can set the flags and ID number of every frame and the "Number to Write " indicates the number of frames of MSG to write each time, but the data is fixed at block diagram. Refer to acCanWrite.vi

This example sends the data of MSG is 0 ~ 99 first, the second transmission is 100 ~ 199.


Example_Receive

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. If the user chooses Custom, you should write values of BTR0 and BTR1 manually in the textbox. Type value of timeout in Timeout filed (The default value is 3000 ms). On Windows platform, the user can select either synchronous mode or asynchronous mode. While on WinCE platform, only synchronous mode is supported. After configuring the above items, users can click "Start" button to receive data.

After clicking "Start" button, the name of the button will change into "Stop". At the same time, results of received frames will be shown in the textbox on the right. Users can click "Stop" button to stop receiving frames during the process, then the name of the button will return to "Start" for the next receive operation.

Advantech CAN driver API can receive one or more frames each time. In this example (except for VB6), it receives 100 frames each time, please refer to example's source code for further details.

  • Windows

  • WinCE

  • LabVIEW

Most settings are as mentioned above. But users must to enter the number into the "NumbertoRead" context to indicate how many frames of MSG received each time.

Hexadecimal switch can switch the decimal or hexadecimal data of MSG.


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.

Before you begin, please select the name of the port you have installed in combobox of CAN Port, such as can0, can1, etc. Select value of Baud Rate that you want in dropdown list of Baud Rate. Select Single or Dual of Acceptance Filter Mode. Enter filter mask for receiving data in the fields of Acceptance Mask and Acceptance Code (The default value is 0xFFFFFFFF). Type values of timeout in Write Timeout and Read Timeout fields (The default value is 3000 ms). After configuring the above items, users can click "Configure" button to change the current setting of the port.

After clicking "Configure" button, successful message and the new configuration information will be displayed if you succeed in configuring. In addition, number of received data and values of controllers will be displayed as well. If the configuration fails, prompting message will be displayed.

Note:

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.

  • Windows

  • WinCE

  • LabView

Users can configure the CAN port then get the information from GetStatus.vi. Users also can see other information of CanStatusPar_t by designiong the GetStatus component in the block panel.


Example_Receive

Event

This function is similar to serial port communication, which sends/receives 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 timeout is fixed at 3000 ms. The user can select RTR check box can realize RTR function. After configuring the above items, users can click "Start" button to send/receive data .

After clicking "Start" button, the name of the button will change into "Stop". At the same time, sent/received results will be shown in both textboxes. The two ports are using duplex communication. Users can click "Stop" button to stop sending/receiving frames during the process, then the name of the button will return to "Start" for the next send/receive operation.

Advantech CAN driver API can send receive and one or more frames each time. In this example (except for VB6), it sends and receives 100 frames each time, please refer to example's source code for further details.

  • Windows

  • WinCE

  • LabVIEW

Most settings are as mentioned above. In addition, the user must enter the number of frames of MSG for CAN bus to send or receive. In this application, users can set Flags, RTR frame, and ID number, but the data is fixed.

In this example frames of MSG is set to 100, so data of MSG sens 0 ~ 99 first, the second transmission is 100 ~ 199.


Example_Receive

Send flow chart


Example_Receive

Receive flow chart


Example_Receive

Configure flow chart


Example_Receive

Event flow chart

Either flow chart of the two sub threads is as below:


Structure List

CAN Message Filter

CAN Message Filter has four modes. The selection will only affect CAN display.

Mode | Function
SFF | Whether to show the Standard frame. After this mode is selected, filter will start from the setting if it is receiving data. The Standard frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The Standard frame can be showed.
EFF | Whether to show the Extended frame. After this mode is selected, filter will start from the setting if it is receiving data. The Extended frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The Extended frame can be showed.
RTR | Whether to show the Remote frame. After this mode is selected, filter will start from the setting if it is receiving data. The Remote frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The Remote frame can be showed.
Self Reception | Whether to show the self reception frame. After this mode is selected, filter will start from the setting if it is receiving data. The self reception frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The self reception frame can be showed.


Structure List

CANopen Message Filter

CANopen Message Filter is divided into two parts:

  • The analytic method of COB-ID

Users can select to analyze COB-ID according to pre-defined connection of CANopen or according to EDS file. The default selection is the pre-defined connection.

  • Show the messages

The selection will only affect CANopen interface display.

Mode | Function
SDO | Whether to show SDO (Service Data Object) frame. After this mode is selected, filter will start from the setting if it is receiving data. The SDO frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The SDO frame can be showed.
PDO | Whether to show PDO (Process Data Object) frame. After this mode is selected, filter will start from the setting if it is receiving data. The PDO frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The PDO frame can be showed.
NMT | Whether to show NMT (Network Management) frame. After this mode is selected, filter will start from the setting if it is receiving data. The NMT frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The NMT frame can be showed.
NMT Error Control | Whether to show NMT Error Control (Error Control services) frame. After this mode is selected, filter will start from the setting if it is receiving data. The NMT Error Control frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The NMT Error Control frame can be showed.
EMCY | Whether to show EMCY (Emergency Object) frame. After this mode is selected, filter will start from the setting if it is receiving data. The EMCY frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The EMCY frame can be showed.
TIME-STAMP | Whether to show TIME-STAMP (Time Stamp Object) frame. After this mode is selected, filter will start from the setting if it is receiving data. The TIME-STAMP frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The TIME-STAMPframe can be showed.
SYNC | Whether to show SYNC (Synchronisation Object) frame. After this mode is selected, filter will start from the setting if it is receiving data. The SYNC frames received later can be showed. If it is not receiving data, i.e., file data is being viewed or the communication is stopped, filter will start form the first frame of the message. The SYNC frame can be showed.


CAN_MSG

CANopen Message View

CANopen Message View is shown as below:

Column | Function
No | The number of the message.
Time | The time to open device; the smallest unit is ms.
Protocol | The protocol type of CANopen message.
ID or ID (HEX) or ID (ASCII) | The ID of the message. Click the column name, and then the data in the column will switch between decimal system, hexadecimal system and ASCII system.
Data or Data (HEX) or Data (ASCII) | The data of the message. Click the column name, and then the data in the column will switch between decimal system, hexadecimal system and ASCII system.
Info | The explanation of the message.


Structure List

Send CAN Message

If the user is not at Listen Only mode, please click Function/CAN/Send CAN Message. Then Send CAN Message dialog box pops up:

Name | Function
ID | CAN message ID.
Flag | SFF: Standard Frame; EFF: Extended Frame.
RTR | Whether this message is a Remote frame.
Self Reception | Whether to enable self reception. If it is enabled, the user can see the message sent by himself.
Cycle | Whether to send repeatedly.
ms | The interval period of the cycle.
Auto Increase | The data sent will increase automatically. If check it, user do not to input length and data.
Length | The length of the message, from 1 to 8.
Data | The data sent, up to 8 byte.
Send Time Out | Time out of sending the data.


CAN_MSG

CAN Message View

CAN Message View is shown as below:

Column | Function
No | The number of the message.
Time | The time to open device; the smallest unit is ms.
Tx/Rx | Sends or receives the message.
ID or ID (HEX) or ID (ASCII) | The ID of the message. Click the column name, and then the data in the column will switch between decimal system, hexadecimal system and ASCII system.
Flag | Shows the message type: SFF, EFF, RTR, Self Reception.
Length | The data length of the message.
Data or Data (HEX) or Data (ASCII) | The data of the message. Click the column name, and then the data in the column will switch between decimal system, hexadecimal system and ASCII system.


Structure List

Send CAN Message

If the system is not at the Listen Only mode, please click Function/CANopen/Change Node State. Then the Change Node State dialog box pops up:

Users can change the CANopen node state detected.

Name | Function
Node ID | Selects node.
Current State | The current state of the node.
New State | The state of the node changed.


Structure List

Clear Data

Click the toolbar or the menu File -> Clear to delete all the data currently stored in CANMonitor.


Structure List

Close Device

Click the toolbar or the menu File -> Close to close the device and abandon all the data received.


Structure List

Goto

Click the toolbar or the menu File -> Goto, users will see the below interface:

After entering the line number in Text Box, click Goto button will go to the specified line.


Structure List

Listen Only Mode

Under Listen only mode, the system will not send answer message after receiveing CAN message. This can ensure that CANMonitor will not be a burden to the network, with an exception to that the user of CANMonitor needs to send message.


Structure List

List Node

If the system is not at the Listen Only mode, click the Function/CANopen/List Node. Then the List Node dialog box pops up.

Here users can see all CANopen nodes and their states detected.


Structure List

Load Data from File

Click the toolbar or the menu File -> Load, and then CANMonitor will load message from the file that saves data.


Structure List

Detect All Nodes in CANopen

If the system is not at the Listen Only mode, click Function/CANopen/Node Guard All. Then CANMonitor will detect all the nodes in CANopen.


Structure List

Open Device

Click the toolbar or the menu File -> New, the "New Connecting..." dialog box for opening device pops up:

Users should select CAN device first, and then configure Baudrate, Acceptance Code, Acceptance Mask. Users should set Max Rows In View, which decides the number of CAN messages that should be saved (Min: 1000; Max: 1000000).


Structure List

Save Data to File

Click the toolbar or the menu File -> Save, and then CANMonitor will save the messages received to the file with the suffix of acb.


Structure List

Scroll

If the toolbar or the menu File -> Auto Scroll is selected and the new data is being sent or received, CANMonitor will automaticaly show the data in the last line.


Structure List

Read Data from Node

If the system is not at the Listen Only mode, click Function/CANopen/Read object. The Read Object dialog box pops up:

Users can read data of a certain node that has been detected.

Name | Function
Node ID | Selects node.
Index | Index.
Sub Index | Sub index.
Read Length | Data length returned.
Return Value | Return value. If the operation is failed, error message will be returned.


Structure List

Write Data to Node

If the system is not at the Listen Only mode, click Function/CANopen/Write object. The Write Object dialog box pops up:

Users can change data of a certain node that has been detected.

Name | Function
Node ID | Selects node.
Index | Index.
Sub Index | Sub index.
Write Length | Data length to be sent.
Write Value | Data to be sent.
Return Value | Correct: Ok; Error: Error code; Timeout: Timeout.


Structure List

Show the Message and Hide the Message

If the communication is started, click the toolbar or the menu File -> Show. Then the user can see the messages being received and sent.

Click the toolbar or the menu File -> Hide, and CANMonitor will hide the messages being sent and received.


Structure List

Start Communication

Click the toolbar or the menu File -> Start, and CANMonitor will use the configuration before stopping the current communication to restart communication.


Structure List

Stop Communication

Click the toolbar or the menu File -> Stop, and CANMonitor will stop the current communication.