You are on page 1of 6

Using LXI Devices in CANoe

Version 1.0
2013-08-13
Application Note AN-IND-1-016

Author(s)
Restrictions
Abstract

Messer, Matthias
Open Document
Introduction on how to create a module-to-module LXI connection with CAPL

Table of Contents
1.0
1.1
2.0
2.1
2.2
2.3
2.4
2.5
2.6
3.0

Overview .......................................................................................................................................................... 1
Use Case / Motivation ................................................................................................................................... 1
Module-to-module communication with LXI ..................................................................................................... 1
Creating a network node ............................................................................................................................... 3
Including the IP addresses ............................................................................................................................ 3
Initiliazing a socket ........................................................................................................................................ 3
Closing a socket ............................................................................................................................................ 4
Receiving data messages ............................................................................................................................. 4
Sending data messages ................................................................................................................................ 4
Contacts ........................................................................................................................................................... 6

1.0 Overview
CANoe provides the possibility to control external devices with an LXI interface. The LXI commands can be sent as
data packets in TCP messages using CAPL. This application note describes how to communicate with LXI devices
in CANoe.

1.1 Use Case / Motivation


Power supplies and measurement devices often have an LXI interface for remote control. To use those devices in
an automated test setup, it is necessary to have access to the LXI interface in CANoe. The communication with
CANoe and an LXI device can be implemented using manually written CAPL code. The extent and complexity of
the code depends on the use case. Typically a few lines of code are sufficient as described in this application note.

2.0 Module-to-module communication with LXI


This application note explains how to establish a module-to-module connection between a PC and an LXI power
supply. A kind of a device driver is defined in CAPL. This CAPL node may be added to the test setup and
provides an interface between the test application in CANoe and the LXI device. System variables are typically
used as the interface mechanism in CANoe.
To implement an LXI communication in the driver node, a TCP socket must be created. This socket is used to
establish a connection between CANoe and the device and for handling the data protocols. The CAPL code below
shows a simple connection between CANoe and a LXI power supply.
The output voltage of the power supply can be set to a specific value with the system variable var_Voltage. The
output itself can be activated or deactivated by pushing the key o. In addition the identification of the power supply
can be requested by changing the system variable var_ID to the value 1.

Copyright 2013 - Vector Informatik GmbH


Contact Information: www.vector.com or +49-711-80 670-0

Using LXI Devices in CANoe

Important:

For this example the power supply CPX400SA from TTi was used. Some of the commands are
device-dependent and can be different for other power supplies. Please read the appropriate user
manual of the device for the correct commands.

variables
{
dword address_canoe;
dword address_power_supply;
dword port = 9221; // used port
char buffer_id[16] = "*idn?"; // Identification command
char buffer_send_volt[128];
char buffer_receive[128];
int output = 0; // output activate/deactivate
}

dword LXI_socket;

on preStart
{
address_canoe = IpGetAddressAsNumber("192.168.100.1"); // IP address PC
address_power_supply = IpGetAddressAsNumber("169.254.4.226"); // IP address power
supply
}
on start
{
LXI_socket = TcpOpen(address_canoe, port); // creation of an IP socket
TcpConnect(LXI_socket, address_power_supply, port); // connecting the IP socket
}
on stopMeasurement
{
TcpClose(LXI_socket);
}
on sysvar sysvar::LXI_Variables::var_ID // identification request
{
if(1 == @this)
{
TcpSend(LXI_socket, buffer_id, strlen(buffer_id));
TcpReceive(LXI_socket, buffer_receive, strlen(buffer_receive)); // Function to
receive data packets
}
}
on sysvar sysvar::LXI_Variables::var_Voltage // set voltage
{
snprintf(buffer_send_volt, elcount(buffer_send_volt), "V1 %f", @this); // creation
of the command string
TcpSend(LXI_socket, buffer_send_volt, strlen(buffer_send_volt));
TcpReceive(LXI_socket, buffer_receive, 128);
}
Application Note AN-IND-1-016

Using LXI Devices in CANoe

on key 'v' // measured output voltage


