Android Question UsbSerial - massive NewData events raised

mmanso

Active Member
Licensed User
Longtime User
Hi there,

I'm using UsbSerial to connect to a usb thermal printer device.

I can connect to it and I can print with success.

After I've connected to the device, I use this:

B4X:
astreamsUsb.Initialize(UsbSerial1.GetInputStream, UsbSerial1.GetOutputStream, "astreamsUsb")

I then start receiving information on the "astreamsUsb_NewData" function. I can read the printer status, I can detect paper errors and all that.

After I started to do this, I realized my app was getting slower and slower. I've created a counter like this:

B4X:
Sub astreamsUsb_NewData (Buffer() As Byte)   
    numMsgs = numMsgs + 1
End Sub

And I realised that in 1 minute, the value of numMsgs was almost 650.000, meaning this event is being called A LOT.

Any thoughts on this issue? I'm using UsbSerial with the speed of 9600 but the printer is a Usb one.

Any help will be appreciated.

Thanks.
 

mmanso

Active Member
Licensed User
Longtime User
Why do you need new data from printer? You generally send the TOPrint to the printer and it does the job !

I need data to detect if the printer have low paper or the paper runned out. We have a kiosk application and it's important that people know that the paper is over (or almost).
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
There are two possibilities, either you ask the printer for its status and it responds, or it regularly sends it status automatically. It sounds like the latter but it seems far too often to be useful. Check the printer manual and see if you can configure the report frequency.
 
Upvote 0

mmanso

Active Member
Licensed User
Longtime User
Using AsyncStreams I can start listening with:

B4X:
astreamsUsbRead.Initialize(UsbSerial1.GetInputStream, Null, "astreamsUsbRead")

(only read, no write)

Then, after 1 sec (with a timer) call a:

B4X:
astreamsUsbRead.Close

and after 30 seconds, call:

B4X:
astreamsUsbRead.Initialize(UsbSerial1.GetInputStream, Null, "astreamsUsbRead")

again?

I'm asking because I've tried and as soon as I close it, it won't start again.

I was trying this because this way I could avoid the program to get ALL those NewData events and I could check them only once in a while.
 
Upvote 0
Top