C# 网络打印机ESC指令打印小票

        public void SendSocketMsg(String ip, int port, int times, byte[] data)
{
try
{
byte[] mData;
if (times == )
{
mData = new byte[data.Length];
Array.Copy(data, , mData, , data.Length);
}
else
{
mData = new byte[data.Length * times];
byte[][] m = new byte[times][];
for (int i = ; i < times; i++)
{
m[i] = data;
}
Array.Copy(PrinterCmdUtils.byteMerger(m), , mData, , PrinterCmdUtils.byteMerger(m).Length);
} #region 同步 Socket
Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ipAddress = IPAddress.Parse(ip);
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port); mySocket.Connect(ipEndPoint);
//mySocket.Send(data);
mySocket.Send(mData);
mySocket.Close();
#endregion
}
catch (Exception ex)
{
Logger.Trace(ex.Message);
Logger.Trace(ex.StackTrace);
}
}
    public class PrintService
{
static byte[] b_init = PrinterCmdUtils.init_printer();
static byte[] b_nextLine = PrinterCmdUtils.nextLine();
static byte[] b_next2Line = PrinterCmdUtils.nextLine();
static byte[] b_next3Line = PrinterCmdUtils.nextLine();
static byte[] b_center = PrinterCmdUtils.alignCenter();
static byte[] b_left = PrinterCmdUtils.alignLeft();
static byte[] b_breakPartial = PrinterCmdUtils.feedPaperCutPartial(); /// <summary>
/// 会员充值小票
/// </summary>
/// <param name="shop"></param>
/// <param name="num"></param>
/// <param name="count"></param>
/// <param name="way"></param>
/// <param name="time"></param>
/// <returns></returns>
public static byte[] charge(String shop, String num, String count, String way, String time)
{
String shop_f = " 会员充值(" + shop + ")";
String num_f = " 会员号码:" + num;
String count_f = " 充值金额:" + count;
String way_f = " 充值方式:" + way;
String time_f = " 充值时间:" + time; try
{
byte[] b_title = System.Text.Encoding.GetEncoding("gbk").GetBytes(shop_f);
byte[] b_num = System.Text.Encoding.GetEncoding("gbk").GetBytes(num_f);
byte[] b_count = System.Text.Encoding.GetEncoding("gbk").GetBytes(count_f);
byte[] b_way = System.Text.Encoding.GetEncoding("gbk").GetBytes(way_f);
byte[] b_time = System.Text.Encoding.GetEncoding("gbk").GetBytes(time_f);
byte[] b_no = System.Text.Encoding.GetEncoding("gbk").GetBytes(" ----------------------------------------");
byte[] b_breakPartial = PrinterCmdUtils.feedPaperCutPartial(); byte[][] charge_0 = {
b_init,
b_center, b_title, b_next2Line,
b_left, b_count, b_nextLine,
b_way, b_nextLine,
b_time, b_nextLine,
b_no, b_nextLine,
b_breakPartial,
PrinterCmdUtils.open_money()
}; byte[][] charge_1 = {
b_init,
b_center, b_title, b_next2Line,
b_left, b_num, b_nextLine,
b_count, b_nextLine,
b_way, b_nextLine,
b_time, b_nextLine,
b_no, b_nextLine,
b_breakPartial,
PrinterCmdUtils.open_money()
}; if (String.IsNullOrEmpty(num))
{
return PrinterCmdUtils.byteMerger(charge_0);
}
else
{
return PrinterCmdUtils.byteMerger(charge_1);
}
}
catch (Exception)
{
throw;
}
} /// <summary>
/// 收银小票 Json对象拼接
/// </summary>
/// <param name="head"></param>
/// <param name="recv"></param>
/// <param name="foot"></param>
/// <returns></returns>
public static byte[] jsonParse(String head, String recv, String foot, String url)
{
try
{
//二维码生成
EscCommand esc = new EscCommand();
esc.addSelectErrorCorrectionLevelForQRCode((byte)0x31);
esc.addSelectSizeOfModuleForQRCode((byte));
esc.addStoreQRCodeData(url);
esc.addPrintQRCode(); ArrayList datas = esc.getCommand();
Byte[] Bytes = new Byte[datas.Count];
for (int i = ; i < datas.Count; i++)
{
Bytes[i] = (Byte)datas[i];
} byte[] bytes = EscCommand.toPrimitive(Bytes); //打印小票头部
List<String> headString = new List<String>();
List<TicketHead> mHeads = JsonConvert.DeserializeObject<List<TicketHead>>(head); headString.Add(" " + mHeads[].Ordertime);
headString.Add(" NO." + mHeads[].Shopno);
headString.Add(FileUtils.getFixedWidthString(" 当班人员:" + mHeads[].Shopuser, ) + "餐牌号:" + mHeads[].Card);
headString.Add(" ---------------------------------------------"); List<String> newString = new List<String>();
List<Ticket> mTickets = JsonConvert.DeserializeObject<List<Ticket>>(recv); String nameTitle = " 名称 数量 售价 优惠 总额";
newString.Add(nameTitle); for (int i = ; i < mTickets.Count; i++)
{
StringBuilder item = new StringBuilder(); if (("".Equals(mTickets[i].Type) || "".Equals(mTickets[i].Type)))
{
if ("".Equals(mTickets[i].Parentid))
{
if (mTickets[i].Name.Length > )
{
item.Append(FileUtils.getFixedWidthString(mTickets[i].Name.Substring(, ), ));
item.Append(mTickets[i].Num.PadRight());
item.Append(String.Format("{0:F2}", mTickets[i].Price).PadRight());
item.Append(String.Format("{0:F2}", mTickets[i].Rebetmoney).PadRight());
item.Append(String.Format("{0:F2}", mTickets[i].Money).PadRight()); newString.Add(" " + item.ToString());
newString.Add(" " + mTickets[i].Name.Substring(, mTickets[i].Name.Length - ));
}
else
{
item.Append(FileUtils.getFixedWidthString(mTickets[i].Name, ));
item.Append(mTickets[i].Num.PadRight());
item.Append(String.Format("{0:F2}", mTickets[i].Price).PadRight());
item.Append(String.Format("{0:F2}", mTickets[i].Rebetmoney).PadRight());
item.Append(String.Format("{0:F2}", mTickets[i].Money).PadRight()); newString.Add(" " + item.ToString());
}
}
else
{
newString.Add(" " + mTickets[i].Name);
}
}
} newString.Add(" ---------------------------------------------"); List<String> footString = new List<String>();
List<TicketFoot> mFoots = JsonConvert.DeserializeObject<List<TicketFoot>>(foot); String moneytotal = ((float.Parse(mFoots[].DecAmmBalance) + float.Parse(mFoots[].DecGroupBuyMoney))).ToString("f2");
String money = ((float.Parse(mFoots[].DecRebeatBalance) + float.Parse(mFoots[].DecGroupBuyMoney))).ToString("f2"); footString.Add(FileUtils.getFixedWidthString(" 餐品数量:", ) + FileUtils.getFixedWidthString(mFoots[].Counts, ) + "点餐金额: " + moneytotal.PadRight()); if (float.Parse(mFoots[].DecWipeMoney) != 0.0f)
footString.Add(FileUtils.getFixedWidthString(" 抹零优惠:", ) + mFoots[].DecWipeMoney); if (float.Parse(mFoots[].DecMemberCoupon) != 0.0f)
footString.Add(FileUtils.getFixedWidthString(" 会员优惠:", ) + mFoots[].DecMemberCoupon); if (float.Parse(money) != 0.0f)
{
footString.Add(FileUtils.getFixedWidthString(" 券类优惠:", ) + money.PadRight()); for (int i = ; i < mTickets.Count; i++)
{
if (!"".Equals(mTickets[i].Type) && !"".Equals(mTickets[i].Type))
{
footString.Add(FileUtils.getFixedWidthString(" " + mTickets[i].Name, ) + mTickets[i].Num);
}
else
{
if (!string.IsNullOrEmpty(mTickets[i].RebetName))
footString.Add(FileUtils.getFixedWidthString(" " + mTickets[i].RebetName, ) + );
}
}
} footString.Add(" ---------------------------------------------");
if (float.Parse(mFoots[].DecPaidBalance) != 0.0f)
footString.Add(FileUtils.getFixedWidthString(" 折后支付:", ) + mFoots[].DecPaidBalance); if (float.Parse(mFoots[].Membermoney) != 0.0f)
footString.Add(FileUtils.getFixedWidthString(" 会员支付:", ) + mFoots[].Membermoney); if (float.Parse(mFoots[].Cashmoney) != 0.0f)
footString.Add(FileUtils.getFixedWidthString(" 现金支付:", ) + mFoots[].Cashmoney); if (!string.IsNullOrEmpty(mFoots[].Bankmoney))
footString.Add(FileUtils.getFixedWidthString(" " + mFoots[].Bankmoney.Split(':')[], ) + mFoots[].Bankmoney.Split(':')[]); if (float.Parse(mFoots[].Givechange) != 0.0f)
footString.Add(FileUtils.getFixedWidthString(" 现金找零:", ) + mFoots[].Givechange); if (float.Parse(mFoots[].RechMoney) != 0.0f)
footString.Add(FileUtils.getFixedWidthString(" 充值金额:", ) + mFoots[].RechMoney); ///////////////////////////////////////////////////////////////////////////////////////// byte[][] headByte = new byte[][]; //头部数组
headByte[] = b_init;
headByte[] = b_center;
headByte[] = System.Text.Encoding.GetEncoding("gbk").GetBytes("欢迎光临");
headByte[] = b_nextLine;
headByte[] = System.Text.Encoding.GetEncoding("gbk").GetBytes(mHeads[].Shopbrand);
headByte[] = b_next2Line;
headByte[] = b_left;
for (int i = ; i < ; i += )
{
headByte[i + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes(headString[i / ]);
headByte[i + ] = b_nextLine;
} byte[][] contentByte = new byte[newString.Count * ][]; //中间体
for (int i = ; i < newString.Count * ; i += )
{
contentByte[i] = System.Text.Encoding.GetEncoding("gbk").GetBytes(newString[i / ]);
contentByte[i + ] = b_nextLine;
} byte[][] footByte = new byte[footString.Count * + ][]; //底部数组
for (int i = ; i < footString.Count * ; i += )
{
footByte[i] = System.Text.Encoding.GetEncoding("gbk").GetBytes(footString[i / ]);
footByte[i + ] = b_nextLine;
} footByte[footString.Count * ] = System.Text.Encoding.GetEncoding("gbk").GetBytes(" ---------------------------------------------");
if (string.IsNullOrEmpty(mHeads[].Memberid))
{
footByte[footString.Count * + ] = b_center;
footByte[footString.Count * + ] = b_center;
}
else
{
footByte[footString.Count * + ] = b_nextLine;
footByte[footString.Count * + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes(" 会员号:" + mHeads[].Memberid);
} footByte[footString.Count * + ] = b_next2Line;
footByte[footString.Count * + ] = b_center;
footByte[footString.Count * + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes("谢谢惠顾!欢迎再次光临!");
footByte[footString.Count * + ] = b_nextLine;
footByte[footString.Count * + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes("如需开发票,请凭小票在一周内到门店开取");
footByte[footString.Count * + ] = b_next2Line; footByte[footString.Count * + ] = b_left;
footByte[footString.Count * + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes(" 门店地址:" + mHeads[].Shopaddress);
footByte[footString.Count * + ] = b_nextLine;
footByte[footString.Count * + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes(" 联系电话:" + mHeads[].Shoptel);
footByte[footString.Count * + ] = b_nextLine;
footByte[footString.Count * + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes(" 品牌网址:" + mHeads[].Url);
footByte[footString.Count * + ] = b_next2Line;
footByte[footString.Count * + ] = b_center; footByte[footString.Count * + ] = b_next2Line;
footByte[footString.Count * + ] = System.Text.Encoding.GetEncoding("gbk").GetBytes("微信扫一扫 畅享免费WiFi");
footByte[footString.Count * + ] = b_next2Line; footByte[footString.Count * + ] = bytes;
footByte[footString.Count * + ] = b_breakPartial;
footByte[footString.Count * + ] = PrinterCmdUtils.open_money(); byte[][] totalByte = new byte[ + newString.Count * + footString.Count * ][]; Array.Copy(headByte, totalByte, headByte.Length);
Array.Copy(contentByte, , totalByte, headByte.Length, contentByte.Length);
Array.Copy(footByte, , totalByte, headByte.Length + contentByte.Length, footByte.Length); return PrinterCmdUtils.byteMerger(totalByte);
}
catch (Exception)
{
Logger.Trace("Head:" + head);
Logger.Trace("Recv:" + recv);
Logger.Trace("Foot:" + foot);
Logger.Trace("url:" + url); throw;
}
}
}
    public class PrinterCmdUtils
{ public const byte ESC = ; // 换码
public const byte FS = ; // 文本分隔符
public const byte GS = ; // 组分隔符
public const byte DLE = ; // 数据连接换码
public const byte EOT = ; // 传输结束
public const byte ENQ = ; // 询问字符
public const byte SP = ; // 空格
public const byte HT = ; // 横向列表
public const byte LF = ; // 打印并换行(水平定位)
public const byte CR = ; // 归位键
public const byte FF = ; // 走纸控制(打印并回到标准模式(在页模式下) )
public const byte CAN = ; // 作废(页模式下取消打印数据 ) /**
* 打印纸一行最大的字节
*/
private const int LINE_BYTE_SIZE = ;
/**
* 分隔符
*/
private const String SEPARATOR = "$";
private static StringBuilder sb = new StringBuilder(); /**
* 打印机初始化
*
* @return
*/
public static byte[] init_printer()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
return result;
} /**
* 打开钱箱
*
* @return
*/
public static byte[] open_money()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
result[] = ;
result[] = ;
return result;
} /**
* 换行
*
* @param lineNum要换几行
* @return
*/
public static byte[] nextLine(int lineNum)
{
byte[] result = new byte[lineNum];
for (int i = ; i < lineNum; i++)
{
result[i] = LF;
} return result;
} /**
* 绘制下划线(1点宽)
*
* @return
*/
public static byte[] underlineWithOneDotWidthOn()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
return result;
} /**
* 绘制下划线(2点宽)
*
* @return
*/
public static byte[] underlineWithTwoDotWidthOn()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
return result;
} /**
* 取消绘制下划线
*
* @return
*/
public static byte[] underlineOff()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
return result;
} /**
* 选择加粗模式
*
* @return
*/
public static byte[] boldOn()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = 0xF;
return result;
} /**
* 取消加粗模式
*
* @return
*/
public static byte[] boldOff()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
return result;
} /**
* 左对齐
*
* @return
*/
public static byte[] alignLeft()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
return result;
} /**
* 居中对齐
*
* @return
*/
public static byte[] alignCenter()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
return result;
} /**
* 右对齐
*
* @return
*/
public static byte[] alignRight()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = ;
return result;
} /**
* 水平方向向右移动col列
*
* @param col
* @return
*/
public static byte[] set_HT_position(byte col)
{
byte[] result = new byte[];
result[] = ESC;
result[] = ;
result[] = col;
result[] = ;
return result;
} /**
* 字体变大为标准的n倍
*
* @param num
* @return
*/
public static byte[] fontSizeSetBig(int num)
{
byte realSize = ;
switch (num)
{
case :
realSize = ;
break;
case :
realSize = ;
break;
case :
realSize = ;
break;
case :
realSize = ;
break;
case :
realSize = ;
break;
case :
realSize = ;
break;
case :
realSize = ;
break;
case :
realSize = ;
break;
}
byte[] result = new byte[];
result[] = ;
result[] = ;
result[] = realSize;
return result;
} /**
* 字体取消倍宽倍高
*
* @return
*/
public static byte[] fontSizeSetSmall()
{
byte[] result = new byte[];
result[] = ESC;
result[] = ; return result;
} /**
* 进纸并全部切割
*
* @return
*/
public static byte[] feedPaperCutAll()
{
byte[] result = new byte[];
result[] = GS;
result[] = ;
result[] = ;
result[] = ;
return result;
} /**
* 进纸并切割(左边留一点不切)
*
* @return
*/
public static byte[] feedPaperCutPartial()
{
byte[] result = new byte[];
result[] = GS;
result[] = ;
result[] = ;
result[] = ;
return result;
} public static byte[] bmpToByte(Bitmap bmp)
{
int h = bmp.Height / + ;
int w = bmp.Width;
byte[][] all = new byte[ + * h + h * w][]; all[] = new byte[] { 0x1B, 0x33, 0x00 }; Color pixelColor;
// ESC * m nL nH 点阵图
byte[] escBmp = new byte[] { 0x1B, 0x2A, 0x21, (byte)(w % ), (byte)(w / ) }; // 每行进行打印
for (int i = ; i < h; i++)
{
all[i * (w + ) + ] = escBmp;
for (int j = ; j < w; j++)
{
byte[] data = new byte[] { 0x00, 0x00, 0x00 };
for (int k = ; k < ; k++)
{
if (((i * ) + k) < bmp.Height)
{
pixelColor = bmp.GetPixel(j, (i * ) + k);
if (pixelColor.R == )
{
data[k / ] += (byte)( >> (k % ));
}
}
}
all[i * (w + ) + j + ] = data;
}
//换行
all[(i + ) * (w + )] = PrinterCmdUtils.nextLine();
}
all[h * (w + ) + ] = PrinterCmdUtils.nextLine();
all[h * (w + ) + ] = PrinterCmdUtils.feedPaperCutAll();
all[h * (w + ) + ] = PrinterCmdUtils.open_money(); return PrinterCmdUtils.byteMerger(all);
} // ------------------------切纸-----------------------------
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2)
{
byte[] byte_3 = new byte[byte_1.Length + byte_2.Length];
System.Array.Copy(byte_1, , byte_3, , byte_1.Length);
System.Array.Copy(byte_2, , byte_3, byte_1.Length, byte_2.Length);
return byte_3;
} public static byte[] byteMerger(byte[][] byteList)
{
int Length = ;
for (int i = ; i < byteList.Length; i++)
{
Length += byteList[i].Length;
}
byte[] result = new byte[Length]; int index = ;
for (int i = ; i < byteList.Length; i++)
{
byte[] nowByte = byteList[i];
for (int k = ; k < byteList[i].Length; k++)
{
result[index] = nowByte[k];
index++;
}
}
return result;
} public static byte[][] byte20Merger(byte[] bytes)
{
int size = bytes.Length / + ;
byte[][] result = new byte[size][];
for (int i = ; i < size; i++)
{
byte[] by = new byte[((i + ) * ) - (i * )];
//从bytes中的第 i * 10 个位置到第 (i + 1) * 10 个位置;
System.Array.Copy(bytes, i * , by, , (i + ) * );
result[i] = by;
}
return result;
}
}
    public class TicketHead
{
private String memberid; //会员号 public String Memberid
{
get { return memberid; }
set { memberid = value; }
}
private String card; //餐牌号 public String Card
{
get { return card; }
set { card = value; }
}
private String shopname; //店名 public String Shopname
{
get { return shopname; }
set { shopname = value; }
}
private String shopaddress; //店地址 public String Shopaddress
{
get { return shopaddress; }
set { shopaddress = value; }
}
private String shoptel; //店电话 public String Shoptel
{
get { return shoptel; }
set { shoptel = value; }
}
private String shopno; //店编号 public String Shopno
{
get { return shopno; }
set { shopno = value; }
}
private String shopuser; //当班人员 public String Shopuser
{
get { return shopuser; }
set { shopuser = value; }
}
private String ordertime; //点单时间 public String Ordertime
{
get { return ordertime; }
set { ordertime = value; }
}
private String url; //网址 public String Url
{
get { return url; }
set { url = value; }
} private string shopbrand; public string Shopbrand
{
get { return shopbrand; }
set { shopbrand = value; }
}
}
    public class Ticket
{
private String id; public String Id
{
get { return id; }
set { id = value; }
}
private String type; public String Type
{
get { return type; }
set { type = value; }
}
private String parentid; public String Parentid
{
get { return parentid; }
set { parentid = value; }
}
private String name; public String Name
{
get { return name; }
set { name = value; }
}
private String num; public String Num
{
get { return num; }
set { num = value; }
}
private String price; public String Price
{
get { return price; }
set { price = value; }
}
private String money; public String Money
{
get { return money; }
set { money = value; }
}
private String rebetmoney; public String Rebetmoney
{
get { return rebetmoney; }
set { rebetmoney = value; }
}
private String rebetName; public String RebetName
{
get { return rebetName; }
set { rebetName = value; }
}
private String rebetid; public String Rebetid
{
get { return rebetid; }
set { rebetid = value; }
}
private String rebetType; public String RebetType
{
get { return rebetType; }
set { rebetType = value; }
}
private String grouptype; public String Grouptype
{
get { return grouptype; }
set { grouptype = value; }
}
private String groupid; public String Groupid
{
get { return groupid; }
set { groupid = value; }
}
private String serialnumber; public String Serialnumber
{
get { return serialnumber; }
set { serialnumber = value; }
} private String addonname; public String AddOnName
{
get { return addonname; }
set { addonname = value; }
} }
    public class TicketFoot
{
private String decAmmBalance; //点餐总额 public String DecAmmBalance
{
get { return decAmmBalance; }
set { decAmmBalance = value; }
}
private String decRebeatBalance; //券内优惠 public String DecRebeatBalance
{
get { return decRebeatBalance; }
set { decRebeatBalance = value; }
}
private String decGroupBuyMoney; //+ public String DecGroupBuyMoney
{
get { return decGroupBuyMoney; }
set { decGroupBuyMoney = value; }
}
private String decPaidBalance; //折后支付 public String DecPaidBalance
{
get { return decPaidBalance; }
set { decPaidBalance = value; }
}
private String decMemberCoupon; //会员优惠 public String DecMemberCoupon
{
get { return decMemberCoupon; }
set { decMemberCoupon = value; }
}
private String decWipeMoney; //抹零优惠 public String DecWipeMoney
{
get { return decWipeMoney; }
set { decWipeMoney = value; }
}
private String wipe; // public String Wipe
{
get { return wipe; }
set { wipe = value; }
}
private String cashmoney; //现金支付 public String Cashmoney
{
get { return cashmoney; }
set { cashmoney = value; }
}
private String bankmoney; //银行卡支付 public String Bankmoney
{
get { return bankmoney; }
set { bankmoney = value; }
}
private String membermoney; //会员支付 public String Membermoney
{
get { return membermoney; }
set { membermoney = value; }
}
private String counts; //餐品数量 public String Counts
{
get { return counts; }
set { counts = value; }
} private String givechange; //找零 public String Givechange
{
get { return givechange; }
set { givechange = value; }
} private string rechMoney;
/// <summary>
/// 充值金额
/// </summary>
public string RechMoney
{
get { return rechMoney; }
set { rechMoney = value; }
}
}
    public class EscCommand
{
ArrayList Command = null; public EscCommand()
{
this.Command = new ArrayList();
} public ArrayList getCommand()
{
return this.Command;
} private void addArrayToCommand(byte[] array)
{
for (int i = ; i < array.Length; i++)
{
this.Command.Add(array[i]);
}
} public void addSelectErrorCorrectionLevelForQRCode(byte n)
{
byte[] command = { , , , , , , , };
command[] = n;
addArrayToCommand(command);
} public void addSelectSizeOfModuleForQRCode(byte n)
{
byte[] command = { , , , , , , , };
command[] = n;
addArrayToCommand(command);
} public void addStoreQRCodeData(String content)
{
byte[] command = { , , , , , , , };
command[] = ((byte)((content.Length + ) % ));
command[] = ((byte)((content.Length + ) / ));
addArrayToCommand(command);
addStrToCommand(content, content.Length);
} private void addStrToCommand(String str, int length)
{
byte[] bs = null;
if (!str.Equals(""))
{
try
{
bs = System.Text.Encoding.GetEncoding("GB2312").GetBytes(str);
}
catch (Exception ex)
{
throw ex;
}
if (length > bs.Length)
{
length = bs.Length;
}
for (int i = ; i < length; i++)
{
this.Command.Add(bs[i]);
}
}
} public void addPrintQRCode()
{
byte[] command = { , , , , , , , };
addArrayToCommand(command);
} public static byte[] toPrimitive(Byte[] array)
{
if (array == null)
{
return null;
}
if (array.Length == )
{
return new byte[]{};
}
byte[] result = new byte[array.Length];
for (int i = ; i < array.Length; i++)
{
result[i] = array[i];
}
return result;
} }
byte[] data = PrintService.jsonParse(str[], recv, str[], str[]);
SendSocketMsg(str[], Convert.ToInt32(str[]), Convert.ToInt32(str[]), data);
上一篇:c#枚举位运算操作


下一篇:Java 8新特性:新语法方法引用和Lambda表达式及全新的Stream API