using labview via the canape com interface · using labview via the canape com interface version...

15
Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public Document Abstract The Application Note shows how to create a client application in LabView using the CANape COM interface to access the ECU. Table of Contents 1 Overview ........................................................................................................................................2 1.1 Requirements .......................................................................................................................2 2 Include the CANape COM Interface into the LabView environment ........................................3 3 Set up the communication between CANape and LabView......................................................7 3.1 Instantiation ..........................................................................................................................7 3.2 Initialization ..........................................................................................................................8 3.3 Attach an ECU device ........................................................................................................10 4 Set up a measurement in LabView ............................................................................................11 4.1 Select an ECU measurement mode ..................................................................................11 4.2 Selection of the ECU measurement signals ......................................................................11 4.3 Measurement start in LabView ..........................................................................................13 4.4 Receiving the measurement data ......................................................................................13 4.5 Stopping the measurement ................................................................................................14 4.6 Closing the measurement session .....................................................................................15 5 Contacts .......................................................................................................................................15

Upload: trinhhuong

Post on 11-May-2019

285 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface Version 1.0

2017-12-05

Application Note AN-IMC-1-036

Author Knoll, Steffen

Restrictions Public Document

Abstract The Application Note shows how to create a client application in LabView using the CANape COM interface to access the ECU.

Table of Contents

1 Overview ........................................................................................................................................ 2 1.1 Requirements ....................................................................................................................... 2

2 Include the CANape COM Interface into the LabView environment ........................................ 3 3 Set up the communication between CANape and LabView...................................................... 7

3.1 Instantiation .......................................................................................................................... 7 3.2 Initialization .......................................................................................................................... 8 3.3 Attach an ECU device ........................................................................................................10

4 Set up a measurement in LabView ............................................................................................11 4.1 Select an ECU measurement mode ..................................................................................11 4.2 Selection of the ECU measurement signals ......................................................................11 4.3 Measurement start in LabView ..........................................................................................13 4.4 Receiving the measurement data ......................................................................................13 4.5 Stopping the measurement ................................................................................................14 4.6 Closing the measurement session .....................................................................................15

5 Contacts .......................................................................................................................................15

Page 2: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 2 Contact Information: www.vector.com or +49-711-80 670-0

1 Overview

The purpose of this application note is to create a client application in LabView using the CANape

COM interface to access the ECU. This application note describes how to include the CANape COM

interface in LabView, how to set up the communication with CANape and how to configure and start a

measurement.

The block diagram in Figure 1 shows the system setup of the interface between LabView and CANape

and between CANape and the ECU.

Figure 1:

1.1 Requirements

This application note is based on LabView version 2014 and CANape 4.0 or higher. Both applications

have to be installed on the computer. Since CANape 13.0 it is also possible to install the CANape

COM interface on a second PC. In this case the CANape COM interface uses a TCP connection to

CANape server. This application note describes the usage of the client interface on a local PC.

After installation of CANape, the CANape COM interface is registered in the Microsoft windows

registry. From now on CANape is ready to work as a COM Server.

Page 3: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 3 Contact Information: www.vector.com or +49-711-80 670-0

2 Include the CANape COM Interface into the LabView environment

First create a new LabVIEW project. The LabVIEW project select dialog appears automatically after

start of LabVIEW (Figure 2)

Figure 2

After a new project is created, it is possible to select a project template. For this is example a blank

project is used (Figure 3)

Figure 3

Page 4: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 4 Contact Information: www.vector.com or +49-711-80 670-0

Figure 4

After a new project is created, the project explorer shows an empty project without any VI file.

(Figure 4)

Figure 5

With a right click on the project root node, a new open a new VI file can be created an added to the

project. (Figure 5 and Figure 6)

Page 5: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 5 Contact Information: www.vector.com or +49-711-80 670-0

Figure 6

The first step to get access to CANape COM in a LabView project the COM interface must be

instantiated. Therefore, the LabView object “Automation Refnum” has to be selected (Figure 6).

To select the requested automation interface, LabView offers the “Select ActiveX Class\Browse…”

