1. 程式人生 > >依碼仕噴碼機程式設計指南

依碼仕噴碼機程式設計指南

協議下載地址:https://download.csdn.net/download/horseroll/10766998

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;
}