{
TcpSend(LXI_socket, "V1 O?", strlen("V1 O?"));
TcpReceive(LXI_socket, buffer_receive, 128);
}
on key 'o' // activate/deactivate output
{
if(0 == output)
{
TcpSend(LXI_socket,"OP1 1", strlen("OP1 1"));
output = 1;
}

else
{
TcpSend(LXI_socket,"OP1 0", strlen("OP1 0"));
output = 0;
}

void OnTcpReceive( dword socket, long result, dword address, dword port, char
buffer[], dword size) // receive function
{
write("Received: %s", buffer); // output of the received string
TcpReceive(LXI_socket, buffer_receive, 128);
}

2.1 Creating a network node


To create an interface a network node must be inserted into the test setup (View Test Setup right-click
New Test Environment Insert Network Node). The specification (.can file) for this node is the CAPL file
describing the interface.

2.2 Including the IP addresses


To initialize the necessary socket for the communication the IP address of the PC and the power supply has to be
converted from a string (e.g. 192.168.100.1) into a numerical value that can be used by the CAPL program. For
this the CAPL function IpGetAddressAsNumber in the on preStart event handler is used.
on preStart
{
address_canoe = IpGetAddressAsNumber("192.168.100.1"); // IP address PC
address_power_supply = IpGetAddressAsNumber("169.254.4.226"); // IP address power
supply
}

2.3 Initiliazing a socket


After the IP addresses are converted the socket must be initiated. This can be done with the CAPL function
TcpOpen. This function needs the IP address of the PC and a port for the communication. Please remember that it
has to be a port that is not used by another program, in this case port 9221. After the socket is created it must be
3
Application Note AN-IND-1-016

Using LXI Devices in CANoe

connected to the used device with the function TcpConnect. For this the devices IP address is needed and a port
must be selected. Both ports can be the same. The necessary functions are part of the on start event handler.
on start
{
LXI_socket = TcpOpen(address_canoe, port); // creation of an IP socket
TcpConnect(LXI_socket, address_power_supply, port); // connecting the IP socket
}

2.4 Closing a socket


When the measurement is stopped the socket has to be closed with the function TcpClose. This function is part of
the on stopMeasurement event handler.
on stopMeasurement
{
TcpClose(LXI_socket);
}

2.5 Receiving data messages


The function TcpReceive is used to receive data into a specified buffer. The function has to be called before the
first packet is received, for example when the connection is established. Usually an answer cant be immediately
sent by the LXI device. The function OnTcpReceive must be used to capture an asynchronous packet and write it
into the buffer. Receiving a packet completes the data transfer and a new packet cant be received anymore unless
the function TcpReceive is called again. The best solution would be to call the receive function again in the
function OnTcpReceive.
void OnTcpReceive( dword socket, long result, dword address, dword port, char
buffer[], dword size) // receive function
{
write("Received: %s", buffer); // output of the received string
TcpReceive(LXI_socket, buffer_receive, 128);

2.6 Sending data messages


The function TcpSend is used to send a command to the device. The command is send as data of the TCP
package and is written in ASCII (e.g. *idn?). The function TcpSend adds the necessary header to the packet so
that the command is only the necessary ASCII code. The available commands for a device are specified in the
appropriate manual. They are normally divided into device-dependent and -independent commands. The two event
handlers on sysvar are used to get the identification of the power supply and to set the output voltage. The two
event handlers on key are used to request the measured output voltage of the power supply and to switch the
output itself on and off.

Application Note AN-IND-1-016

Using LXI Devices in CANoe

on sysvar sysvar::LXI_Variables::var_ID // identification request


{
if(1 == @this)
{
TcpSend(LXI_socket, buffer_id, strlen(buffer_id));
TcpReceive(LXI_socket, buffer_receive, strlen(buffer_receive)); // Function to
receive data packets
}
}
on sysvar sysvar::LXI_Variables::var_Voltage // set voltage
{
snprintf(buffer_send_volt, elcount(buffer_send_volt), "V1 %f", @this); // creation
of the command string
TcpSend(LXI_socket, buffer_send_volt, strlen(buffer_send_volt));
TcpReceive(LXI_socket, buffer_receive, 128);
}
on key 'v' // measured output voltage
{
TcpSend(LXI_socket, "V1 O?", strlen("V1 O?"));
TcpReceive(LXI_socket, buffer_receive, 128);
}
on key 'o' // activate/deactivate output
{
if(0 == output)
{
TcpSend(LXI_socket,"OP1 1", strlen("OP1 1"));
output = 1;
}

else
{
TcpSend(LXI_socket,"OP1 0", strlen("OP1 0"));
output = 0;
}

Application Note AN-IND-1-016

Using LXI Devices in CANoe

3.0 Contacts

Germany
and all countries not named below:

France, Belgium, Luxemburg:

Sweden, Denmark, Norway,


Finland, Iceland:

Vector Informatik GmbH


Ingersheimer Str. 24
70499 Stuttgart
GERMANY
Phone: +49 711-80670-0
Fax:
+49 711-80670-111
E-mail: info@de.vector.com

Vector France S.A.S.


168, Boulevard Camlinat
92240 Malakoff
FRANCE
Phone: +33 1 42 31 40 00
Fax:
+33 1 42 31 40 09
E-mail: information@fr.vector.com

VecScan AB
Theres Svenssons Gata 9
41755 Gteborg
SWEDEN
Phone: +46 31 764 76 00
Fax:
+46 31 764 76 19
E-mail: info@se.vector.com

United Kingdom, Ireland:

China:

India:

Vector GB Ltd.
Rhodium, Central Boulevard
Blythe Valley Park
Solihull, Birmingham
West Midlands B90 8AS
UNITED KINGDOM
Phone: +44 121 50681-50
Fax:
+44 121 50681-69

Vector Informatik India Pvt. Ltd.


4/1/1/1, Sutar Icon, Sus Road,
Pashan, Pune - 411 021
INDIA

E-mail: info@uk.vector.com

Vector Automotive Technology


(Shanghai) Co., Ltd.
Sunyoung Center, Room 1601-1603
No.398 Jiang Su Road
Changning District
Shanghai 200050
P.R. CHINA
Phone: +86 21 6432 53530
Fax: +86 21 6432 5308
E-mail: info@cn.vector.com

USA, Canada, Mexico:

Japan:

Korea:

Vector CANtech, Inc.


39500 Orchard Hill Place, Suite 550
Novi, MI 48375
USA

Vector Japan Co. Ltd.


Tennozu Yusen Bldg. 16F
2-2-20 Higashi-shinagawa,
Shinagawa-ku,
Tokyo 140-0002
JAPAN
Phone: +81 3 5769 7800
Fax:
+81 3 5769 6975
E-mail: info@jp.vector.com

Vector Korea IT Inc.


5F, Gomoas bldg.
12 Hannam-daero 11-gil, Yongsan-gu
Seoul, 140-889
REPUBLIC OF KOREA

Phone: +1 248 449 9290


Fax:
+1 248 449 9704
E-mail: info@us.vector.com

Application Note AN-IND-1-016

Phone: +91 20 2587 2023


Fax: +91 20 2587 2025
E-mail: info@in.vector.com

Phone: +82 2 807 0600


Fax:
+82 2 807 0601
E-mail: info@kr.vector.com

You might also like