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# 网络打印机ESC指令打印小票的更多相关文章
- 【转】C#使用ESC指令控制POS打印机打印小票
.前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的pos ...
- C#使用ESC指令控制POS打印机打印小票
1.前言 C#打印小票可以与普通打印机一样,调用PrintDocument实现.也可以发送标注你的ESC指令实现.由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的po ...
- C# EPL USB 指令打印
private void btnPrinter_Click(object sender, EventArgs e) { #region ESC 热敏图像点阵像素点读取打印 //Bitmap bitma ...
- usb口打印机的指令打印和驱动打印
打印机简介:是计算机的输出设备之一,用于将计算机处理结果打印在相关介质上. 打印机类型:激光打印机.喷墨打印机.针式打印机.热敏打印机等. 计算机和打印机之间的连接方式:usb口.串口.并口.网口.蓝 ...
- ActiveXObject Word.Application 打印小票
javascript 时间格式 Date.prototype.format = function (format) { var o = { "M+": this.getMonth( ...
- C# 打印小票 POS
C# 打印小票 POS 最近在写一个餐饮的收银系统,以前从来没有碰过打印机这玩意.感觉有些无从下手,在前面做报表时,总想找第三方的控件来用用,结果始终不行没搞定.没研究透,催得急没办法还是的动手自己写 ...
- ESC/POS打印控制命令
0x00. Command Notation [Name] The name of the command. [Format] ...
- C# 收银机顾显(客显)及打印小票(58热敏打印机)
最近做winform收银机,设计顾显及打印小票总结. 1.顾显(串口COM1) 只涉及到总计,所以只是简单的功能. public static ClientDisplayResult Display( ...
- 按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式
按照已有的模板打印小票<二> ——调用windows打印机打印 可设置字体样式 之前写过一篇文章<按照已有的模板输出一(如发票)>,是关于如何给已有的模板赋值.在项目的实践过程 ...
随机推荐
- [Codeforces 23D] Tetragon
Brief Intro: 给3条相同长度的边的中点,问是否存在一个严格凸四边形 Algorithm: 明显只要求出一个点就能利用对称性算出其他点的坐标 设中点K,L,M分别在边AB,BC,CD上,易知 ...
- 【矩阵乘法】bzoj2326 [HNOI2011]数学作业
http://hzwer.com/2831.html #include<cstdio> #include<iostream> #include<vector> us ...
- 【最小割】【Dinic】【强联通分量缩点】bzoj1797 [Ahoi2009]Mincut 最小割
结论: 满足条件一:当一条边的起点和终点不在 残量网络的 一个强联通分量中.且满流. 满足条件二:当一条边的起点和终点分别在 S 和 T 的强联通分量中.且满流.. 网上题解很多的. #include ...
- [TC-HouseProtection]House Protection
题目大意: 一个平面直角坐标系中有给定的$n(n\le50)$个红点和$m(m\le50)$个蓝点,每个点可以选择画一个半径为$r$(所有的$r$相同)的圆或不画.圆的半径上限为$R(R\le1000 ...
- openresty的ngx.timer.at
openresty的ngx.timer.at真是个强大的方法. 例如某些函数不可以在一些NGINX的执行阶段使用时,可以ngx.timer.at API 创建一个零延迟的timer,在timer中去处 ...
- 输入输出流和String的混合使用-替换信息
---恢复内容开始--- package demo; import java.io.BufferedReader; import java.io.BufferedWriter; import java ...
- cocos2d 文件系统使用文件内存映射性能对比
//cocos 修改代码 ..... //性能测试代码 extern "C" { #include <time.h> #include <stdlib.h> ...
- Problem O: 零起点学算法10——求圆柱体的表面积
#include<stdio.h> int main() { float r,h,pi; pi=3.1415926; scanf("%f %f",&r,& ...
- Scala实战高手****第9课:Scala类和对象彻底实战和Spark源码鉴赏
scala类和对象 RDD中创建_sc和deps相比java更加的简洁. 在Spark的例如SparkContext.sqlSpark等全局成员在完成实例化. 在唯一实例的时候一般不会去使用伴生对象a ...
- Oracle RAC 环境下的 v$log v$logfile
通常情况下,在Oracle RAC 环境中,v$视图可查询到你所连接实例的相关信息,而gv$视图则包含所有实例的信息.然而在RAC环境中,当我们查询v$log视图时说按照常理的话,v$log视图应当看 ...