Hello everyone, could someone please guide/help me on how to do this? I have the JavaPOS JAR file, and I want to create a library for B4J with it.
You can use Java Object else you will have to write a wrapper(s).
You will need to know some java regardless of using Java Object or doing a wrapper. Search for some b4J examples posted by @stevel05 . He has posted many B4J projects using Java Object. You will have to use some tool to open the jar so that you can see the classes and the public methods in each of the classes.
I am too tied up with work to take on something like this. Maybe post a job offer in the job offer part of the forum and see if someone will assist you.
I dont think there is a guide but there are plenty of examples in the B4J forum. As mentioned before, you will need to have some knowledge of Java to use JavaObject or to do a B4J wrapper.Thanks Johan. Is there a tutorial for JavaObject for B4J here in the forum? I can't seem to find a comprehensive guide on how to do it.
It is similar in B4J when using JavaObject in B4A.Is there a tutorial for JavaObject for B4J here in the forum?
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
java.lang.NoClassDefFoundError: jpos/JposException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:340)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:519)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:506)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at b4j.example.main.<clinit>(main.java:17)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:427)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.loadClass(LauncherImpl.java:382)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$3(LauncherImpl.java:421)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.ClassNotFoundException: jpos.JposException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 25 more
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.NullPointerException
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:458)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
... 5 more
java.lang.ExceptionInInitializerError
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:427)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.loadClass(LauncherImpl.java:382)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$3(LauncherImpl.java:421)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: jpos/JposException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at b4j.example.main.<clinit>(main.java:17)
... 12 more
Caused by: java.lang.NoClassDefFoundError: jpos/JposException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:340)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:519)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:506)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:252)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
... 14 more
Caused by: java.lang.ClassNotFoundException: jpos.JposException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 25 more
package anywheresoftware.b4j.javaPOS;
import anywheresoftware.b4a.BA.ShortName;
import jpos.JposConst;
import jpos.JposException;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
//import jpos.events.ErrorEvent;
//import jpos.events.ErrorListener;
//import jpos.events.OutputCompleteEvent;
//import jpos.events.OutputCompleteListener;
//import jpos.events.StatusUpdateEvent;
//import jpos.events.StatusUpdateListener;
import jpos.util.JposPropertiesConst;
@ShortName("javaPOS")
public class javaPOS {
/**
*
* set the printer name.
* USB = JposPrinter_USB
* SERIAL = JposPrinter_serial
*/
public void PrintTest(){
/*
* If you want to place the jpos.xml file elsewhere on your local file
* system then uncomment the following line and specify the full path to
* jpos.xml.
*/
//System.setProperty( JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "jpos.xml");
System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_URL_PROP_NAME, "c:/SDK/javaPOS/JavaPOS/JposPrinterJavaPOS_Beta04/pos.xml");
String ESC = ((char) 0x1b) + "";
String LF = ((char) 0x0a) + "";
String QR_DOT=((char)0x8)+"";
String QR_ER_LV=((char)0x30)+"";
String PDF_PAR=((char)0x00)+""+((char)0x00)+""+((char)0x06)+""+((char)0x03)+""+
((char)0x30)+""+((char)0x32)+""+((char)0x00)+"";
String SPACES = " ";
// Create an instance of the POSPrinter
POSPrinter printer = new POSPrinter();
try {
// register for asynchronous OutputCompleteEvent notification
//printer.addOutputCompleteListener(this);
// Open the device
printer.open("JposPrinter_USB");
// claim exclusive usage of the printer object
printer.claim(1);
// enable the device for input and output
printer.setDeviceEnabled(true);
printer.setAsyncMode(true);
// set map mode to metric - all dimensions specified in 1/100mm units
printer.setMapMode(POSPrinterConst.PTR_MM_METRIC); // unit = 1/100 mm - i.e. 1 cm = 10 mm = 10 * 100 units
do {
// register for asynchronous StatusUpdateEvent notification
// see the JavaPOS specification for details on this
// printer.checkHealth(JposConst.JPOS_CH_EXTERNAL);
// printer.checkHealth(JposConst.JPOS_CH_INTERACTIVE);
// check if the cover is open
if (printer.getCoverOpen() == true) {
System.out.println("printer.getCoverOpen() == true");
// cover open so do not attempt printing
break;
}
// check if the printer is out of paper
if (printer.getRecEmpty() == true) {
System.out.println("printer.getRecEmpty() == true");
// the printer is out of paper so do not attempt printing
break;
}
// being a transaction
// transaction mode causes all output to be buffered
// once transaction mode is terminated, the buffered data is
// outputted to the printer in one shot - increased reliability
printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_TRANSACTION);
if (printer.getCapRecBitmap() == true) {
// print an image file
try {
printer.printBitmap(POSPrinterConst.PTR_S_RECEIPT, "posprinter.jpg", POSPrinterConst.PTR_BM_ASIS, POSPrinterConst.PTR_BM_CENTER);
} catch (JposException e) {
if (e.getErrorCode() != JposConst.JPOS_E_NOEXIST) {
// error other than file not exist - propogate it
throw e;
}
// image file not found - ignore this error & proceed
}
}
// call printNormal repeatedly to generate out receipt the following
// JavaPOS-POSPrinter control code sequences are used here
// ESC + "|cA" -> center alignment
// ESC + "|4C" -> double high double wide character printing
// ESC + "|bC" -> bold character printing
// ESC + "|uC" -> underline character printing
// ESC + "|rA" -> right alignment
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|bC" + "ZhuHai, China, " + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|bC" + "0756-3895710" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|uC" + "Qnty Unit Tx Description" +
SPACES.substring(0, printer.getRecLineChars() - "Qnty Unit Tx Description".length()) + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, " 1 100 POS58IIH" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, " 1 200 POS76E" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, " 1 300 POSC2008" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|rA" + "Subtotal: 600" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|rA" + "Tax: 50" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|rA" + ESC + "|bC" + "Total: 650" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|rA" + "Tender: 700" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|rA" + ESC + "|bC" + "Change: 50" + LF);
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, LF);
if (printer.getCapRecBarCode() == true) {
// print a PDF417 Code
// the 10 * 100, 60 * 100 parameters below specify the barcode's
// height and width in the metric map mode (1cm tall, 6cm wide)
/*printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
ESC+PDF_PAR+"JposPrinter(C)2016 By Lee",
POSPrinterConst.PTR_BCS_PDF417,
10 * 100, 60 * 100,
POSPrinterConst.PTR_BC_CENTER,
POSPrinterConst.PTR_BC_TEXT_NONE);*/
printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
ESC+QR_DOT+QR_ER_LV+"JposPrinter(C)2016 By Lee",
POSPrinterConst.PTR_BCS_QRCODE,
10 * 100, 60 * 100,
POSPrinterConst.PTR_BC_CENTER,
POSPrinterConst.PTR_BC_TEXT_NONE);
/*printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
"JposPrinter(C)2016 By Lee",
POSPrinterConst.PTR_BCS_Code128,
10 * 100, 60 * 100,
POSPrinterConst.PTR_BC_CENTER,
POSPrinterConst.PTR_BC_TEXT_NONE);*/
}
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|cA" + ESC + "|4C" + ESC + "|bC" + "Thank you" + LF);
// the ESC + "|100fP" control code causes the printer to execute
// a paper cut after feeding to the cutter position
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC + "|100fP");
// terminate the transaction causing all of the above buffered
// data to be sent to the printer
printer.transactionPrint(POSPrinterConst.PTR_S_RECEIPT, POSPrinterConst.PTR_TP_NORMAL);
System.out.println("Async transaction print submited: time = "
+ System.currentTimeMillis() + " output id = " + printer.getOutputID());
// exit our printing loop
} while (false);
} catch (Exception e) {
e.printStackTrace();
} finally {
// close the printer object
if (printer.getState() != JposConst.JPOS_S_CLOSED) {
try {
while (printer.getState() != JposConst.JPOS_S_IDLE) {
Thread.sleep(0);
}
printer.close();
} catch (Exception e) {
}
}
}
}
}
Are you insisting to use JavaPOS?
Have you tried using ESC/POS command to print on thermal printer?
Yes, ESC/POS printer code module provided by agraham above can be use for B4A, B4J and B4i to print through Bluetooth, WiFi, USB and Serial. A little modification is required.
It is better you create a new thread.Hello Aeric, the ESC/POS printer code module provided by agraham doesn't include the code for the cash drawer. Is it possible to add this, or is there a tutorial here in the forum on how to do it?
The Code is provided as a Class. Open it in the IDE and extend it by yourself. It is B4X-Code.Is it possible to add this, or is there a tutorial here in the forum on how to do it?
You may need to check the "printer" documentation on the correct ESC/POS command to kick the drawer using the RJ11 cable.
My printer has slightly different command.
Open money box
1. with this code I can print printString = Chr(10)& Chr(10)& Chr(10) printString = printString & feed printString = printString & Chr(10)& Chr(10)& Chr(10)& Chr(10)& Chr(10) jo.RunMethod("printString",Array(printerGen,printString)) Dim by() As Byte = jo.RunMethodjo("cut",Null)...www.b4x.com
Then send the command to printBytes.
Thank you, Aeric. I've posted my question here: https://www.b4x.com/android/forum/threads/connect-esc-pos-library-to-usb.160531/Again.
I advise you open a new thread for new question of different scope or topic.
If possible, don't abandon the post which members have helped you.Thank you, Aeric. I've posted my question here: https://www.b4x.com/android/forum/threads/connect-esc-pos-library-to-usb.160531/