private byte[] getbyte_GetKey(CmdData cmd) { int nRack = 0, nNode = 0, nVerify = 0; byte[] OutBuff = { 0, 0, 0, 0, 0, 0, 0 }; nRack = cmd.address / 256 + 0x80; nNode = cmd.address % 256; if (nNode == 13) { nNode += 200; } nVerify = 0x40 ^ nRack ^ nNode ^ 0x56; OutBuff[0] = 0x40; OutBuff[1] = (byte)nRack; OutBuff[2] = (byte)nNode; OutBuff[3] = 0x56; OutBuff[4] = (byte)nVerify; OutBuff[5] = 0x2a; OutBuff[6] = 0xd; return(OutBuff); }
private void ExecuteCmd(int address, CmdType cmdType, object data) { CmdData cmddata = new CmdData(); cmddata.address = address + 256 * (base.Com.port - 2); cmddata.cmdType = cmdType; cmddata.data = data; this.Send(cmddata); }
private byte[] getbyte_SendText(CmdData cmd) { IList <byte> byteList = new List <byte>(); int nAddressH = cmd.address / 256 + 0x80; int nAddressL = cmd.address % 256; if (nAddressL == 13) { nAddressL += 200; } byteList.Add(0x40); byteList.Add((byte)nAddressH); byteList.Add((byte)nAddressL); byteList.Add(0x50); int nPosition = 4; string[] aryData; string strData = ""; aryData = (string[])(cmd.data); strData = aryData[0] + aryData[1] + aryData[2] + aryData[3]; byte[] aryByteTemp = Encoding.Default.GetBytes(strData); foreach (byte data in aryByteTemp) { byteList.Add(data); nPosition++; if (nPosition == 100) { break; } } int nVerify = byteList[0]; for (int j = 1; j < 100; j++) { nVerify = nVerify ^ byteList[j]; } byteList.Add((byte)nVerify); byteList.Add(0x2a); byteList.Add(0xd); return(byteList.ToArray()); }
public byte[] Encode(object CMD) { CmdData cmd = (CmdData)CMD; byte[] aryByte = {}; switch (cmd.cmdType) { case CmdType.SendData: aryByte = getbyte_SendText(cmd); break; case CmdType.ResetElectronicLabel: aryByte = getbyte_Reset(cmd); break; case CmdType.ControlPlateID: break; case CmdType.OpenLight: break; case CmdType.CloseLight: break; case CmdType.LoudSpeaker: break; case CmdType.ShowOnly: break; case CmdType.KeyRaisedAck: break; case CmdType.Delete: break; case CmdType.ResetControlPlate: break; case CmdType.GetKey: aryByte = getbyte_GetKey(cmd); break; default: break; } return(aryByte); }
private byte[] getbyte_GetKey(CmdData cmd) { int nRack = 0, nNode = 0, nVerify = 0; byte[] OutBuff = { 0, 0, 0, 0, 0, 0, 0 }; nRack = cmd.address / 256 + 0x80; nNode = cmd.address % 256; if (nNode == 13) nNode += 200; nVerify = 0x40 ^ nRack ^ nNode ^ 0x56; OutBuff[0] = 0x40; OutBuff[1] = (byte)nRack; OutBuff[2] = (byte)nNode; OutBuff[3] = 0x56; OutBuff[4] = (byte)nVerify; OutBuff[5] = 0x2a; OutBuff[6] = 0xd; return OutBuff; }
private byte[] getbyte_SendText(CmdData cmd) { IList<byte> byteList = new List<byte>(); int nAddressH = cmd.address / 256 + 0x80; int nAddressL = cmd.address % 256; if (nAddressL == 13) nAddressL += 200; byteList.Add(0x40); byteList.Add((byte)nAddressH); byteList.Add((byte)nAddressL); byteList.Add(0x50); int nPosition = 4; string[] aryData; string strData = ""; aryData = (string[])(cmd.data); strData = aryData[0] + aryData[1] + aryData[2] + aryData[3]; byte[] aryByteTemp = Encoding.Default.GetBytes(strData); foreach (byte data in aryByteTemp) { byteList.Add(data); nPosition++; if (nPosition == 100) break; } int nVerify = byteList[0]; for (int j = 1; j < 100; j++) { nVerify = nVerify ^ byteList[j]; } byteList.Add((byte)nVerify); byteList.Add( 0x2a); byteList.Add( 0xd); return byteList.ToArray(); }