Android Question USB ticket printer - error when open(9600,1)

Abílio Magalhães

Member
Licensed User
Longtime User
Hi,

I', using Usb Serial library 2.4 and my usb ticket printer is recognized.

Demo example from library 2.4 prompt user to accept permissions but when code try to open the port it fails.

That could be wrong to get the error and app enter in the line: Log("Error opening USB port 1") ??

Printer is working with some serial over usb examples from Google Play.


Kind regards,
Abilio
-------------------------------------------------
The code:

If usb1.UsbPresent(1) = usb1.USB_NONE Then ' Ver_2.4

Log("Msgbox - no deviceddddd")

Msgbox("No USB device or accessory detected!", "Error")

Log("Msgbox - returned")

Return

EndIf

Log("Checking permission 1")

If (usb1.HasPermission(1)) Then ' Ver_2.4

Log(usb1.DeviceInfo(1))

Msgbox(usb1.DeviceInfo(1), "Device Information 1") ' Ver_2.4

Dim dev As Int

'dev = usb.Open(115200, 1) ' Ver_2.4

usb1.SetParameters(115200,usb1.DATABITS_8,usb1.STOPBITS_1,usb1.PARITY_NONE)

dev = usb1.Open(115200, 1) ' Ver_2.4

If dev <> usb1.USB_NONE Then

Log("Connected successfully! 1")

btnOpen.Enabled = False

btnClose.Enabled = True

btnSend.Enabled = True

astreams1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, "astreams1")

Else

Log("Error opening USB port 1")

EndIf

Else

usb1.RequestPermission(1) ' Ver_2.4

EndIf
 

Dadaista

Active Member
Licensed User
Longtime User
And... what can we do in this case?

With the ticket printer came an android program that prints!!! :confused::confused:

.jar, .class and .java files in the installation cd. (source code).

How can I build a lib recognized in b4a?o_Oo_O
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
And... what can we do in this case?

With the ticket printer came an android program that prints!!! :confused::confused:

.jar, .class and .java files in the installation cd. (source code).

How can I build a lib recognized in b4a?o_Oo_O

better post the available java project here ,so that some one can make a lib or port.

Or Try creating your own library.
 
Upvote 0

Dadaista

Active Member
Licensed User
Longtime User
How can I post the project? I don't know where is it. A lot of files is what I see :(

I would like to know create libraries but unfortunately my knowledge is not enough :(

thx jazzzzzzz :)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Try so:

B4X:
Sub btn_general_check_Click

    If usb1.UsbPresent(1) = usb1.USB_NONE Then    ' Ver_2.4
        Label1.Text = "No device USB NONE"
        Return
    End If
    If (usb1.HasPermission(1)) Then    ' Ver_2.4
        Log(usb1.DeviceInfo(1))
        'This is very important - ( VendorId, ProductId )
        usb1.SetCustomDevice(usb1.DRIVER_SILABS, 0x4B8, 0xE15)

        Dim dev As Int
        dev = usb1.Open(19200, 1) 'STMicroeletronics
        If dev <> usb1.USB_NONE Then
            Log("Connected successfully! 1")

            Label1.Text = ""
            Log("CONNECTED SUCCESSFULLY!!!")

             astreams1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, "astreams1")

            'This is important
            usb1.SetParameters(19200, usb1.DATABITS_8,usb1.STOPBITS_1, usb1.PARITY_NONE)
            'Here if you want codce that call print
        Else
            Log("Error opening USB port 1")
        End If
    Else
        usb1.RequestPermission(1)  ' Ver_2.4
    End If
   

End Sub

1. Look
Log(usb1.DeviceInfo(1))

You have a result more or less this type:

Screenshot_2016-05-19-18-15-27.png


2. Get value ProductId and VendorId
3. Put this value in code
usb1.SetCustomDevice(usb1.DRIVER_SILABS, 0x4B8, 0xE15)
 
Upvote 0

Dadaista

Active Member
Licensed User
Longtime User
Oh!!! it works!!!

Thank you so much for your help MarcoRome. It has been really useful. So I really appreciate it. :):)
 
Upvote 0
Top