A configuration file is provided to define the USB device VID, PID and other information. The configureation file default path is curretn working directory, that could be changed by define environment variable IDT_CFG_PATH.
all commands follow a simple mode: a command to unit(OUT) and a response to host(IN).
The main class is VivoDevice that contain the most API need to access the unit.
A helper class VivoProtocol2 is used so build the command and response.
Bootloader class provide an interface to download a firmware file to unit with progress listener interface that tell the caller what package is downloading
RRQUIREMENT:
$ sudo cp libidtechproducts_pos_VivoDevice.so /usr/local/lib/libidtechproducts_pos_VivoDevice.so
This rules file make the non-root user could access the Unipay III.
$ sudo cp 40-unipayiii.rules /etc/udev/rules.d/
$ sudo udevd -d
the posconfig.json location is working directory, and the environment variable "IDT_CFG_PATH" is used to change the default location.
export IDT_CFG_PATH="cfg"
this envrionment change the config file position to ./cfg/posconfig.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
{
"config_version" : 1.0,
"devices" : [
{
"name" : "default",
"interface" : "USBHID",
"VID" : "0ACD",
"PID" : "3520"
},
{
"name" : "UnipayIII",
"interface" : "USBHID",
"VID" : "0ACD",
"PID" : "3520",
"enable_log" : 1
},
{
"name" : "KioskIII",
"interface" : "USBHID",
"VID" : "0ACD",
"PID" : "3710"
},
],
"log_level" : 1,
"log_file" : ".pos.log",
"log_to_console" : true
}
|
the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | private static void ping_test(){ VivoDevice dev = new VivoDevice(); try { System.out.println("VivoDeivce Test: ping"); dev.Open("default"); // use the Ping method if ( dev.Ping().GetStatus() == StatusCode.EOK) System.out.println("ping success"); else System.out.println("ping fail"); //DirectWrite/Read method VivoProtocol2 p = VivoProtocol2.BuildCommand((byte)0x18,(byte)0x01); dev.DirectWrite(p.GetRawData(), 1000); byte[] ret = dev.DirectRead(1000); System.out.println("out " + ret.toString()); dev.Close(); }catch (VivoDeviceException e) { System.out.println("Device Error Happen!"); System.out.println(e); } } |
line 2: it define a variable "VivoDevice".
line 5: it open the a devcie with logial name in the "posconfig.json", that JSON file contain the information of the device, including USB VID/PID.
This example show 2 method to access the devcie: SDK method and directWrite/Read.
line 8: call the SDK method "Ping".
line 15/16: call the DirectWrite/Read to send the ping command.
line 14 : it use a help class VivoProtocol2 to create the ping command with Command/Sub-Command that defined in the product design specification.
line 19: it close the device finally.