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,259
  • usb2.png
    usb2.png
    109.7 KB · Views: 1,233
Last edited:

vvg

Member
Licensed User
Longtime User
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
 

vvg

Member
Licensed User
Longtime User
Error:
(Exception) java.lang.Exception: java.lang.ArrayIndexOutOfBoundsException: length=8; index=8

My vid - 1155
Pid - 22304
 

mmanso

Active Member
Licensed User
Longtime User
I'm trying to print an image with your library and the result I'm getting is this:

IMG_1561.jpg


That print has two images... the logo on top and right after (A01) is another image.

The logo is not being well processed. I've another machine with a bluetooth printer and I'm using a library to print the same thing to it. The result is this:

IMG_1562.jpg


Do you have any ideia why is this happening and if there's anything I can do to fix it?

Apart from this, everything works ok with the library.

Thanks.
 

mmanso

Active Member
Licensed User
Longtime User
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

Hi there,

Did you manage to sort this issue? I'm having the same problem.

Thanks.
 

mmanso

Active Member
Licensed User
Longtime User
Hi there,

I've fixed the bug in the USBprint.jar that was causing the crash using the method:

B4X:
pt.connectusb2(vid,pid)

If you replace the library by the attached, it will work.

Cheers.
 

Attachments

  • USBprint.jar
    18 KB · Views: 339

Kevin Hartin

Active Member
Licensed User
Any idea why I am getting the following error on compile?
Compile Error:
Linking resources    Error
AndroidManifest.xml:31: error: unexpected element <action> found in <manifest><application><activity>.

I used the Example code which has the manifest as follows;

Manifest:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true" 
    android:normalScreens="true" 
    android:smallScreens="true" 
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddActivityText(main,
    <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />

    )

The only change I have made to the code is vid=0x1d6B and pid=0x0002 after a Device Info app reported DeviceID 1d6b:0002

Thanks,
Kev
 
Top