codeskin.can
Class JKvaser

java.lang.Object
  extended by codeskin.can.JKvaser
All Implemented Interfaces:
CANCallBack, CANDriver

public class JKvaser
extends java.lang.Object
implements CANDriver, CANCallBack

Kvaser driver. Note that we are not obeying 100% to Kvaser's rule about a handle only being allowed to be used in one thread. In fact, the open, close, acceptance mask, and bus-on/off calls are called outside of the service thread. This may need to be changed if it creates a problem.


Method Summary
 void callBack(CANMessage cmsg)
          Function that is called if a CAN message is received.
 void close()
          Closes driver.
static void eventCallbackFromNative(int hnd, int stat)
          Allows native code to signal an event
 CANStatusRecord getCANStatusRecord()
          Accessor method for status record.
 CANMessageBuffer getMessageBuffer()
          Accessor method for receive buffer.
 int getNumberOfFilters()
          Returns the number of acceptance filters available.
static JKvaser getPort(java.lang.String name)
          Creates singleton instances of the class.
 CANMessageBuffer getTxAcknowledgeBuffer()
          Accessor method for transmit acknowledge buffer.
 boolean goBusOff()
          Go bus off.
 boolean goBusOn()
          Go bus on.
 boolean isBusOn()
           
static java.lang.String libraryVersion()
          JKvaser library version
 boolean open(int baudrate, int ac, int am, boolean isExt)
          Opens Kvaser port
static void printFromNative(java.lang.String msg)
          Allows native code to print to JAVA console.
 void registerCallBack(CANCallBack canCB)
          Registers method to be called when CAN message is received.
 boolean sendMessage(CANMessage cm)
          Sends CAN message.
 boolean setAcceptanceFilter(int fid, int ac, int am, boolean isExt)
          Sets acceptance filter.
 boolean setBaudRate(int baudrate)
          Sets baud-rate.
 boolean updateStatusRecord()
          Updates status record.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

libraryVersion

public static java.lang.String libraryVersion()
JKvaser library version

Returns:
java library version

printFromNative

public static void printFromNative(java.lang.String msg)
Allows native code to print to JAVA console.

Parameters:
msg - message string

eventCallbackFromNative

public static void eventCallbackFromNative(int hnd,
                                           int stat)
Allows native code to signal an event

Parameters:
hnd - handle to port
stat - event

open

public boolean open(int baudrate,
                    int ac,
                    int am,
                    boolean isExt)
Opens Kvaser port

Parameters:
baudrate - baudrate
ac - acceptance code
am - acceptance mask
Returns:
true for success

goBusOn

public boolean goBusOn()
Description copied from interface: CANDriver
Go bus on. Must be called to start receiving and allow sending.

Specified by:
goBusOn in interface CANDriver
Returns:
true if successful

goBusOff

public boolean goBusOff()
Description copied from interface: CANDriver
Go bus off.

Specified by:
goBusOff in interface CANDriver
Returns:
true if successful

isBusOn

public boolean isBusOn()

setBaudRate

public boolean setBaudRate(int baudrate)
Description copied from interface: CANDriver
Sets baud-rate.

Specified by:
setBaudRate in interface CANDriver
Parameters:
baudrate - baudrate
Returns:
true if successful

getNumberOfFilters

public int getNumberOfFilters()
Description copied from interface: CANDriver
Returns the number of acceptance filters available.

Specified by:
getNumberOfFilters in interface CANDriver
Returns:
Number of available filters

setAcceptanceFilter

public boolean setAcceptanceFilter(int fid,
                                   int ac,
                                   int am,
                                   boolean isExt)
Description copied from interface: CANDriver
Sets acceptance filter. Different filters can be configured, depending on implementation. A "1" in the mask means that the corresponding bit in code is relevant.

Specified by:
setAcceptanceFilter in interface CANDriver
Parameters:
fid - filter id
ac - acceptance code
am - acceptance mask
isExt - true for extended message filter
Returns:
true if successful

close

public void close()
Description copied from interface: CANDriver
Closes driver. Note that open() is implementation specific.

Specified by:
close in interface CANDriver

sendMessage

public boolean sendMessage(CANMessage cm)
Description copied from interface: CANDriver
Sends CAN message.

Specified by:
sendMessage in interface CANDriver
Parameters:
cm - Message
Returns:
true if successful

callBack

public void callBack(CANMessage cmsg)
Description copied from interface: CANCallBack
Function that is called if a CAN message is received.

Specified by:
callBack in interface CANCallBack
Parameters:
cmsg - CAN message

registerCallBack

public void registerCallBack(CANCallBack canCB)
Description copied from interface: CANDriver
Registers method to be called when CAN message is received.

Specified by:
registerCallBack in interface CANDriver
Parameters:
canCB - callback

getMessageBuffer

public CANMessageBuffer getMessageBuffer()
Description copied from interface: CANDriver
Accessor method for receive buffer. Note that receive buffer is only serviced if no callback method has been registered.

Specified by:
getMessageBuffer in interface CANDriver
Returns:
true if successful

getTxAcknowledgeBuffer

public CANMessageBuffer getTxAcknowledgeBuffer()
Description copied from interface: CANDriver
Accessor method for transmit acknowledge buffer.

Specified by:
getTxAcknowledgeBuffer in interface CANDriver
Returns:
CAN buffer

getCANStatusRecord

public CANStatusRecord getCANStatusRecord()
Description copied from interface: CANDriver
Accessor method for status record.

Specified by:
getCANStatusRecord in interface CANDriver
Returns:
status record

updateStatusRecord

public boolean updateStatusRecord()
Description copied from interface: CANDriver
Updates status record.

Specified by:
updateStatusRecord in interface CANDriver
Returns:
true for success

getPort

public static JKvaser getPort(java.lang.String name)
Creates singleton instances of the class.

Parameters:
name - port name
Returns:
instance of class (or null if problem with native library)