新聞速報

        

2025年2月12日 星期三

EPSON 微型印表機 低階控制

 EPSON 微型印表機  低階控制

採用 UDP : 3289

ENPC (UDP)

3289

指令格式為  15 Bytes

        out = ["EPSON",
                "Q",                    # PacketType (Q for query and C for command)
                "\x03",                # DeviceType(3) (fixed)
                "\x00",                # DeviceNumber(0) (fixed)
                "\x00\x10",         # Function(0010h)
                "\x00\x00",         # Result (fixed?)
                "\x00\x00",         # parameter length Length
                ""                       # command parameter
                ]


LanCard  ReSet



using System;
using System.Text;

 

class EpsonNetParser
{
    public static void Parse(byte[] buffer)
    {
        if (buffer.Length < 14) // 最小封包長度
        {
            Console.WriteLine("封包長度不足");
            return;
        }
 
        Console.WriteLine("EpsonNet Protocol Data:"); 
        // 取前 5 個字節作為 EPSON Header
        Console.WriteLine($"EPSON Header: {BitConverter.ToString(buffer, 0, 5)}");
 
        // 取得 Type(查詢/命令)
        char typeChar = (char)buffer[5];
        string ctype = char.IsLower(typeChar) ? "Reply" : "";
        string typeDescription = typeChar switch
        {
            'q' => "Query",
            'c' => "Command",
            's' => "_S_omething else",
            _ => $"Unknown Type ({typeChar})"
        };
        Console.WriteLine($"Type: {typeDescription} {ctype}");
 
        // 設備類型與設備編號
        Console.WriteLine($"Device Type: {buffer[6]}");
        Console.WriteLine($"Device Number: {buffer[7]}");
 
        // 解析 Function Number
        int functionNumber = BitConverter.ToUInt16(buffer, 8);
        string functionDescription = functionNumber switch
        {
            0x0000 => "Basic Information",
            0x0010 => "Status",
            0x0011 => "Forced Transmission",
            0x0012 => "Reset",
            0x0013 => "Buffer Flash",
            0x0016 => "Clearing Connection Timeout Timer",
            _ => "Unknown Function"
        };
        Console.WriteLine($"Function Number: {functionNumber} ({functionDescription})");
 
        // 結果代碼
        int resultCode = BitConverter.ToUInt16(buffer, 10);
        if (ctype == "")
        {
            Console.WriteLine($"(Fixed Value 0x0000) {resultCode}");
        }
        else
        {
            string resultDescription = resultCode switch
            {
                0x0000 => "Normal end",
                0xFFFE => "No device requested",
                0xFFFF => "Function not supported",
                _ => "Unknown result code"
            };
            Console.WriteLine($"Result Code: {resultCode} ({resultDescription})");
        }
 
        // 命令長度
        int commandLength = BitConverter.ToUInt16(buffer, 12);
        Console.WriteLine($"Command Length: {commandLength}");
 
        if (commandLength > 0 && buffer.Length >= 14 + commandLength)
        {
            string commandData = Encoding.ASCII.GetString(buffer, 14, commandLength);
            string dataType = ctype == "" ? "Command" : "Reply Data";
            Console.WriteLine($"{dataType}: {commandData}");
        }
    }
}

 

// 測試
class Program
{
    static void Main()
    {
        byte[] testPacket = new byte[]
        {
            0x45, 0x50, 0x53, 0x4E, 0x00, // EPSON Header
            0x71, // 'q' (Query)
            0x01, // Device Type
            0x02, // Device Number
            0x00, 0x10, // Function Number (0x10 = Status)
            0x00, 0x00, // Result Code (0x0000 = Normal)
            0x00, 0x05, // Command Length (5 bytes)
            0x48, 0x65, 0x6C, 0x6C, 0x6F // "Hello"
        };
        EpsonNetParser.Parse(testPacket);
    }
}

 

沒有留言:

張貼留言