|
FOROS PROFESIONALES WINDEV, WEBDEV y WINDEV Mobile |
| | | | | |
[WM18]Printing to Epson TM-T88 from Android |
Iniciado por Ericus, 04,abr. 2016 22:52 - 9 respuestas |
| |
| | | |
|
| |
Publicado el 04,abril 2016 - 22:52 |
Hi
Once again trying to print from an Android application to an ethernet printer.
The epos SDK for Android manual seems a great tool but I am not getting anywhere.
My code look like this but I have actually no idea what I am doing. So I created a Java procedure called EpsonPrint and I want to pass it the IP address of my printer which is 192.168.0.23.
Most of the code below is copied from the manual but it won't compile.
Can anybody perhaps throw a few pointers this way to get me out of this hole?
Thanks in advance
Ericus Steyn
import com.epson.epos2.discovery.Discovery; import com.epson.epos2.discovery.DiscoveryListener; import com.epson.epos2.discovery.FilterOption; import com.epson.epos2.discovery.DeviceInfo; import com.epson.epos2.Epos2Exception; import com.epson.epos2; import com.epson.eposeasyselect;
import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; import android.widget.SimpleAdapter;
import java.util.ArrayList; import java.util.HashMap;
import android.permission.INTERNET; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Typeface; import android.text.Layout; import android.text.StaticLayout; import android.text.TextPaint; import android.util.Log; import java.lang.String;
static String EpsonPrint(String portName); Printer printer = null; try { printer = new Printer(Printer.TM_T88, Printer.MODEL_ANK, this); } catch (Epos2Exception e) { //Displays error messages } printer.setReceiveEventListener(this);
try { printer.addTextAlign(Printer.ALIGN_CENTER); printer.addText("Hello World"); } catch (Epos2Exception e) { //Displays error messages }
try { printer.connect("TCP:192.168.0.23", Printer.PARAM_DEFAULT); printer.beginTransaction(); } catch (Epos2Exception e) { //Displays error messages }
PrinterStatusInfo status = printer.getStatus(); if (status.getConnection() && status.getOnline()) { try { printer.sendData(Printer.PARAM DEFAULT); }catch (Epos2Exception e) { // Displays error messages // Abort process } }else { // Displays error messages // Abort process }
public void onPtrReceive(final Printer printerObj, final int code, final PrinterStatusInfo status, final String printJobId) { runOnUiThread(new Runnable() { @Override public synchronized void run() { if (code == Epos2CallbackCode.CODE_SUCCESS) { //Displays successful print messages } else { //Displays error messages } } }); new Thread(new Runnable() { @Override public synchronized void run() { //Abort process } }).start(); }
try { printer.endTransaction(); printer.disconnect(); } catch (Epos2Exception e) { //Displays error messages }
printer.clearCommandBuffer(); printer.setReceiveEventListener(null); |
| |
| |
| | | |
|
| | |
| |
Publicado el 06,abril 2016 - 12:56 |
Are there no WM developers developing Android POS systems?
There must be somebody writing to Epson POS printers.
I am even prepared to pay for the code section that connects with the printer and prints a cash slip.
Regards
Ericus Steyn |
| |
| |
| | | |
|
| | |
| |
Publicado el 06,abril 2016 - 13:08 |
Ericus,
we develop POS systems and also have a Android client. However it's not a stand alone client. Whenever printing is needed, the Android device sends a message to de main POS system (which is a Windev app and also holds the hfsql database) and the printing is done from there. Main advantage is that we can print to every printer we want, be it parallel, serial, usb tcpip. So if you also have a pc connected this different route may also be an option. |
| |
| |
| | | |
|
| | |
| |
Publicado el 06,abril 2016 - 17:50 |
Hallo Arie
Thanks for the advice.
This app will be running on a tablet only, with the printer connected via Ethernet.
I have got a sample application running in Eclipse. Not quite 100% there yet but maybe I can get more info from Eclipse on how to print to the printer.
It seems as if everything is done via XML but still trying to figure out how to do this from WM18.
Regards
Ericus |
| |
| |
| | | |
|
| | |
| |
Publicado el 06,abril 2016 - 19:56 |
Ericus,
I would first simplify the Java code as much as possible, just to get something to work. So remove the event handler which make things more complex. I don't think it is required. I also think that some of the "imports" can be omitted.
Where can I find the epson library? I'm willing to give it a try, see if it gets compiled. I don't have an Epson printer atm, so I can not do a real world test.
import com.epson.epos2.discovery.Discovery; import com.epson.epos2.discovery.DiscoveryListener; import com.epson.epos2.discovery.FilterOption; import com.epson.epos2.discovery.DeviceInfo; import com.epson.epos2.Epos2Exception; import com.epson.epos2; import com.epson.eposeasyselect; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListView; import android.widget.SimpleAdapter; import java.util.ArrayList; import java.util.HashMap; //import android.permission.INTERNET; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Typeface; import android.text.Layout; import android.text.StaticLayout; import android.text.TextPaint; import android.util.Log; import java.lang.String; public static boolean EpsonPrint_Simple(String portName, String yourtext); { Printer printer = null; printer = new Printer(Printer.TM_T88, Printer.MODEL_ANK, this); printer.addTextAlign(Printer.ALIGN_CENTER); printer.addText(yourtext); printer.connect(portname, Printer.PARAM_DEFAULT); printer.beginTransaction(); printer.sendData(Printer.PARAM_DEFAULT); printer.endTransaction(); printer.disconnect(); return true; } and call this with a simple WL call
EpsonPrint_Simple("TCP:192.168.0.23","Hello World!") |
| |
| |
| | | |
|
| | |
| |
Publicado el 06,abril 2016 - 22:43 |
| |
| |
| | | |
|
| | |
| |
Publicado el 07,abril 2016 - 14:38 |
| |
| |
| | | |
|
| | |
| |
Publicado el 11,abril 2016 - 11:41 |
Hi Ericus,
I finally had some time and I found that the code you provided does not match the SDK. A JAR file is actually a compressed file and you can look into it. If you add the .ZIP extension you open and browse it using total commander or whatever tool you want. Then you see how the names of the libraries actually are.
i.e. import com.epson.epos2; should be import com.epson.eposprint;
After some trial and error I can compile the code below. If it really works is now up to you :rp:
import com.epson.epsonio.*; import com.epson.eposprint.*; import com.epson.easyselect.*; public static boolean EpsonPrint_Simple(String portName, String yourtext) { //Initialize a Print class instance Print printer = new Print(); int[] status = new int[1]; status[0] = 0; DeviceInfo[] mList = null; Print printer = new Print(); //Get device list try { mList = Finder.getDeviceInfoList(FilterOption.PARAM_DEFAULT); //Exception handling } catch ( EpsonIoException e ) { // errStatus = e.getStatus(); } try { //Initialize a Builder class instance Builder builder = new Builder("TM-T88V", Builder.MODEL_ANK); //Create a print document // builder.addTextLang(Builder.LANG_EN); builder.addTextSmooth(Builder.TRUE); builder.addTextFont(Builder.FONT_A); builder.addTextSize(4, 4); builder.addTextStyle(Builder.FALSE, Builder.FALSE, Builder.TRUE, Builder.PARAM_UNSPECIFIED); // builder.addText("Hello,\ "); builder.addText("World!\ "); builder.addCut(Builder.CUT_FEED); //Send a print document // ////Wi-Fi/Ethernet device // printer.openPrinter(mList.getDeviceType(), mList.getDeviceName()); printer.openPrinter(Print.DEVTYPE_TCP, "192.168.192.168", Print.TRUE, Print.PARAM_DEFAULT); ////USB device // printer.openPrinter(mList.getDeviceType(), mList.getDeviceName(), "null", Print.TRUE, Print.PARAM_DEFAULT); ////USB device // printer.openPrinter(mList.getDeviceType(), mList.getDeviceName(), getApplicationContext(), Print.TRUE, Print.PARAM_DEFAULT); // printer.sendData(builder, 10000, status); // if((status[0] & Print.ST_PRINT_SUCCESS) == Print.ST_PRINT_SUCCESS) { { builder.clearCommandBuffer(); } // printer.closePrinter(); } } catch (EposException e) { int errStatus = e.getErrorStatus(); status[0] = e.getPrinterStatus(); //printer.closePrinter(); } return true; } |
| |
| |
| | | |
|
| | |
| |
Publicado el 11,abril 2016 - 11:59 |
Forgot to mention that you have to include these 2 files when generating the APK file ePOSEasySelect.jar ePOS-Print.jar I have copied them into my WM-projectmap, but you can include them from any location.
You also have to copy them to the device. i.e. by adding them to the APK (there's an option somewhere in the wizard to do that) |
| |
| |
| | | |
|
| | |
| |
Miembro registrado 24 mensajes |
|
Publicado el 21,octubre 2021 - 10:15 |
Hello, I am facing the same problem. Indeed, I need to print from an EPSON TM-m30II-H printer from an Android tablet. Can you help me please (Windev Mobile source code example)? Thank you.
-- Jean-Marc SOUCHEZ www.directdevlop.fr |
| |
| |
| | | |
|
| | | | |
| | |
| | |
| |
|
|
|