function to select the CANape 1.9 Type Library in a dropdown box. (Figure 7)

After this LabView displays a new icon in the Application window. This icon is also displayed in the

Diagram window. With a right mouse click on the icon, CANape COM can be selected.

(Figure 6 and 7)

Figure 7

Page 6: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 6 Contact Information: www.vector.com or +49-711-80 670-0

Per Drag&Drop the ActiveX-Refnum object has to be placed in the LabView Frontpanel page. Right

click the icon with the mouse, select the ActiveX Class item and select the CANAPELib.IApplication

from the pop up menu (see Figure 7).

Figure 8

After selection of CANape COM interface the LabView icon changes to the view which is shown in

Figure 9. CANAPELib.iApplication represents the root interface of the CANape COM application

model.

Figure 9

Page 7: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 7 Contact Information: www.vector.com or +49-711-80 670-0

3 Set up the communication between CANape and LabView

3.1 Instantiation

After the declaration of the CANape COM interface an object of this type needs to be instantiated.

Therefore, the LabView object “Open ActiveX-Object” has to be selected via the popup menu of the

CANAPELib.IApplication on LabView’s Block diagram page (Figure 5).

Figure 10

Figure 11

To use the CANape COM interface the output of the object “CANAPELib.IApplication” must be

wired with the input of the”Automation open” object (Figure 12). LabView can now use the CANape

COM interface methods and properties. At the end of a LabView session, the CANape COM

automation interface must be closed. We will discuss this topic in a later section.

Page 8: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 8 Contact Information: www.vector.com or +49-711-80 670-0

3.2 Initialization

Figure 12

To start and initialize CANape in the automation mode the “Open” method must be used. This

method is delivered by the interface “CANAPELib.IApplication”. To include this method in LabView’s

block diagram the object “Invoke Node” must be used. This object has to be wired with the object

“Automation open” (Figure 8) and the desired method “Open” can be selected via the popup menu

(Figure 12).

Figure 13

The method “Open” has two parameters. The first parameter describes the path to the working

directory of CANape. The working directory must contain the ECU description file in the ASAP2 (*.a2l)

file format. The second parameter is used as a debug flag. CANape will use the flag information to

Page 9: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 9 Contact Information: www.vector.com or +49-711-80 670-0

decide whether the CANape “Write Window” should be hidden or displayed. More information about

the Write Window is available in the CANape manual.

To get a clearer arrangement in this example the initialization sequence is placed into an own frame

(Figure 16). This can be realized by using the “Stacked Sequence” element. In the LabView

Frontpanel three “String Input Elements” have to be placed for specifying the Working Directory, the

Device Name and the ECU’s A2l file name. Add an on/off switch element for the debug flag. Connect

in the Bock diagram the labeled String Input Element “Working Directory” to the “workDir”

connector. Add a Boolean to (0:1) converter element in the Block diagram and connect it with the

“CANape debug” element and to the “debug” connector (Figure 16 and 17).

Figure 14

Figure 15

Page 10: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 10 Contact Information: www.vector.com or +49-711-80 670-0

3.3 Attach an ECU device

To attach the ECU to CANape additional information is needed from LabView. The used driver type e.g. CCP or XCP and the ECU description file (*.a2l) must be defined.

Add a stacked sequence element and redo the same steps as previously described to add a

“CANAPELib.Devices” instance. Add then the different elements as shown in Figure 11 and connect

the previously defined String Input Elements to the interface connectors.

Figure 16

The wire of “IApplication” is delivered by the previous frame (Figure 16). The first step is to read out

the “IDevices” interface using the property IApplication.Devices”.

To attach a new device the method “IDevices.Add” has to be used. This method has four

parameters. The first parameter describes the information about the device name. The second

parameter describes the name and location of the *.a2l file. The third parameter defines the used

protocol, e.g. CCP or XCP and the last parameter defines the CAN channel which is used to connect

the ECU to CAN hardware.

In this example, the Vector CCPsim ECU Simulator is used. Therefore, the driver “CCP” is used as

“DriverType” and CAN channel 1 is defined as communication interface between CANape and the

ECU.

