Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
10
Erster Beitrag:
vor 1 Jahr, 4 Monaten
Letzter Beitrag:
vor 1 Jahr, 4 Monaten
Beteiligte Autoren:
Ericus, Arie, Fabrice Harari

[WM18]Printing to Epson TM-T88 from Android

Startbeitrag von Ericus am 04.04.2016 20: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);

Antworten:

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

von Ericus - am 06.04.2016 10:56
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.

von Arie - am 06.04.2016 11:08
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

von Ericus - am 06.04.2016 15:50
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!")

von Arie - am 06.04.2016 17:56
Hallo Arie

I downloaded this sample for Android

https://dl.dropboxusercontent.com/u/8747879/ePOS-Print_SDK_151113E.zip

The index.html shows it works with the TM-T88V

I really appreciate your willingness to assist.


Ericus Steyn

von Ericus - am 06.04.2016 20:43
Hi Ericus,

there is a post on the french windev mobile forum :
http://forum.pcsoft.fr/fr-FR/pcsoft.fr.windevmobile/23149-imprimante-mobile-avec-android/read.awp

One guy (NICO) already did it for a zebra printer and says he's available for more information.
So if you are looking for somebody to assist, he may be able to help with some code.

Best regards

von Fabrice Harari - am 07.04.2016 12:38
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,\t");
builder.addText("World!\n");
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;
}


von Arie - am 11.04.2016 09:41
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)

von Arie - am 11.04.2016 09:59
Hi

I have managed to get my application to compile and install on the device but whenever I want to print it complains about the libeposprint.so file not found.

So I found the 3 .so files that come with the SDK and included it in the APK but still it will not print and I receive the same error.

The full error on the device is:

Internal error of WDJava framework. :dalvik.system.PathClassLoader[DexPathList[[zip file */data/app/com.mycompany.plumaccountingmobile-1/base.apk"].nativeLibraryDirectories = [/data/app/com.mycompany.plumaccountingmobile-1/lib/arm,/vendor/lib,/system/lib]] couldn't find "libeposprint.so"

I am not that familiar with Android file layouts but not of these folders exist or I don't know where to look for them.

Can anybody help please?

Thanks in advance.



Ericus Steyn

von Ericus - am 18.04.2016 10:45
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.