Class Device

All Implemented Interfaces:
Runnable

public class Device extends JposDevice implements Runnable
Base of a JposDevice based implementation of a JavaPOS CoinDispenser device service implementation for the sample device implemented in SampleCoinDispenserSimulator.tcl.
The simulator provides a coin dispenser with the following properties: Has one slot for 1, 5, 10, 50 and 100 currency units and two slots for 2, 20 and 200 currency units. This allows correct payment for every amount up to 499 currency units.
These 11 slots are ordered by coin size: 1, 2, 2, 10, 5, 20, 20, 100, 50, 200, 200
Here the communication protocol:
  • Commands to simulator:
    • R\n: Read coin count for all slots.
    • A a b c d e f g h i j k\n: Add values a - k to the corresponding slots.
    • O a b c d e f g h i j k\n: Subtract values a - k from the corresponding slots. All values must be 0 or 1
  • Response from simulator:
    • OK a b c d e f g h i j k\n: Operation successful, a - k are the current coin counts for the corresponding slots.
    • KO\n: Operation failed. This may happen due to a jam condition.

Here a full list of all device specific properties that can be changed via jpos.xml:
  • CharacterTimeout: Positive integer value, specifying the maximum delay between bytes that belong to the same frame. Default value: 50 milliseconds.
  • ClientPort: Integer value between 0 and 65535 specifying the TCP port used for communication with the device simulator. Default: 0 (for random port number selected by operating system).
  • ComPort: The IPv4 address of the device. Must always be specified and not empty. Notation: address:port, where address is a IPv4 address and port the TCP port of the device.
  • MinClaimTimeout: Minimum timeout in milliseconds used by method Claim to ensure correct working. Must be a positive value. If this value is too small, Claim might throw a JposException even if everything is OK if the specified timeout is less than or equal to MinClaimTimeout. Default: 100.
  • NearLimit: Minimum amount of coins in each slot. If one slot contains a lower number of coins, status will be reported as near empty. However, an empty status will only be reported if all slots are empty. Default: 2.
  • PollTimeout: Minimum time between status requests, in milliseconds. Status requests will be used to monitor the device state. Default: 500.
  • ReadArgumentCheck: Specifies whether the cashCounts argument of readCashCounts shall be used as a template for the result or be overwritten by a string that contains cashCount values for all slots. Default: false.
  • RequestTimeout: Maximum time, in milliseconds, between sending a command to the simulator and getting the first byte of its response. Default: 200.
  • SlotCapacity: The maximum number of coins that one single (simulated) hardware slot can hold. Default: 999.
  • Constructor Details

    • Device

      public Device(String port) throws jpos.JposException
      Constructor. Stores port and baud rate
      Parameters:
      port - COM port
      Throws:
      jpos.JposException - If COM port is invalid
  • Method Details

    • checkProperties

      public void checkProperties(jpos.config.JposEntry entry) throws jpos.JposException
      Description copied from class: JposBaseDevice
      Checks whether a JposEntry belongs to a predefined property value an if so, sets the corresponding driver value
      Overrides:
      checkProperties in class JposBaseDevice
      Parameters:
      entry - Entry to be checked, contains value to be set
      Throws:
      jpos.JposException - if a property value is invalid
    • changeDefaults

      public void changeDefaults(CoinDispenserProperties props)
      Description copied from class: JposDevice
      Change defaults of properties. Must be implemented within derived classed that support coin dispenser services.
      Overrides:
      changeDefaults in class JposDevice
      Parameters:
      props - Property set for setting the property defaults
    • run

      public void run()
      Thread main, used for status check loop while device is enabled.
      Specified by:
      run in interface Runnable
    • sendCommand

      protected String[] sendCommand(String command)
      Method to perform any command
      Parameters:
      command - Command data to be sent
      Returns:
      Array of string components of response, null in error case.
    • getCoinDispenserProperties

      public CoinDispenserProperties getCoinDispenserProperties(int index)
      Description copied from class: JposDevice
      Returns device implementation of CoinDispenserProperties.
      Overrides:
      getCoinDispenserProperties in class JposDevice
      Parameters:
      index - Device index, see constructor of JposCommonProperties.
      Returns:
      Instance of CoinDispenserProperties that matches the requirements of the corresponding device service.