Kvaser REST API Specification
Copyright 2011-2015 Kvaser AB, Mölndal, Sweden
http://www.kvaser.com
Printed Thursday 21st May, 2015
We believe that the information contained herein was accurate in all respects at the time of printing.
Kvaser AB cannot, however, assume any responsibility for errors or omissions in this text. Also note
that the information in this document is subject to change without notice and should not be construed
as a commitment by Kvaser AB.
Kvaser REST API Specification
2 (18)
(This page is intentionally left blank.)
Kvaser AB, Mölndal, Sweden — www.kvaser.com
Kvaser REST API Specification
3 (18)
Contents
1 About this Manual
2 Introduction
3 Connection Functions
3.1 deviceStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 canInitializeLibrary
. . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 canUnloadLibrary . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4 CANlib Equivalent Functions
4.1 canOpenChannel
. . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.2 canClose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.3 canSetBusParams . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4 canBusOn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.5 canBusOff
4.6 canSetBusOutputControl
. . . . . . . . . . . . . . . . . . . . . . . .
4.7 canRead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.8 canWrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.9 canIoCtl
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 Connection flow examples
6 Document Revision History
4
5
6
6
7
7
9
9
9
10
10
11
11
11
12
13
14
18
Kvaser AB, Mölndal, Sweden — www.kvaser.com
Kvaser REST API Specification
4 (18)
1 About this Manual
This document specifies the JSON REST API that is available in selected Kvaser
CAN interfaces. The reader is assumed to be familiar with Kvaser CANlib.
THIS SPECIFICATION IS SUBJECT TO CHANGE!
Kvaser AB, Mölndal, Sweden — www.kvaser.com
Kvaser REST API Specification
5 (18)
2 Introduction
This document specifies the JSON REST API which is available in selected Kvaser
CAN interfaces. The API is based upon the Kvaser CANlib, so most function and
parameter names are the same. Assuming that the device is connected, has IP
address 192.168.1.10, and is listening on port 8080, you can access the API in the
form:
http://192.168.1.10:8080/deviceStatus
The following rules applies to this API:
• All constants must be specified with its numerical value, e.g. canBITRATE_1M
should be given as -1
• All numbers are decimal
• All calls can take an optional integer parameter, ident= which is included in
the response
The status constants that are currently used by the JSON REST API are listed in
Table 1.
Constant
canOK
canERR_PARAM
canERR_NOMSG
canERR_NOCHANNELS
canERR_TIMEOUT
canERR_INVHANDLE
canERR_NOT_IMPLEMENTED
canERR_INVALID_PASSWORD1
canERR_NO_SUCH_FUNCTION1
canERR_NOT_AUTHORIZED1
canERR_INVALID_SESSION1
Value
0
-1
-2
-5
-7
-10
-32
-128
-129
-130
-131
Table 1: Status constants used by the JSON REST API. Note that the last constants
are extensions to current Kvaser CANlib.
1Extensions to current Kvaser CANlib.
Kvaser AB, Mölndal, Sweden — www.kvaser.com
Kvaser REST API Specification
6 (18)
3 Connection Functions
The following functions are used to query and connect to a device. This is done
differently than in Kvaser CANlib, e.g. the session concept is new.
3.1 deviceStatus
You may at any time ask a device for its status with the function deviceStatus.
The device can then respond whether it is free or already connected to some host.
• uri:/deviceStatus
• parameters:
[mode=jsonp ] If set, the response will be coded in JSONP, i.e. wrapped
with the fixed string ’canlib_callback(. . . )’.
• returns:
" usage " : %u ,
# Flags : 0= Free , 1= In use via service ,
# 2= In use via JSON API ,
# 4= In use via JSONP API
# The f o l l o w i n g r e s p o n s e codes are only present if the device
# is in use :
" timeout " : %u ,
# time left before current session
# will end ( seconds )
# IP address of the host the device
# is c u r r e n t l y c o n n e c t e d to .
" ip " : " % u .% u .% u .% u "
• example:
http : / / 1 9 2 . 1 6 8 . 1 . 1 0 : 8 0 8 0 / d e v i c e S t a t u s ? mode = jsonp
c a n l i b _ c a l l b a c k ({ " usage " :1})
http : / / 1 9 2 . 1 6 8 . 1 . 1 0 : 8 0 8 0 / d e v i c e S t a t u s ? mode = jsonp & ident =0001
c a n l i b _ c a l l b a c k ({ " usage " :0 , " ident " :1})
http : / / 1 9 2 . 1 6 8 . 1 . 1 0 : 8 0 8 0 / d e v i c e S t a t u s
{ " usage " :1}
http : / / 1 9 2 . 1 6 8 . 1 . 1 0 : 8 0 8 0 / d e v i c e S t a t u s
{ " usage " :3 , " timeout " :1066 , " ip " : " 1 9 2 . 1 6 8 . 1 . 1 2 " }
Kvaser AB, Mölndal, Sweden — www.kvaser.com
Kvaser REST API Specification
7 (18)
3.2 canInitializeLibrary
The function canInitializeLibrary sets up a connection and creates a session.
Therefore, this routine must be called before any other function that needs a
session. When a session is active, the device will deny any further calls to this
function by returning status code -131 (Invalid session).
The returned session must be used when calling other functions, denoted with
below. A session is terminated either by an explicit call to
canUnloadLibrary or after an inactivity of more than ’timeout’ seconds.
• uri:/canInitializeLibrary
• parameters:
[ password=%s ] Access password, the string can be URI encoded if
needed.
[ mode=jsonp ] When set, the response will be coded as JSONP.
[ timeout=%u ] The session timeout in seconds.
[ dummy_session=%u ] If set to ’1’, the session returned will be
’00000000000000000000000000000000’.
• returns:
{ " stat " : < canOK | canERR_xxx > , " session " : " %32 x " }
• example:
http : / / 1 9 2 . 1 6 8 . 1 . 1 0 : 8 0 8 0 / c a n I n i t i a l i z e L i b r a r y ? timeout =1200
{ " stat " :0 , " session " : " 1 b 6 e d 7 9 f 7 5 5 f 0 a b 9 4 f f 9 a d 6 2 4 7 0 a d 0 a 0 " }
http : / / 1 9 2 . 1 6 8 . 1 . 1 0 : 8 0 8 0 / c a n I n i t i a l i z e L i b r a r y ? timeout =1200
{ " stat " : -131}
3.3 canUnloadLibrary
The function canUnloadLibrary terminates an active session, making the device
free.
Kvaser AB, Mölndal, Sweden — www.kvaser.com
Kvaser REST API Specification
8 (18)
• uri://canUnloadLibrary
• parameters: None.
• returns:
{ " stat " : < canOK | canERR_xxx >}
• example:
http : / / 1 9 2 . 1 6 8 . 1 . 1 0 : 8 0 8 0 / 1 b 6 e d 7 9 f 7 5 5 f 0 a b 9 4 f f 9 a d 6 2 4 7 0 a d 0 a 0 /
c a n U n l o a d L i b r a r y
{ " stat " :0}
Kvaser AB, Mölndal, Sweden — www.kvaser.com