-
Re: link-os getCurrentStatus() function relatively slow
Robin WestSep 16, 2017 1:23 PM (in response to Adel Sari)
Hi Adel,
There are a few things to try:
1. Try using the status channel (port 9200) as it should parse and respond to those queries faster.
Connection thePrinterConn = new TcpStatusConnection(theIpAddress, TcpStatusConnection.DEFAULT_STATUS_TCP_PORT);
2. You can get and parse the status yourself. I can attach some psudo code showing the process if you want. It might be slightly faster than directly using the SDK, but not hugely.
3. you can utilize the alerts system to be notified when there is a problem, whenever there is a problem. It saves you from having to query the printer all the time, but you do have to have a TCP server socket open to be told there is an issue. If you are the primary app your client is working with, then this might be a good solution. You check the status when your app starts up, then start the TCP server to listen for status alerts from the printer. There are several commands to work with the alerts using SGD commands or ZPL.
Hope this helps!
-
Re: link-os getCurrentStatus() function relatively slow
Adel Sari Aug 31, 2017 11:12 AM (in response to Robin West)Hi Robin,
I would be grateful if you can attach some pseudo code (point 2).
point 3 is not an option for me.
thanks
-
Re: link-os getCurrentStatus() function relatively slow
Robin WestSep 1, 2017 12:38 PM (in response to Adel Sari)
public static getStatus(string theIpAddress)
{
Connection thePrinterConn = new TcpStatusConnection(theIpAddress, TcpStatusConnection.DEFAULT_STATUS_TCP_PORT);
try{
thePrinterConn.open();
String getstatus = "~HQES";
byte[] response = new byte[150];
thePrinterConn.write(getstatus
.getBytes()
);thePrinterConn.waitForData(3000);
response = thePrinterConn.read();
parseResponse(response);
}
catch(ConnectionException){//do stuff}
finally { //close connection }
}
public static parseResponse(byte[] response)
{
int is_error = response[70];
int media = response[88];
int head = response[87];
int pause = response[84];
string[] status = new string[10];
bool ok = false;
if (is_error == 48) // ASCII '0'
{
ok = true;
status.Add("Ready to Print");
}
if (media == 49) // ASCII '1'
status.Add("Error: Paper out");
if (media == 50) // ASCII '2'
status.Add("Error: Ribbon Out");
if (media == 52) // ASCII '4'
status.Add("Error: Media Door Open");
if (media == 56) // ASCII '8'
status.Add("Error: Cutter Fault");
if (head == 49) // ASCII '1'
status.Add("Error: Printhead Overheating");
if (head == 50) // ASCII '2'
status.Add("Error: Motor Overheating");
if (head == 52) // ASCII '4'
status.Add("Error: Printheat Fault");
if (head == 56) // ASCII '8'
status.Add("Error: Incorrect Printhead");
if (pause == 49) // ASCII '1'
status.Add("Printer Paused");
if ((!ok) && (status.Count == 0))
status.Add("Error: Unknown Error");
}
The response should be 144 bytes ending in a hex 03, so you might have to read a few times to get it all. I stole this from some C# code, so please use it as psudocode and not real Java. The printer can have multiple status conditions at the same time.
-
-
Re: link-os getCurrentStatus() function relatively slow
Adel Sari Sep 1, 2017 10:52 AM (in response to Robin West)Hi Robin,
Using TcpStatusConnection fixed the issue, it's really faster to get the status with.
Thanks
-