I am trying to get the host status from a ZQ520 printer in a cross plat form app as shown below.
string queryString = "^XA^HZA^XZ";
connection.TimeToWaitAfterRead = 60000;
connection.TimeToWaitAfterWrite = 60000;
connection.TimeToWaitForMoreData = 60000;
byte[] response = connection.SendAndWaitForResponse(Encoding.UTF8.GetBytes(queryString), 60000, 60000, "");
//Attempted with and without terminator
string strResponse = Encoding.UTF8.GetString(response);
The response is complete when running on an android; however, it is truncated on iOS. The iOS response is 2,170 bytes in length. The expected response is about 36K.
This is the truncated response.
ZQ520
V76.20.15Z
5.2
1.3
MANUFACTURER:Zebra Technologies ;COMMAND SET:CPCL;MODEL:ZTC ZQ520 (CPCL);CLASS:PRINTER;OPTIONS:XML;
DISABLED
8
832
R
8388608
8365056
E
67108864
66939392
N
ZebraNet Wireless PS
V76.20.15Z
79071
H
H
00.00.00
00:00:00:00:00:00
0161A
Online
ZTC ZQ520-203dpi ,
Y
00 days 00 hours 46 mins 14 secs
XXRBJ192801767
20.0
20.0
10.0
0
0
0
REWIND
REWIND
REWIND
CONTINUOUS
CONT
2 Replies
Hi Steve,
Thanks for the reply. Yes I am using Link OS (v1.2) and I do have a BT connection.
I have tried adjusting the timeouts and had it set as high as 180000 at one time. I also tried to get the response with and without a terminator. The problem still hasn't been resolved; however, I did stumble on a workaround using trial and error. A curious thing to note about the initial response is it is always exactly 2048 bytes in length. It kind of looks like there is a 2K limit being set somewhere. The remainder of the response is available, but you need to invoke connection.Read() to get it. The following sample returns the complete response in the byte[] response1. The first call places 2048 bytes into response1. The read statement places about 34k into response2. Both arrays are combined and placed back into response1. It is about 36k in length. This also appears to be an iOS only issue. My android device does not require a second read. The entire 36k response is returned with SendAndAwaitForResponse on my android.
string queryString = session.AppSpec.GetValue("ZebraGetInfo", "^XA^HZA^XZ");
/*connection.TimeToWaitAfterRead = 180000;
connection.TimeToWaitAfterWrite = 180000;
connection.TimeToWaitForMoreData = 180000;
connection.MaxTimeoutForRead = 180000;*/;
byte[] response1 = connection.SendAndWaitForResponse(Encoding.UTF8.GetBytes(queryString), 2000, 2000, "");
string strResponse = Encoding.UTF8.GetString(response1);
if (!strResponse.Contains(""))
{
byte[] response0 = response1;
System.Threading.Thread.Sleep(2000);
byte[] response2 = connection.Read();
response1 = new byte[response0.Length + response2.Length];
response0.CopyTo(response1, 0);
response2.CopyTo(response1, response0.Length);
}
Are you using Link-OS SDK for Xamarin for your cross platform app? Does this happen on Bluetooth connection?
I use Link-OS SDK for iOS, in which I observed the incomplete response to ^HZA on Bluetooth with ZQ520 printer when using the default timeouts in the connection. After adding 10,000ms wait time (instead of 60000ms), I am able to get the full response back from ZQ520. Then I switched to ZQ610 printer with and without adding the extra wait-time. The responses to ^HZA from ZQ610 were complete regardless the extra wait-time. Certainly, this confirms that ZQ520 has a slower response to ^HZA, probably due to the HW & SW on ZQ520. However, adding the extra wait-time, we can still get the full response to ^HZA from ZQ520. For simplification, I passed nil to the validator parameter when calling SendAndWaitForResponse(). Could you try without the validator to see if you can get the full response from ZQ520 with 10000ms wait-time?
Updated...
Just did a test with Link-OS SDK for Xamarin v2.15.2634. The response from ZQ520 to ^HZA on Bluetooth is complete on both Android and iOS. The code used to retrieve the host status is below. In my test, the timeouts are the default timeouts for connection. The initialResponseTimeout and responseCompletionTimeout are set to 2000ms. There is no issue of incomplete or truncated response of the host status for me.
string queryString = "^XA^HZA^XZ";
byte[] response = connection.SendAndWaitForResponse(Encoding.UTF8.GetBytes(queryString), 2000, 2000, "");
string strResponse = Encoding.UTF8.GetString(response);