B4A Library ECS/POS printer USB print library

i do not know java,and never use eclipse before, i study make libary 1 week,now have self library now )
i have test this code many times, it is really hardly work for me,
here cannot upload my eclipse project,it is too big,how to upload it ?
if this library can help you ,i will send my eclips project .my java is poor,
if i upload eclips project ,you can make this libary more better then me.


i have test on my pos printer,work good now ,can print picture.string

my print device use default ".connectusb" fuction, if you change print device need ".connectusb2" instead.

and you need get your usb" VendorID , productID"
how to get your print device ID ,here have picture .(do not forget add 0x before your IDs)

the ".printdata"fuction ,you can send HEX code to printer. it is is printer control code.in PDF file have EPSON FAQ, in FAQ,the Turn "white/black reverse "command "1d 42", MUST change to under FORMAT SEND:
"0x1d, 0x42, 0x01". (0x01 must put in end. and add 0x)

In mainfest need add usb permition :
B4X:
AddActivityText(main,
    <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />

    )

under is b4a sample code

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
     #BridgeLogger: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
 
    Dim pt As  printdemo
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    pt.initialize

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
 
    Dim vid As Int
    Dim pid As Int
    vid=0x1CBE
    pid=0x0003
    pt.connectusb2(vid,pid) 'HERE IS YOU DEVICE VendorID AND productID"
 
End Sub

Sub Button2_Click
    pt.printstr("UNDER IS PICTURE")
 
    pt.printtest  'TEST PAPER
 
 
End Sub

Sub Button3_Click
    Dim pic As Bitmap
 
    pic.Initialize(File.DirAssets,"look.bmp")
 
    pt.printstr("UNDER IS PICTURE")
    pt.Print_BMP2(pt.POSPrintBMP(pic,300,0))   '(PICTURE,PAPER WIDTH,0)
 
 
    Sleep(1000)
 
 
 
    pt.cut    'CUT PAPAR
    pt.Printbeep 'VOICE BEEP
End Sub
 

Attachments

  • usbprint.zip
    40.6 KB · Views: 1,085
  • uspprint_demo.zip
    468.4 KB · Views: 1,123
  • usb1.png
    usb1.png
    106.4 KB · Views: 1,261
  • usb2.png
    usb2.png
    109.7 KB · Views: 1,234
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Hello, nice library
is possible print to bluetooth printers with this library ?

thanks
 

hears

Active Member
Licensed User
Longtime User
Hello, nice library
is possible print to bluetooth printers with this library ?

thanks
bluetooth cannot,my printer only have wifi and usb
,next step will writ WIFI print
 

hears

Active Member
Licensed User
Longtime User
THIS IS EPSON HEX COMMAND FAQ,IT CAN SEND BY ".printdata" function
 

Attachments

  • EPSON POS FAQ.pdf
    161.2 KB · Views: 756

hears

Active Member
Licensed User
Longtime User

fifiddu70

Well-Known Member
Licensed User
Longtime User
i have this error when push button1:
Logger connesso a: WIKO U FEEL
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **

main_button1_click (java line: 371)
java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
at cn.com.zj.usbdemo.PrintDemo.connectusb2(PrintDemo.java:1353)
at b4a.example.main._button1_click(main.java:371)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
 

hears

Active Member
Licensed User
Longtime User
i have this error when push button1:
Logger connesso a: WIKO U FEEL
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **

main_button1_click (java line: 371)
java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
at cn.com.zj.usbdemo.PrintDemo.connectusb2(PrintDemo.java:1353)
at b4a.example.main._button1_click(main.java:371)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

you need get your usb info,after change this 2 value

B4X:
Dim vid As Int
    Dim pid As Int
    vid=0x1CBE
    pid=0x0003
    pt.connectusb2(vid,pid) 'HERE IS YOU DEVICE VendorID AND productID"

need download andriod shell APP to get this,
https://www.b4x.com/android/forum/attachments/usb2-png.62620/
 

hears

Active Member
Licensed User
Longtime User
i have this error when push button1:
Logger connesso a: WIKO U FEEL
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **

