Professional Documents
Culture Documents
38
and getId ( 1, getData ( read or write the data and exchange of specific sets of Device Profile parameters.
the identifier bit field of a CanMsg instance. The bit fields The class PDO extends the CanMsg class by adding PDO
are implemented as dedicated BitVector objects for conve- specific properties and functionality like setting the trans-
nient access to individual bits of the message data or the fer mode to synchronousor asynchronous for instance (cf.
CAN identifier. The CANopenService Data Object (SDO) Table 2).
and Process Data Object (PDO) are represented by the The transmit frequency of synchronous transfers is de-
SDO class and the PDO class, respectively. Both classes fined by the mute attribute that specifies the number of
directly extend the CanMsg class (cf. Figure 2) by adding Sync telegrams to be skipped.
higher level communication facilities. The parameters receive, which, and moduleId,
of the PDO constructor select a specific PDO configura-
SDO communication SDO communication is used to tion (e.g. receive PDO 1 on module 0x10).
access arbitrary device parameters with no real-time guar- Normally, the programmer does not use the PDO class
antees. This kind of communication is often used in a directly but one of the TransmitPDO or ReceivePDO
configurationphase or in a maintenance context. Individ- classes. They are directly derived from PDO and pro-
ual parameters are addressed by an index and a subindex vide CAN real-time read and write access to Device Profile
which are coded into the message data. Depending on data, respectively (cf. Table 2).
the memory size of the requested device parameter several In order to get notified upon the arrival of specific
CAN telegrams have to be passed from client to server and PDO telegrams on the CAN the programmer can instanti-
vice versa, since the data has to be split up into CAN tele- ate a correspondingTransmitPDO object. This object per-
grams of fixed size. CANopen defines various protocols forms the correspondingmessage subscription at the Can-
for this purpose which are all supported by the Java CAN Port object and reports incoming telegrams to a PDOHan-
API. If the parameter upload or download fails a special dler interface implementation by calling the correspond-
SDO abort protocol is used to provide the error informa- ing transmitPDOArrived( ) method (cf. Figure 1
tion. on page 2 and Table 2). A set of methods (e.g. read-
The protocols are hidden from the programmer, Real32 ( ) ) is available for convenient extraction of the
who only uses the sendReadSdo0 and send- transmit PDO data. The class that implements the PDO-
WriteSdo ( ) methods (cf. Table 1). Both methods use Handler interface has to be registered at the TransmitPDO
index and subindex parameters to select a specific object with the addPDOHandler ( ) method.
Device Profile entry. The requested CAN module is iden- The CANopenreceive PDO concept is encapsulated by
tified by the nodeId parameter of the SDO constructor. the ReceivePDO class. Specific PDOs can be instantiated,
In order to create a thin interface, all parameter values are loaded with data and sent to the CAN with a corresponding
transferred as string values with an associated dataType send method (e.g. sendUnsigned32).
value. The supported data type values are defined in the
class DatuTypes according to [8]. The issupported ( )
The Sync object Periodic CANopen Sync messages can
predicate of this class can be used to check whether a spe-
be generated by means of a the Sync class. Since this
cific data type is currently supported by the Java CAN API.
class is derived from java.lang. Thread a Sync object can
At the moment the Java CAN API supports Rea132, Visi-
be started with the start ( ) method. The CanPort refer-
ble String (arbitrary length) and all Unsignedllnteger data
ence and the sync frequency are specified in the construc-
types.
tor.
The size and timestamp parameters of the
sendReadSdo ( ) method receive the size and the time
stamp of the received Device Profile entry. 2.3. NMT services
Both, the sendReadSdo ( ) and the send- The CANopen node state diagram defines the set of
Wri teSdo ( ) method, return an integer error code if the possible system states like init, pre-operational, opera-
SDO transfer was aborted and throw a CanPortException tional etc. of a CANopen module. To offer the possibil-
if a CAN communication error occurred. Several methods ity to invoke transitions in the node state diagram of indi-
are available to retrieve the CANopen error code, error vidual nodes (e.g. during a boot-up procedure), the class
class and additional information of an aborted data NMT was integrated into the Java CAN API (cf. Table 3).
transfer. Each state transition is mapped to a corresponding static
Behind the scenes, the SDO class constructs the neces- method which takes a CanPort reference and the module
sary CAN telegrams, sends them to the CAN via the Can- ID as arguments.
Port reference and collects and analyzes the response tele-
grams. The parameter values are de/en-coded according to 3. The Java CAN API Example Application
the specified data type by the class DataDecoder.
This section presents the CanApiDemo Java applica-
PDO communication CANopen Process Data Objects tion that demonstrates some of the key features of the
(PDOs) are preconfigured messages used for high-speed Java CAN API. It reads a specific Device Profile entry of
39
I Class I Method I Signature
U
an U 0 module by means of an SDO object, sets the out- 3.1. The CanApiDemo class
put lines with a ReceivePDO instance and catches the re- Table 4 shows the Java source code for the CanApi-
sulting transmit PDO. The transmit PDO is generated by Demo class which implements the main ( ) method. In
the VO module because the output lines are connected to Lines 7 and 8, the CanPort instance is created, parame-
its input lines (cf. Figure 3) and a state change in the in- terized by the CAN bitrate (125000), the communication
put lines triggers the VO module to send a corresponding channel (2), and the timer interval (0) which is not used
transmit PDO to the CAN. Furthermore, a concurrent log by this application. In order to monitor all generated CAN
object is created that logs all CAN messages to the console telegrams on the connected CAN, a CanLog instance is al-
for observation. The console output of the application is located in Line 9. The CanLog class will be described in
depicted in Figure 4. The application is kept simple in Section 3.3. The VO module with identifier Ox10 is set to
order to focus on the Java CAN API concepts and not on operational by means of a startRemoteNode ( ) (cf.
Java programming language issues. Section 2.3) method call in line 11.
The next step is to read the device name parameter of
CAN Interface-
the I/O module. This parameter is accessible through the
CAN-Fieldbus
Device Profile entry at index 0x1008, subindex 0x0. An
SDO instance is created in line 14 to retrieve this param-
eter by means of the CANopen Initiate Domain Upload
and Upload Domain Segment protocol. The constructor
CANopen I/O-
Module takes a reference to the responsible CAN communication
port and the CAN ID of the VO module. The code in
Selectron DIOC711 lines 15 to 19 allocates the SDO parameters used by the
Node ID: Ox10
sendReadSdo ( ) method (cf. Table 1 on page 4) in line
Figure 3. CanApiDemo setup 21. As pointed out before the Java CAN API transfers all
parameter values as Java strings. Since the requested pa-
rameter is of type Visible String the data type parameter is
set to DataTypes .VISIBLESTRING and no further
value decoding is necessary. If the call is successful, i.e.
no exception is thrown, lines 24 and 25 write the parame-
ter value and the time stamp to the console (cf. Figure 4).
Line 26 frees the resources occupied by the SDO object.
In the same way the output byte Device Profile param-
eter, representing the eight output lines of the U 0 module,
could be written by sending an SDO to the entry at index
0x6200, subindex Ox 1. The CanApiDemo performs an al-
ternative approach using PDO communication to achieve
the same effect. The corresponding ReceivePDO object is
Figure 4. The console output of CanApiDemo instantiated in line 31 specifying the responsible CanPort
40
I Class I Method
L
I Signature
-
I NMT 11 Dublic
-
static void startRemoteNode I CanPort nort. int moduleld
I
41
1:import de.uni-tuebingen.can.JCan.*; ous CAN server applications which act as bridges between
2:import de.uni-tuebingen.can.CanProtocol.*;
3: import java .util.* ; the Internet and the CAN fieldbus. The servers are im-
4: plemented on top of the Java CAN API and make exten-
5: public class CanLog sive use of the CANopen communication objects provided
6: implements CanPortEventListener{ there.
I:
8: private CanPort port; Complete parameter images of (running) CANopen au-
9: private byte[] data; tomation systems are produced by the Canlnvestigator
10: private long [ I time; Java component of the CANINSIGHT remote CAN field-
11: bus management system. Every parameter image consists
12: public CanLog (CanPort port) {
13: this.port = port; of a single XML document. The involved Device Pro-
1 4 data = new bytet81; files, the CAN system setup and the monitoring filters are
15: time = new long[l]; described by a further XML document. The XML doc-
16: try{ uments are instances of the CANopen Markup Language
17: port.addEventListener(this);
18: 1 (CoML,) which is described in [ 11.
19: catch (TooManyListenersException e){} An earlier application of the Java CAN API was a ba-
20 port.subscribeAllIDs(1, true); sic cliendserver system for the integration of arbitrary
21: 1 CANopen fieldbus devices into the World Wide Web [6].
22:
23: public void canEvent(CanP0rtEvent e){ The Java client for this system is available online at http:/l-
24: int msgId = e.getEventSrc0; robol6.fh-reutlingen.de/english/demo/jrcc.html.
25: try{
26: port.peakValue(msgId, data, time);
21: 1 5. Summary
28: catch (CanPortException ex){}
29: System. out .print (”\n--- log: ”+ The Java CAN API is a generic programming frame-
30: Integer. toHexString (msgId) + ”: ”) ; work for rapid Java CAN tool development. It provides
31: CanMsg.showMsg(data);
32: powerful abstractions for the CANopen communication
33: } objects, network management services and CAN layer 2
messages. In contrast to proprietary OPC solutions or
Table 6. The CanLog class programmable logic controllers it provides an open, ob-
ject oriented programming platform with few operating
system restrictions. The Java CAN API has proven its
instance. The addEventListener ( ) method takes a
usability in several automation engineering contexts like
CanPortEventListener as its argument. The CanLog class
teleservice, distance education, and fieldbus system man-
implements this interface and passes a reference to itself
agement.
(a this pointer) to the method. Thus, the CanLog class
handles all incoming CAN messages on its own and its im-
plementation of the CanPortEventListener .can-
References
Event ( ) method is called by the Java CAN API upon the D. Buhler. The CANopen Markup Language - Represent-
arrival of any CAN message. ing fieldbus data with XML. In Proc. of the 26th IEEE
The canEvent method retrieves the CAN message International Conference on Industrial Electronics, Con-
identifier in line 24 and the message data and time stamp trol and Instrumentation (IECON 2000), Nagoya, Japan,
in line 26. Lines 29 to 3 1 write the extracted information Oct. 2000. IEEE Computer Society Press (to appear).
to the console (cf. Figure 4 on page 4). D. Buhler and G . Gruhler. XML-based representation and
monitoring of CAN devices. In Proc. of the 7th Inter-
national CAN Conference (ICC 2000), Amsterdam, the
4. Practical Uses of the Java CAN API Netherlands, Oct. 2000. CAN in Automation (www.can-
cia.de) (to appear).
The Java CAN API was used for the implementation D. Buhler and W. Kuchlin. Remote fieldbus system man-
of a teleservice infrastructure for CANICANopen automa- agement with Java and XML. In Proc. of the IEEE Inter-
tion systems [ 111, the Virtual Automation Lab [4] and the national Symposium on Industrial Electronics ( N E2000),
XML-based CANINSIGHT fieldbus management system Puebla, Mexico, Dec. 2000. IEEE Computer Society Press
[3,21. (to appear).
The teleservice infrastructure offers the possibility to D.Buhler, W. Kuchlin, G. Gruhler, and G. Nusser. The
transparently transfer CAN messages over the Internet. As Virtual Automation Lab - Web based teaching of automa-
tion engineering concepts. In Proc. of the 7th IEEE In-
a result, a remote CAN can be accessed by locally installed
ternational Conference on the Engineering of Computer
standard diagnostic software tools. Based Systems (ECBS 2000). IEEE Computer Society
The Virtual Automation Lab [4] is an interactive Web- Press, April 2000.
based learning environment for both computer science and D. Buhler and G. Nusser. Java CAN API - Source
automation engineering students within a virtual univer- Code Documentation. http://robol6.fh-reutlingen.de/-
sity setting. Java applets provide user interfaces to vari- JavaCANAPYdocl.
42
[6] D. Biihler, G. Nusser, G. Gruhler, and W. Kiichlin. A
Java client/server system for accessing arbitrary CANopen
fieldbus devices via the Intemet. South African Computer
Joumal, (24):239-243, Nov. 1999.
[7] Can In Automation (CIA) e.V., Erlangen. CANopen Com-
munication Projile for Industrial Systems, Based on CAL,
3.0 edition, 1996. CiA Draft Standard 301.
[SI Can In Automation (CiA) e.V., Erlangen. CMS Data Types
and Encoding Rules (DS202-3), 1996. CiA Draft Standard
202-3.
[9] Can In Automation (CiA) e.V., Erlangen. NMT Protocol
Spec$cation, Draft Standard 203-1, 203-2, 1996.
[lo] E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design
Patterns: Elements of Reusable Object-OrientedSoftware.
Addison-Wesley, Reading, Massachusetts, 1995.
[ 111 G. Gruhler, G. Nusser, D. Buhler, and W. Kiichlin. Tele-
service of CAN systems via Intemet. In Proc. of the 6th
International CAN Conference (ICC 99), Torino (Italy),
Nov. 1999. CAN in Automation (www.can-cia.de).
[12] IS0 11898. Road Vehicles, Interchange of Digital Infor-
mation - ControllerArea Network (CAN)for High-speed
Communication, 1993.
[13] T. Lumpp, G. Gruhler, and W. Kuchlin. Virtual Java
devices-Integration of fieldbus based systems in the In-
temet. In Proc. of the 24th IEEE International Confer-
ence on Industrial Electronics, Control and Instrumenta-
tion (IECON ’98). Aachen, Germany, Sept. 1998. IEEE
Computer Society Press.
[14] J. Rumbaugh. The life of an object model: How the ob-
ject model changes during development. Joumal of Object
Oriented Programming, 7( 1):24 - 32, March I April 1994.
[15] J. Rumbaugh, M. Blaha, W. Premerlani, and E Eddy.
Object-OrientedModeling and Design. Prentice Hall, En-
glewood Cliffs, NJ, 1991.
Acknowledgement
This paper is based upon work conducted within the
research consortium VVL funded b y the state of Baden-
Wiirttemberg through the research initiative “Virtuelle
Hochschule”.
43