peak.canlight
Class CANLight

java.lang.Object
  extended by peak.canlight.CANLight

public class CANLight
extends java.lang.Object

This is the main class for using the pcanlight api with your java applications. Steps to use this api:

 1. Create a new CANLight object:
example:
can = new CANLight();
(or use an constructor which returns an initialized object) 2. Call the initializeAPI method passing the hardware parameter which you want use
example to initialize a USB hardware channel 1:
can.initializeAPI(CANLight.PCAN_USB_1CH);
(All hardwares are represented by a static constant prefixed by 'PCAN_') 3. If necessary call setFilter(), resetFilter() or resetClient() example: can.resetClient(); can.resetFilter(); can.setFilter(0x000,0x123,CANLight.TYPE_ST); 4. Call the read or write method
example: CANMessage msg; msg = can.read(); can.write(msg); (do not forget to check if msg is null after calling the read method)
5. At the end call the close method example: can.close();

A minimalistic program that writes every can message that it receives (ping-pong)
looks like this:
import peak.canlight.*;

public class MinimalisticProgram
{
      public static void main(String[] args)
      {
          CANLight can;
          CANMessage msg;
          int res;
          can = new CANLight();
          if(!can.initializeAPI(CANLight.PCAN_USB_1CH))
          {
              System.out.println("Unable to initialize the API");
              System.exit(0);
          }
          res = canLight.init(CANLight.BAUD_1M, CANLight.MAX_EXTENDED_ID);
          msg = new CANMessage();
          while(true)
          {
              while(can.read(msg) == CANLight.ERR_OK)
              {
                  res = can.write(msg);
                  if(res != CANLight.ERR_OK)
                  {
                      System.out.println("Unable to write the CAN message");
                      System.exit(0);
                  }
              }
          }
      }
}


Field Summary
static int BAUD_100K
          A constant for 100 Kilobaud
static int BAUD_10K
          A constant for 10 Kilobaud
static int BAUD_125K
          A constant for 125 Kilobaud
static int BAUD_1M
          A constant for 1 Megabaud
static int BAUD_20K
          A constant for 20 Kilobaud
static int BAUD_250K
          A constant for 250 Kilobaud
static int BAUD_500K
          A constant for 500 Kilobaud
static int BAUD_50K
          A constant for 50 Kilobaud
static int BAUD_5K
          A constant for 5 Kilobaud
static int ERR_ANYBUSERR
          A constant for all others error status <> 0 please ask by PEAK ......intern Driver errors.....
static int ERR_BUSHEAVY
          A constant for bus error: an Error count reached the limit
static int ERR_BUSLIGHT
          A constant for bus error: an Error count reached the limit
static int ERR_BUSOFF
          A constant for bus error: CAN_Controller went to 'Bus-Off'
static int ERR_HWINUSE
          A constant for ERR_HWINUSE
static int ERR_ILLHW
          A constant for invalid Hardware handle
static int ERR_MASK_ILLHANDLE
          A constant for mask for all Handle errors
static int ERR_NETINUSE
          A constant for ERR_NETINUSE
static int ERR_NO_DLL
          A constant for a Dll could not be loaded or a function was not found into the Dll
static int ERR_NOVXD
          A constant for problem with Localization of the VxD
static int ERR_OK
          A constant for no error
static int ERR_OVERRUN
          A constant for a constant for CAN-Controller was read to late
static int ERR_PARMTYP
          A constant for parameter not permitted
static int ERR_PARMVAL
          A constant for invalid Parameter value
static int ERR_QOVERRUN
          A constant for rcvQueue was read to late
static int ERR_QRCVEMPTY
          A constant for rcvQueue is empty
static int ERR_QXMTFULL
          A constant for send queue is full
static int ERR_REGTEST
          A constant for registerTest of the 82C200/SJA1000 failed
static int ERR_RESOURCE
          A constant for not generatably Resource (FIFO Client Timeout)
static int ERR_XMTFULL
          A constant for send buffer of the Controller ist full
static int HW_DONGLE_PRO
          A constant for Dongle Pro hardware
static int HW_DONGLE_SJA
          A constant for SJA Dongle hardware
static int HW_ISA
          A constant for ISA hardware
static int HW_ISA_SJA
          A constant for SJA ISA hardware
static int HW_PCI
          A constant for PCI hardware
static int MAX_EXTENDED_ID
          Maximal values for the extended ID of a CAN Message
static int MAX_STANDARD_ID
          Maximal values for the standard ID of a CAN Message
static byte MSG_TYPE_STATUS
          Status Message