main_button1_click (java line: 371)
java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
at cn.com.zj.usbdemo.PrintDemo.connectusb2(PrintDemo.java:1353)
at b4a.example.main._button1_click(main.java:371)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

this libary not work with all USB printer, only usb pos print
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi, i try many time with this lib and printer ncx

my device is


Product ID: 0x811e
Vendor ID: 0x0fe6
Version: 1.00
Speed: Up to 12 Mb/sec
Location ID: 0x14100000 / 11
Current Available (mA): 500
Current Required (mA): 100
Extra Operating Current (mA): 0


change to

B4X:
                pt.connectusb2(0x0fe6,0x811e)


all i got it's an error

(Exception) java.lang.Exception: java.lang.ArrayIndexOutOfBoundsException: length=8; index=8

Any help will be apreciated.

Victor
 

Gabino A. de la Gala

Well-Known Member
Licensed User
Longtime User
I got the same error when Connect click :

B4X:
--------- beginning of crash
--------- beginning of main
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
main_button1_click (java line: 371)
java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
    at cn.com.zj.usbdemo.PrintDemo.connectusb2(PrintDemo.java:1353)
    at b4a.example.main._button1_click(main.java:371)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7352)
    at android.widget.TextView.performClick(TextView.java:14177)
    at android.view.View.performClickInternal(View.java:7318)
    at android.view.View.access$3200(View.java:846)
    at android.view.View$PerformClick.run(View.java:27800)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
 

George Sheehy

Member
Licensed User
This is the error:

upload_2019-11-5_6-17-27.png


Loaded Libraries:

upload_2019-11-5_6-18-45.png


Ther error is generated at Line 47 and is : pt.connectusb2(vid,pid)

This is the code:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#BridgeLogger: True
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
Dim pt As printdemo
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
pt.initialize
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click

Dim vid As Int
Dim pid As Int
vid=0x4B8
pid=0xE15
pt.connectusb2(vid,pid) '<-- This is the statment that generates the error

End Sub

Sub Button2_Click
pt.printstr("UNDER IS PICTURE")

pt.printtest 'TEST PAPER


End Sub

Sub Button3_Click
Dim pic As Bitmap

pic.Initialize(File.DirAssets,"look.bmp")

pt.printstr("UNDER IS PICTURE")
pt.Print_BMP2(pt.POSPrintBMP(pic,300,0)) '(PICTURE,PAPER WIDTH,0)


Sleep(1000)



pt.cut 'CUT PAPAR
pt.Printbeep 'VOICE BEEP
End Sub
 

victormedranop

Well-Known Member
Licensed User
Longtime User
This is the error:

View attachment 85217

Loaded Libraries:

View attachment 85218

Ther error is generated at Line 47 and is : pt.connectusb2(vid,pid)

This is the code:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#BridgeLogger: True
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

Sub Globals
Dim pt As printdemo
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
pt.initialize
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click

Dim vid As Int
Dim pid As Int
vid=0x4B8
pid=0xE15
pt.connectusb2(vid,pid) '<-- This is the statment that generates the error

End Sub

Sub Button2_Click
pt.printstr("UNDER IS PICTURE")

pt.printtest 'TEST PAPER


End Sub

Sub Button3_Click
Dim pic As Bitmap

pic.Initialize(File.DirAssets,"look.bmp")

pt.printstr("UNDER IS PICTURE")
pt.Print_BMP2(pt.POSPrintBMP(pic,300,0)) '(PICTURE,PAPER WIDTH,0)


Sleep(1000)



pt.cut 'CUT PAPAR
pt.Printbeep 'VOICE BEEP
End Sub


i try this libs, but never work.

victor
 

George Sheehy

Member
Licensed User
I am currently trying to get the following to work with my app.

EPSON TM-T20II VID_04B8, PID_0E15
Excelvan Model: ZJ-5890F VID_0416, PID_5011


1st choice is the EPSON
The 2nd printer (Excelvan) is a cheap printer (arounc $25.00) that I would like to try.

Thanks.
 

f0raster0

Well-Known Member
Licensed User
Longtime User
we use a printer Bluetooth, maybe you could get one.
it's really simple. We use in restaurants, without problems.
 
Top