H hogiebaer Active Member Licensed User Longtime User Jun 8, 2015 #1 Hi Devs, I have a big problem with AStreams or Sockets. When printing on a receipt printer over port 9100 i use Socket1.Connect(printer_ip,9100,4000) .. Code: Copy sub socket1_Connected (Successful As Boolean) if successful=true then astream.initialize(....) Astream.Write(data) Astream.close Socket1.Close end if end sub This code works. Most of the time. But sometimes the Astream.Write doesnt finish, or doesnt get started at all before the Astream.Close event happens, or the socket close. If i don´t close the stream/socket it works, but i have to close the stream/socket, because the printer can´t reach from another station, if the connection is online !! What can i do ???? Thx Use b4a 4.30, network(1.25), randomaccessfile(2.00) Last edited: Jun 8, 2015
Hi Devs, I have a big problem with AStreams or Sockets. When printing on a receipt printer over port 9100 i use Socket1.Connect(printer_ip,9100,4000) .. Code: Copy sub socket1_Connected (Successful As Boolean) if successful=true then astream.initialize(....) Astream.Write(data) Astream.close Socket1.Close end if end sub This code works. Most of the time. But sometimes the Astream.Write doesnt finish, or doesnt get started at all before the Astream.Close event happens, or the socket close. If i don´t close the stream/socket it works, but i have to close the stream/socket, because the printer can´t reach from another station, if the connection is online !! What can i do ???? Thx Use b4a 4.30, network(1.25), randomaccessfile(2.00)
H hogiebaer Active Member Licensed User Longtime User Jun 8, 2015 #2 Ok, i have a dirty solution Code: Copy astream.write(data) Do While astream.OutputQueueSize<>0 DoEvents Loop astr.Close psock.Close but it could be very dangerous, i hate "doevents" other solutions ? Last edited: Jun 8, 2015 Upvote 0
Ok, i have a dirty solution Code: Copy astream.write(data) Do While astream.OutputQueueSize<>0 DoEvents Loop astr.Close psock.Close but it could be very dangerous, i hate "doevents" other solutions ?
Erel B4X founder Staff member Licensed User Longtime User Jun 9, 2015 #3 Does the printer return any response when it is done printing? If not then you should use a timer instead of the Do While loop. Upvote 0
Does the printer return any response when it is done printing? If not then you should use a timer instead of the Do While loop.
H hogiebaer Active Member Licensed User Longtime User Jun 9, 2015 #4 Hi Erel, no response, the only "error" is for me the "connected=false" or "astream events". The way over a timer is a good idea. i could start a timer after write (100msec) Code: Copy sub checkclose_tick if astream.outputqueuesize<>0 then return checkclose_tick.enable=false astream.close socket1.close end sub Upvote 0
Hi Erel, no response, the only "error" is for me the "connected=false" or "astream events". The way over a timer is a good idea. i could start a timer after write (100msec) Code: Copy sub checkclose_tick if astream.outputqueuesize<>0 then return checkclose_tick.enable=false astream.close socket1.close end sub