static byte MSGTYPE_EXTENDED
          29bit message type (extended)
static byte MSGTYPE_RTR
          Remote request
static byte MSGTYPE_STANDARD
          11bit message type (standard)
static int PCAN_DNG
          A constant for DONGLE
static int PCAN_DNP
          A constant for DONGLE PRO
static int PCAN_ISA_1CH
          A constant for ISA 1st channel
static int PCAN_ISA_2CH
          A constant for ISA 2nd channel
static int PCAN_PCC_1CH
          A constant for PCC 1st channel
static int PCAN_PCC_2CH
          A constant for PCC 2nd channel
static int PCAN_PCI_1CH
          A constant for PCI 1st channel
static int PCAN_PCI_2CH
          A constant for PCI 2nd channel
static int PCAN_USB_1CH
          A constant for USB 1st channel
static int PCAN_USB_2CH
          A constant for USB 2nd channel
static int TYPE_EX
          A constant for the 29bit message type (extended)
static int TYPE_ST
          A constant for the 11bit message type (standard)
 
Constructor Summary
CANLight()
          Standard Contructor If an object is created with this constructer use init() to initialize the object
 
Method Summary
 int close()
          Deactivates the hardware and frees all used resources
 int getDLLVersionInfo(java.lang.StringBuffer strBuffer)
          Returns the version information of the used PCAN-Light DLL
 int getStatus()
          Returns the status of the hardware
 int getUSBDeviceNr(int[] deviceNumber)
          Returns the device number of a USB CAN Hardware
 int getVersionInfo(java.lang.StringBuffer strBuffer)
          Returns a String with version and copyright information
 int init(int baudRate, int msgType)
          Activates the PNP hardware, initializes it and makes some tests Use this method only with PNP hardware!
 int init(int baudRate, int msgType, int ioPort, int interrupt)
          Activates the NON PNP hardware, initializes it and makes some tests.
 boolean initializeAPI(int hwType)
          Initializes the PCANLight for a specific hardware
 int read(CANMessage message)
          Reads the next message.
 int readEx(CANMessage message, CANTimestamp rcvTime)
          Reads the next message.
 int resetClient()
          Clears the receive- and transmit-queues.
 int resetFilter()
          Closes the hardware filter such, that no more messages will be received
 int resetRcvEvent()
          Resets the handle of the Receive-Event.
 int setFilter(int from, int to, int msgType)
          Sets a hardware or software filter depending on the message type passed as third parameter
 int setRcvEvent()
          Sets the handle of the Receive-Event.
 int setUSBDeviceNr(int deviceNumber)
          Write the new device number of a USB CAN Hardware
 int write(CANMessage message)
          Writes a message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BAUD_1M

public static final int BAUD_1M
A constant for 1 Megabaud

See Also:
Constant Field Values

BAUD_500K

public static final int BAUD_500K
A constant for 500 Kilobaud

See Also:
Constant Field Values

BAUD_250K

public static final int BAUD_250K
A constant for 250 Kilobaud

See Also:
Constant Field Values

BAUD_125K

public static final int BAUD_125K
A constant for 125 Kilobaud

See Also:
Constant Field Values

BAUD_100K

public static final int BAUD_100K
A constant for 100 Kilobaud

See Also:
Constant Field Values

BAUD_50K

public static final int BAUD_50K
A constant for 50 Kilobaud

See Also:
Constant Field Values

BAUD_20K

public static final int BAUD_20K
A constant for 20 Kilobaud

See Also:
Constant Field Values

BAUD_10K

public static final int BAUD_10K
A constant for 10 Kilobaud

See Also:
Constant Field Values

BAUD_5K

public static final int BAUD_5K
A constant for 5 Kilobaud

See Also:
Constant Field Values

TYPE_ST

public static final int TYPE_ST
A constant for the 11bit message type (standard)

See Also:
Constant Field Values

TYPE_EX

public static final int TYPE_EX
A constant for the 29bit message type (extended)

See Also:
Constant Field Values

MSGTYPE_STANDARD

public static final byte MSGTYPE_STANDARD
11bit message type (standard)

See Also:
Constant Field Values

MSGTYPE_RTR

public static final byte MSGTYPE_RTR
Remote request

See Also:
Constant Field Values

MSGTYPE_EXTENDED

public static final byte MSGTYPE_EXTENDED
29bit message type (extended)

See Also:
Constant Field Values

MSG_TYPE_STATUS

public static final byte MSG_TYPE_STATUS
Status Message

See Also:
Constant Field Values

MAX_STANDARD_ID

public static final int MAX_STANDARD_ID
Maximal values for the standard ID of a CAN Message

