M mmanso Active Member Licensed User Longtime User Aug 25, 2021 #1 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: Copy 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: Copy 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.
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: Copy 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: Copy 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.
jahswant Well-Known Member Licensed User Longtime User Aug 25, 2021 #2 mmanso said: Sub astreamsUsb_NewData (Buffer() As Byte) numMsgs = numMsgs + 1 End Sub Click to expand... Why do you need new data from printer? You generally send the TOPrint to the printer and it does the job ! Upvote 0
mmanso said: Sub astreamsUsb_NewData (Buffer() As Byte) numMsgs = numMsgs + 1 End Sub Click to expand... Why do you need new data from printer? You generally send the TOPrint to the printer and it does the job !
M mmanso Active Member Licensed User Longtime User Aug 25, 2021 #3 jahswant said: Why do you need new data from printer? You generally send the TOPrint to the printer and it does the job ! Click to expand... 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
jahswant said: Why do you need new data from printer? You generally send the TOPrint to the printer and it does the job ! Click to expand... 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).
agraham Expert Licensed User Longtime User Aug 25, 2021 #4 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
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.
M mmanso Active Member Licensed User Longtime User Aug 25, 2021 #5 I'll try to find something related with that. Thanks. Upvote 0
M mmanso Active Member Licensed User Longtime User Aug 25, 2021 #6 Using AsyncStreams I can start listening with: B4X: Copy astreamsUsbRead.Initialize(UsbSerial1.GetInputStream, Null, "astreamsUsbRead") (only read, no write) Then, after 1 sec (with a timer) call a: B4X: Copy astreamsUsbRead.Close and after 30 seconds, call: B4X: Copy 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
Using AsyncStreams I can start listening with: B4X: Copy astreamsUsbRead.Initialize(UsbSerial1.GetInputStream, Null, "astreamsUsbRead") (only read, no write) Then, after 1 sec (with a timer) call a: B4X: Copy astreamsUsbRead.Close and after 30 seconds, call: B4X: Copy 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.