/// <summary> /// 向串口发送指令 /// </summary> /// <param name="id">COM口序号</param> /// <param name="mac">无线终端MAC</param> /// <param name="addr">卡地址</param> /// <param name="func">功能号</param> /// <param name="data">参数数组,高字节在前</param> /// <param name="TimeOut">等待超时的毫秒数</param> public static void SendCMD(int id, short mac, byte addr, byte func, int[] data, int TimeOut) { byte[] cmd = new byte[8 + data.Length * 4]; FUNC.GetBytes(mac, out cmd[0], out cmd[1]); cmd[2] = Convert.ToByte('W'); cmd[3] = Convert.ToByte('A'); cmd[4] = Convert.ToByte('T'); cmd[5] = addr; cmd[6] = func; for (int i = 0; i < data.Length; i++) { byte[] d = FUNC.GetBytes(data[i]); cmd[7 + i * 4] = d[0]; cmd[8 + i * 4] = d[1]; cmd[9 + i * 4] = d[2]; cmd[10 + i * 4] = d[3]; } cmd[cmd.Length - 1] = FUNC.CRC8(cmd, 2, cmd.Length - 3); for (int i = 0; i < cmd.Length; i++) { Debug.Write(cmd[i].ToString("X2") + " "); } SendBytes(id, cmd, TimeOut); }
/// <summary> /// 向串口发送指令 /// </summary> /// <param name="id">COM口序号</param> /// <param name="addr">卡地址</param> /// <param name="func">功能号</param> /// <param name="data">参数,高字节在前</param> /// <param name="TimeOut">等待超时的毫秒数</param> public static void SendCMD(int id, byte addr, byte func, int data, int TimeOut) { byte[] cmd = new byte[10]; byte[] d = FUNC.GetBytes(data); cmd[0] = Convert.ToByte('W'); cmd[1] = Convert.ToByte('A'); cmd[2] = Convert.ToByte('T'); cmd[3] = addr; cmd[4] = func; cmd[5] = d[0]; cmd[6] = d[1]; cmd[7] = d[2]; cmd[8] = d[3]; cmd[9] = FUNC.CRC8(cmd, 0, 9); SendBytes(id, cmd, TimeOut); }
/// <summary> /// 向串口发送指令 /// </summary> /// <param name="id">COM口序号</param> /// <param name="addr">卡地址</param> /// <param name="func">功能号</param> /// <param name="data">参数数组,高字节在前</param> /// <param name="TimeOut">等待超时的毫秒数</param> public static void SendCMD(int id, byte addr, byte func, int[] data, int TimeOut) { byte[] cmd = new byte[6 + data.Length * 4]; cmd[0] = Convert.ToByte('W'); cmd[1] = Convert.ToByte('A'); cmd[2] = Convert.ToByte('T'); cmd[3] = addr; cmd[4] = func; for (int i = 0; i < data.Length; i++) { byte[] d = FUNC.GetBytes(data[i]); cmd[5 + i * 4] = d[0]; cmd[6 + i * 4] = d[1]; cmd[7 + i * 4] = d[2]; cmd[8 + i * 4] = d[3]; } cmd[cmd.Length - 1] = FUNC.CRC8(cmd, 0, cmd.Length - 1); SendBytes(id, cmd, TimeOut); }