See Also:
Constant Field Values

MAX_EXTENDED_ID

public static final int MAX_EXTENDED_ID
Maximal values for the extended ID of a CAN Message

See Also:
Constant Field Values

HW_ISA

public static final int HW_ISA
A constant for ISA hardware

See Also:
Constant Field Values

HW_DONGLE_SJA

public static final int HW_DONGLE_SJA
A constant for SJA Dongle hardware

See Also:
Constant Field Values

HW_DONGLE_PRO

public static final int HW_DONGLE_PRO
A constant for Dongle Pro hardware

See Also:
Constant Field Values

HW_ISA_SJA

public static final int HW_ISA_SJA
A constant for SJA ISA hardware

See Also:
Constant Field Values

HW_PCI

public static final int HW_PCI
A constant for PCI hardware

See Also:
Constant Field Values

PCAN_ISA_1CH

public static final int PCAN_ISA_1CH
A constant for ISA 1st channel

See Also:
Constant Field Values

PCAN_ISA_2CH

public static final int PCAN_ISA_2CH
A constant for ISA 2nd channel

See Also:
Constant Field Values

PCAN_PCI_1CH

public static final int PCAN_PCI_1CH
A constant for PCI 1st channel

See Also:
Constant Field Values

PCAN_PCI_2CH

public static final int PCAN_PCI_2CH
A constant for PCI 2nd channel

See Also:
Constant Field Values

PCAN_PCC_1CH

public static final int PCAN_PCC_1CH
A constant for PCC 1st channel

See Also:
Constant Field Values

PCAN_PCC_2CH

public static final int PCAN_PCC_2CH
A constant for PCC 2nd channel

See Also:
Constant Field Values

PCAN_USB_1CH

public static final int PCAN_USB_1CH
A constant for USB 1st channel

See Also:
Constant Field Values

PCAN_USB_2CH

public static final int PCAN_USB_2CH
A constant for USB 2nd channel

See Also:
Constant Field Values

PCAN_DNP

public static final int PCAN_DNP
A constant for DONGLE PRO

See Also:
Constant Field Values

PCAN_DNG

public static final int PCAN_DNG
A constant for DONGLE

See Also:
Constant Field Values

ERR_OK

public static final int ERR_OK
A constant for no error

See Also:
Constant Field Values

ERR_XMTFULL

public static final int ERR_XMTFULL
A constant for send buffer of the Controller ist full

See Also:
Constant Field Values

ERR_OVERRUN

public static final int ERR_OVERRUN
A constant for a constant for CAN-Controller was read to late

See Also:
Constant Field Values

ERR_BUSLIGHT

public static final int ERR_BUSLIGHT
A constant for bus error: an Error count reached the limit

See Also:
Constant Field Values

ERR_BUSHEAVY

public static final int ERR_BUSHEAVY
A constant for bus error: an Error count reached the limit

See Also:
Constant Field Values

ERR_BUSOFF

public static final int ERR_BUSOFF
A constant for bus error: CAN_Controller went to 'Bus-Off'

See Also:
Constant Field Values

ERR_QRCVEMPTY

public static final int ERR_QRCVEMPTY
A constant for rcvQueue is empty

See Also:
Constant Field Values

ERR_QOVERRUN

public static final int ERR_QOVERRUN
A constant for rcvQueue was read to late

See Also:
Constant Field Values

ERR_QXMTFULL

public static final int ERR_QXMTFULL
A constant for send queue is full

See Also:
Constant Field Values

ERR_REGTEST

public static final int ERR_REGTEST
A constant for registerTest of the 82C200/SJA1000 failed

See Also:
Constant Field Values

ERR_NOVXD

public static final int ERR_NOVXD
A constant for problem with Localization of the VxD

See Also:
Constant Field Values

ERR_HWINUSE

public static final int ERR_HWINUSE
A constant for ERR_HWINUSE

See Also:
Constant Field Values

ERR_NETINUSE

public static final int ERR_NETINUSE
A constant for ERR_NETINUSE

See Also:
Constant Field Values

ERR_ILLHW

public static final int ERR_ILLHW
A constant for invalid Hardware handle

See Also:
Constant Field Values

ERR_RESOURCE

public static final int ERR_RESOURCE
A constant for not generatably Resource (FIFO Client Timeout)

See Also:
Constant Field Values

ERR_PARMTYP

public static final int ERR_PARMTYP
A constant for parameter not permitted

See Also:
Constant Field Values

ERR_PARMVAL

public static final int ERR_PARMVAL
A constant for invalid Parameter value

