本文共 1739 字,大约阅读时间需要 5 分钟。
协议下载地址:
1.首先与依码仕喷码机通过RS232进行通讯连接
2.准备打印,发送字节05
3.打印机返回字节06,发送E9H指令,new Byte[] { 0xE9, 0x00, 0x01, 0x01, 0xE9 }
4.打印机返回字节06,发送字节05
5.打印机返回字节06,发送D8H指令,new Byte[] { 0xD8, 0x00, 0x00, 0xD8 }
6.打印机返回字节06,发送字节05
7.打印机返回字节06,发送E3H指令,即发送数据,具体方法见下方sendMe()方法
8.打印机返回字节06,说明打印机已经接收到信号,等待打印
8.打印机打印完成,返回字节06,发送字节06
9.打印机返回字节06,发送字节06,发送字节05
10.打印机返回字节06,发送E3H,从步骤7开始循环
SendMe方法(我这边是打印16位长度的的数字,不同长度字节内容也不一样,看协议修改)
public void sendMe(){ SerialOutput = new Byte[]{ 227,0,41,192,0,0,0,0,1,0,3,0,3,0,2,0,100,0,0,10, 128,1,13,1,16,30,1,30,18, 49,50,51,52,53,54,56,48, 49,50,51,52,53,54,56,48, 18,16,1,13,128,1,13 }; SerialOutput[2] = 33 + 16; Byte[] strbyte = new Byte[16]; int z = 0; strbyte = System.Text.Encoding.Default.GetBytes("0000000000000001"); for (int i = 29; i < 45; i++)//16位的字节更换 { SerialOutput[i] = strbyte[z]; z++; } byte checksum = CheckSum(SerialOutput); Byte[] serial = new Byte[SerialOutput.Length + 1]; for (int i = 0; i < serial.Length - 1; i++) { serial[i] = SerialOutput[i]; } serial[serial.Length - 1] = checksum; comm.WritePort(serial, 0, serial.Length); ToolData.WriteLog(richTextBox1, CameraList[ListNumber] + " 等待打印", 1);}//字节计数public static byte CheckSum(Byte[] bytes){ byte checksum = 0; foreach (byte b in bytes) { checksum ^= b; } return checksum;}
也可以把E3H指令换成99H指令
两者区别:E3H是固定了字体以及速度这些,而99H只是传输外部变量,具体的字体大小字型这些全部是在喷码机上设置
更新外部变量内容 指令99: 99 00 0A 12 31 36 35 31 46 36 32 30 12 E2 指令详述: i) 99:命令字 ii) 00 0A:长度 iii) 12 31 36 35 31 46 36 32 30 12 : 起始12,末尾12:为格式字节 31 36 35 31 46 36 32 30 :喷印内容1651F620 iv) E2:校验码
转载地址:http://ouulf.baihongyu.com/