peak.can.basic

## Class PCANBasic

- java.lang.Object
- - peak.can.basic.PCANBasic

-     public class PCANBasic
      extends java.lang.Object

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

       1. Create a new PCANBasic object:

          example:

          can = new PCANBasic();

       2. Call the initializeAPI method

          example:

          can.initializeAPI();

       3. Call the Initialize method passing the TPCANHandle parameter which you want use, TPCANBaudrate and other parameters for Non-PNP devices

          example:

          can.initialize(TPCANHandle.PCAN_USBBUS1, TPCANBaudrate.PCAN_BAUD_1M);

       4. Call the read or write method passing the TPCANHandle parameter which is initialized and you want use

          example:
              TPCANMsg msg = new TPCANMsg();;
              can.Read(TPCANHandle.PCAN_USBBUS1, msg, null);
              can.Write(TPCANHandle.PCAN_USBBUS1, msg);
          (do not forget to check if msg is null after calling the Read method)

       5. At the end call the Uninitialize method
          example:
          can.Uninitialize(TPCANHandle.PCAN_USBBUS1);

  A minimalistic program that writes every can message that it receives (ping-pong)
  looks like this:

      import peak.can.basic.*;

      public class MinimalisticProgram
      {
            public static void main(String[] args)
            {
                PCANBasic can = null;
                TPCANMsg msg = null;
                TPCANStatus status = null;
                can = new PCANBasic();
                if(!can.initializeAPI())
                {
                    System.out.println("Unable to initialize the API");
                    System.exit(0);
                }
                status = can.Initialize(TPCANHandle.PCAN_PCIBUS1, TPCANBaudrate.PCAN_BAUD_1M, TPCANType.PCAN_TYPE_NONE, 0, (short) 0);
                msg = new TPCANMsg();
                while(true)
                {
                    while(can.Read(TPCANHandle.PCAN_PCIBUS1, msg, null) == TPCANStatus.PCAN_ERROR_OK)
                    {
                        status = can.Write(TPCANHandle.PCAN_PCIBUS1, msg);
                        if(status != TPCANStatus.PCAN_ERROR_OK)
                        {
                            System.out.println("Unable to write the CAN message");
                            System.exit(0);
                        }
                    }
                }
            }
      }

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PCANBasic()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `TPCANStatus` | `FilterMessages(TPCANHandle Channel, int FromID, int ToID, TPCANMode Mode)` Configures the reception filter.
    `TPCANStatus` | `GetErrorText(TPCANStatus Error, short Language, java.lang.StringBuffer Buffer)` Returns a descriptive text of a given TPCANStatus error code, in any desired language The current languages available for translation are: Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), Italian (0x10) and French (0x0C)
    `TPCANStatus` | `GetStatus(TPCANHandle Channel)` Gets the current status of a PCAN Channel
    `TPCANStatus` | `GetValue(TPCANHandle Channel, TPCANParameter Parameter, java.lang.Object Buffer, int BufferLength)` Retrieves a PCAN Channel value Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used.
    `TPCANStatus` | `Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, int IOPort, short Interrupt)` Initializes a PCAN Channel
    `boolean` | `initializeAPI()` Initializes the PCANBasic API
    `TPCANStatus` | `InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD)` Initializes a FD capable PCAN Channel See PCAN_BR_* values Bitrate string must follow the following construction rules: - parameters and values must be separated by '=' - Couples of Parameter/value must be separated by ',' - Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2, nom_brp, nom_sjw, nom_tseg1, nom_tseg2. - Following Parameters are optional (not used yet): data_ssp_offset, nom_samp Example: f_clock_mhz=80, nom_brp=1, nom_tset1=63, nom_tseg2=16, nom_sjw=7, data_brp=4, data_tset1=12, data_tseg2=7, data_sjw=1
    `TPCANStatus` | `Read(TPCANHandle Channel, TPCANMsg MessageBuffer, TPCANTimestamp TimestampBuffer)` Transmits a CAN message
    `TPCANStatus` | `ReadFD(TPCANHandle Channel, TPCANMsgFD MessageBuffer, TPCANTimestampFD TimestampBuffer)` Reads a CAN message from the receive queue of a FD capable PCAN Channel
    `TPCANStatus` | `Reset(TPCANHandle Channel)` Resets the receive and transmit queues of the PCAN Channel A reset of the CAN controller is not performed.
    `TPCANStatus` | `ResetRcvEvent(TPCANHandle Channel)` Resets the handle of the Receive-Event for the Channel.
    `TPCANStatus` | `SetRcvEvent(TPCANHandle Channel)` Sets the handle of the Receive-Event for the Channel. static method peak.can.basic.RcvEventDispatcher.dispatchRcvEvent is used to notify each Receive-Event
    `TPCANStatus` | `SetValue(TPCANHandle Channel, TPCANParameter Parameter, java.lang.Object Buffer, int BufferLength)` Configures or sets a PCAN Channel value Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used.
    `TPCANStatus` | `Uninitialize(TPCANHandle Channel)` Uninitializes one or all PCAN Channels initialized by CAN_Initialize Giving the TPCANHandle value "PCAN_NONEBUS", uninitialize all initialized channels
    `TPCANStatus` | `Write(TPCANHandle Channel, TPCANMsg MessageBuffer)` Transmits a CAN message
    `TPCANStatus` | `WriteFD(TPCANHandle Channel, TPCANMsgFD MessageBuffer)` Transmits a CAN message over a FD capable PCAN Channel

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PCANBasic

          public PCANBasic()

  - ### Method Detail

    - #### Initialize

          public TPCANStatus Initialize(TPCANHandle Channel,
                                        TPCANBaudrate Btr0Btr1,
                                        TPCANType HwType,
                                        int IOPort,
                                        short Interrupt)

      Initializes a PCAN Channel
      Parameters:
        `Channel` - The handle of a PCAN Channel
        `Btr0Btr1` - The speed for the communication (BTR0BTR1 code)
        `HwType` - NON PLUG&PLAY: The type of hardware and operation mode
        `IOPort` - NON PLUG&PLAY: The I/O address for the parallel port
        `Interrupt` - NON PLUG&PLAY: Interrupt number of the parallel port
      Returns:
        a TPCANStatus error code

    - #### InitializeFD

          public TPCANStatus InitializeFD(TPCANHandle Channel,
                                          TPCANBitrateFD BitrateFD)

      Initializes a FD capable PCAN Channel

      See PCAN_BR_* values Bitrate string must follow the following construction rules: - parameters and values must be separated by '=' - Couples of Parameter/value must be separated by ',' - Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2, nom_brp, nom_sjw, nom_tseg1, nom_tseg2. - Following Parameters are optional (not used yet): data_ssp_offset, nom_samp

      Example: f_clock_mhz=80, nom_brp=1, nom_tset1=63, nom_tseg2=16, nom_sjw=7, data_brp=4, data_tset1=12, data_tseg2=7, data_sjw=1

      Parameters:
        `Channel` - The handle of a FD capable PCAN Channel
        `BitrateFD` - The speed for the communication (FD Bitrate string)
      Returns:
        A TPCANStatus error code

    - #### Uninitialize

          public TPCANStatus Uninitialize(TPCANHandle Channel)

      Uninitializes one or all PCAN Channels initialized by CAN_Initialize Giving the TPCANHandle value "PCAN_NONEBUS", uninitialize all initialized channels
      Parameters:
        `Channel` - The handle of a PCAN Channel
      Returns:
        A TPCANStatus error code

    - #### Reset

          public TPCANStatus Reset(TPCANHandle Channel)

      Resets the receive and transmit queues of the PCAN Channel A reset of the CAN controller is not performed.
      Parameters:
        `Channel` - The handle of a PCAN Channel
      Returns:
        A TPCANStatus error code

    - #### GetStatus

          public TPCANStatus GetStatus(TPCANHandle Channel)

      Gets the current status of a PCAN Channel
      Parameters:
        `Channel` - The handle of a PCAN Channel
      Returns:
        A TPCANStatus error code

    - #### Read

          public TPCANStatus Read(TPCANHandle Channel,
                                  TPCANMsg MessageBuffer,
                                  TPCANTimestamp TimestampBuffer)

      Transmits a CAN message
      Parameters:
        `Channel` - The handle of a PCAN Channel
        `MessageBuffer` - A TPCANMsg buffer with the message to be read
        `TimestampBuffer` - A TPCANTimestamp structure buffer to get the reception time of the message. If this value is not desired, this parameter should be passed as NULL
      Returns:
        A TPCANStatus error code

    - #### ReadFD

          public TPCANStatus ReadFD(TPCANHandle Channel,
                                    TPCANMsgFD MessageBuffer,
                                    TPCANTimestampFD TimestampBuffer)

      Reads a CAN message from the receive queue of a FD capable PCAN Channel
      Parameters:
        `Channel` - The handle of a FD capable PCAN Channel
        `MessageBuffer` - A TPCANMsgFD structure buffer to store the CAN message
        `TimestampBuffer` - A TPCANTimestampFD buffer to get the reception time of the message
      Returns:
        A TPCANStatus error code

    - #### Write

          public TPCANStatus Write(TPCANHandle Channel,
                                   TPCANMsg MessageBuffer)

      Transmits a CAN message
      Parameters:
        `Channel` - The handle of a PCAN Channel
        `MessageBuffer` - A TPCANMsg buffer with the message to be sent
      Returns:
        A TPCANStatus error code

    - #### WriteFD

          public TPCANStatus WriteFD(TPCANHandle Channel,
                                     TPCANMsgFD MessageBuffer)

      Transmits a CAN message over a FD capable PCAN Channel
      Parameters:
        `Channel` - The handle of a FD capable PCAN Channel
        `MessageBuffer` - A TPCANMsgFD buffer with the message to be sent
      Returns:
        A TPCANStatus error code

    - #### FilterMessages

          public TPCANStatus FilterMessages(TPCANHandle Channel,
                                            int FromID,
                                            int ToID,
                                            TPCANMode Mode)

      Configures the reception filter. The message filter will be expanded with every call to this function. If it is desired to reset the filter, please use the CAN_SetParameter function
      Parameters:
        `Channel` - The handle of a PCAN Channel
        `FromID` - The lowest CAN ID to be received
        `ToID` - The highest CAN ID to be received
        `Mode` - Message type, Standard (11-bit identifier) or Extended (29-bit identifier)
      Returns:
        A TPCANStatus error code

    - #### GetValue

          public TPCANStatus GetValue(TPCANHandle Channel,
                                      TPCANParameter Parameter,
                                      java.lang.Object Buffer,
                                      int BufferLength)

      Retrieves a PCAN Channel value Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned
      Parameters:
        `Channel` - The handle of a PCAN Channel
        `Parameter` - The TPCANParameter parameter to get
        `Buffer` - Buffer for the parameter value
        `BufferLength` - Size in bytes of the buffer
      Returns:
        A TPCANStatus error code

    - #### SetValue

          public TPCANStatus SetValue(TPCANHandle Channel,
                                      TPCANParameter Parameter,
                                      java.lang.Object Buffer,
                                      int BufferLength)

      Configures or sets a PCAN Channel value Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned
      Parameters:
        `Channel` - The handle of a PCAN Channel
        `Parameter` - The TPCANParameter parameter to get
        `Buffer` - Buffer for the parameter value
        `BufferLength` - Size in bytes of the buffer
      Returns:
        A TPCANStatus error code

    - #### GetErrorText

          public TPCANStatus GetErrorText(TPCANStatus Error,
                                          short Language,
                                          java.lang.StringBuffer Buffer)

      Returns a descriptive text of a given TPCANStatus error code, in any desired language The current languages available for translation are: Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), Italian (0x10) and French (0x0C)
      Parameters:
        `Error` - A TPCANStatus error code
        `Language` - Indicates a 'Primary language ID'
        `Buffer` - Buffer for a null terminated char array
      Returns:
        A TPCANStatus error code

    - #### SetRcvEvent

          public TPCANStatus SetRcvEvent(TPCANHandle Channel)

      Sets the handle of the Receive-Event for the Channel. static method peak.can.basic.RcvEventDispatcher.dispatchRcvEvent is used to notify each Receive-Event
      Parameters:
        `Channel` - The handle of a PCAN Channel
      Returns:
        A TPCANStatus error code

    - #### ResetRcvEvent

          public TPCANStatus ResetRcvEvent(TPCANHandle Channel)

      Resets the handle of the Receive-Event for the Channel.
      Parameters:
        `Channel` - The handle of a PCAN Channel
      Returns:
        A TPCANStatus error code

    - #### initializeAPI

          public boolean initializeAPI()

      Initializes the PCANBasic API
      Returns:
        a boolean to indicate if API is successfully loaded