With these settings in LabView the CCPSim ECU simulator can be accessed by CANape.

Page 11: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 11 Contact Information: www.vector.com or +49-711-80 670-0

4 Set up a measurement in LabView

4.1 Select an ECU measurement mode

In this example three measurement signals from the ECU will be measured in the polling mode. In the

first step, the ECU Measurement mode must be selected. Depending on the ECU implementation

several measurement modes are available and can be selected. Via the “task ID” the ECU

measurement mode is selected. Therefore the “CANAPELib.ITasks” interface is needed. “ITasks” is

a property of “IDevice.ITasks” and is designed to ask the ECU about the implemented tasks. In this

example, the task with the ID 1 will be selected and this means that the “polling” measurement mode

will be used. The selected task is delivered as an “ITask” interface. It is delivered as a return value of

the method “ITasks.item”.

Add a frame behind the new stacked sequence element and redo the same steps as previously

described to add a “CANAPELib.ITasks” instance. Add and connect in the next steps the different

elements as shown in Figure 19.

Figure 17

4.2 Selection of the ECU measurement signals

To select the ECU measurement signals the client application (LabView) has to know their names.

Because the CANape COM implementation is based on ASAP 3 V 2.1 functionality there is no

possibility to ask the server for the object names defined in the ECU description file (ASAP2 file, *.a2l).

(Figure 20)

Page 12: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 12 Contact Information: www.vector.com or +49-711-80 670-0

Figure 18

To declare the measurement objects the interface “IChannels” is needed. This interface is delivered

by the property “ITask.Channels”. To add the measurement signals into the measurement signal list

of CANape the method “IChannels.Add” must be used. This method has one parameter which

describes the name of a measurement object (Figure 20). In the LabView front panel three “String

Input Elements” needs to be placed for specifying the CCPSim channel1 to 3 (Figure 21).

Figure 19

Page 13: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 13 Contact Information: www.vector.com or +49-711-80 670-0

4.3 Measurement start in LabView

Figure 20

To start the measurement in LabView the “IMeasurement” interface is required. “IMeasurement” is

a property of the interface “IApplication”. The return parameter must be declared in LabView with a

”To G Data” Object”. (See section 3.3)

The interface “IMeasurement“ provides two methods:

> IMeasurement.Start and > IMeasurement.Stop to stop the measurement again.

To start a measurement the method “IMeasurement.Start” (Figure 22) is used.

4.4 Receiving the measurement data

Figure 21

To receive measurement data the method “ITask.NextSample” is used. One way to call this method

repeatedly, is to implement a while loop (Figure 23). If the calling frequency of this method is higher

than the sampling rate the method will return with an error. A timer is included into the while loop to

avoid this case.

Page 14: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 14 Contact Information: www.vector.com or +49-711-80 670-0

To get an output on the screen a “LabView Array Object” must be used (Figure 24). Additional the

array must be filled with a “Digital Indicator Object”. To fill the object with the measurement results the

object should be wired to the “G Data Object”.

Figure 22

4.5 Stopping the measurement

Figure 23

To stop a measurement session the method “IMeasurement.Stop” should be called. This method is

part of the “IMeasurement “ interface.

Page 15: Using LabView via the CANape COM Interface · Using LabView via the CANape COM Interface Version 1.0 2017-12-05 Application Note AN-IMC-1-036 Author Knoll, Steffen Restrictions Public

Using LabView via the CANape COM Interface

Copyright © 2017 - Vector Informatik GmbH 15 Contact Information: www.vector.com or +49-711-80 670-0

4.6 Closing the measurement session

Figure 24

To close the VI sequence at the end, each COM interface has to be released in order of their

dependency on each other. In this example, the release order has to be done in this way:

> IMeasurement > IChannels > ITask > Itasks > IDevice > IDevices

Before releasing the “IApplication” interface the method “IApplication.Quit” must be called. This

method cleans the CANape internal interface and closes CANape at the end. It is impossible to get a

new connection to CANape without calling this method (Figure 26).

5 Contacts

For a full list with all Vector locations and addresses worldwide, please visit http://vector.com/contact/.