See Also:
Constant Field Values

ERR_MASK_ILLHANDLE

public static final int ERR_MASK_ILLHANDLE
A constant for mask for all Handle errors

See Also:
Constant Field Values

ERR_ANYBUSERR

public static final int ERR_ANYBUSERR
A constant for all others error status <> 0 please ask by PEAK ......intern Driver errors.....

See Also:
Constant Field Values

ERR_NO_DLL

public static final int ERR_NO_DLL
A constant for a Dll could not be loaded or a function was not found into the Dll

See Also:
Constant Field Values
Constructor Detail

CANLight

public CANLight()
Standard Contructor If an object is created with this constructer use init() to initialize the object

Method Detail

initializeAPI

public boolean initializeAPI(int hwType)
Initializes the PCANLight for a specific hardware

Parameters:
hwType - the hardware to be used

init

public int init(int baudRate,
                int msgType)
Activates the PNP hardware, initializes it and makes some tests Use this method only with PNP hardware!

Parameters:
baudRate - the baudrate to be used
msgType - the type of the message frame (standard or extended)
Returns:
0, if successful, otherwise the error code

init

public int init(int baudRate,
                int msgType,
                int ioPort,
                int interrupt)
Activates the NON PNP hardware, initializes it and makes some tests. Use this method only with NON PNP hardware!

Parameters:
baudRate - the baudrate to be used
msgType - the type of the message frame (standard or extended)
ioPort - the io port to use
interrupt - the interrupt to use
Returns:
0, if successful, otherwise the error code

getVersionInfo

public int getVersionInfo(java.lang.StringBuffer strBuffer)
Returns a String with version and copyright information

Parameters:
strBuffer - String buffer to return the hardware information (max. 255 characters)
Returns:
0, if successful, otherwise the error code.

getDLLVersionInfo

public int getDLLVersionInfo(java.lang.StringBuffer strBuffer)
Returns the version information of the used PCAN-Light DLL

Parameters:
strBuffer - String buffer to return the DLL information (max. 255 characters)
Returns:
0, if successful, otherwise the error code

getUSBDeviceNr

public int getUSBDeviceNr(int[] deviceNumber)
Returns the device number of a USB CAN Hardware

Parameters:
deviceNumber - number a single element array to pass an Integer by reference which represents the device number
Returns:
0, if successful, otherwise the error code.

setUSBDeviceNr

public int setUSBDeviceNr(int deviceNumber)
Write the new device number of a USB CAN Hardware

Parameters:
deviceNumber - device number
Returns:
0, if successful, otherwise the error code

close

public int close()
Deactivates the hardware and frees all used resources

Returns:
0, if successful, otherwise the error code

getStatus

public int getStatus()
Returns the status of the hardware

Returns:
Error/status of the hardware after execute the function

read

public int read(CANMessage message)
Reads the next message. With this method it is possible to reuse a previously created message object

Parameters:
message - An existing message object, that should be "filled" with data should not be null
Returns:
0, if successful, otherwise the error code
See Also:
CANMessage

readEx

public int readEx(CANMessage message,
                  CANTimestamp rcvTime)
Reads the next message. With this method it is possible to reuse a previously created message object.

Parameters:
message - An existing message object, that should be "filled" with data. Should not be null
rcvTime - The TPCANTimestamp structure for the message's timestamp
Returns:
0, if successful, otherwise the error code.
See Also:
CANMessage, CANTimestamp

setFilter

public int setFilter(int from,
                     int to,
                     int msgType)
Sets a hardware or software filter depending on the message type passed as third parameter

Parameters:
from - The smallest message ID, which should be received
to - The largest message ID, which should be received
msgType - The message type (use TYPE_ST or TYPE_EX)
Returns:
0, if successful, otherwise the error code

resetFilter

public int resetFilter()
Closes the hardware filter such, that no more messages will be received

Returns:
0, if successful, otherwise the error code

write

public int write(CANMessage message)
Writes a message.

Parameters:
message - The message that should be written to the can bus
Returns:
0, if successful, otherwise the error code
See Also:
CANMessage

resetClient

public int resetClient()
Clears the receive- and transmit-queues.

Returns:
0, if successful, otherwise the error code

setRcvEvent

public int setRcvEvent()
Sets the handle of the Receive-Event. static method peak.canlight.RcvEventDispatcher.dispatchRcvEvent is used to notify each Receive-Event

Returns:
0, if successful, otherwise the error code

resetRcvEvent

public int resetRcvEvent()
Resets the handle of the Receive-Event.

Returns:
0, if successful, otherwise the error code