Welcome! Log In Create A New Profile

Advanced

[WM18]Printing to Epson TM-T88 from Android

Posted by Ericus 
Ericus
[WM18]Printing to Epson TM-T88 from Android
April 04, 2016 10:52PM
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);
Ericus
Re: [WM18]Printing to Epson TM-T88 from Android
April 06, 2016 12:56PM
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
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.
Ericus
Re: [WM18]Printing to Epson TM-T88 from Android
April 06, 2016 05:50PM
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
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!")
Ericus
Re: [WM18]Printing to Epson TM-T88 from Android
April 06, 2016 10:43PM
Hallo Arie

I downloaded this sample for Android

[dl.dropboxusercontent.com]

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

I really appreciate your willingness to assist.


Ericus Steyn
Fabrice Harari
Re: [WM18]Printing to Epson TM-T88 from Android
April 07, 2016 02:38PM
Hi Ericus,

there is a post on the french windev mobile forum :
[forum.pcsoft.fr]

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
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    
		//<The page mode starts>    
		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);    
		//<Specify the print data>    
		builder.addText("Hello,\t");    
		builder.addText("World!\n");    
		builder.addCut(Builder.CUT_FEED);    
		//Send a print document    
		//<Start communication with the printer>    
		////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);    
		//<Send data>    
		printer.sendData(builder, 10000, status);    
		//<Delete the command buffers>    
		if((status[0] & Print.ST_PRINT_SUCCESS) == Print.ST_PRINT_SUCCESS)    {
			{        
				builder.clearCommandBuffer();    
			}    
			//<End communication with the printer>    
			printer.closePrinter();
		}
	} 
	catch (EposException e) 
	{    
		int errStatus = e.getErrorStatus();    
		status[0] = e.getPrinterStatus();    
		//printer.closePrinter(); 
	}
	
	return true;
}
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)
Ericus
Re: [WM18]Printing to Epson TM-T88 from Android
April 18, 2016 12:45PM
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
Jean-Marc SOUCHEZ
Re: [WM18]Printing to Epson TM-T88 from Android
October 27, 2021 10:16AM
Hello,
I am looking to do the same program.
Have you been successful and can you help me ?
Thank you.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: