示例#1
0
        public byte[] Integration(byte[] datacontent)
        {
            List <byte> bylist = new List <byte>();

            bylist.Add((byte)Head);
            bylist.Add((byte)FunctionAddress);
            bylist.AddRange(HexadecimalConversion.IntToAscii(DeviceAddress));
            bylist.AddRange(HexadecimalConversion.IntToAscii(Command));
            if (datacontent != null)
            {
                bylist.AddRange(datacontent);
            }
            int xor = DataValidation.Xor(bylist);

            bylist.AddRange(HexadecimalConversion.IntToAscii(xor));
            bylist.Add((byte)End);
            return(bylist.ToArray());
        }
示例#2
0
        /// <summary>
        /// 加载无线端口
        /// </summary>
        public static void LoadPort()
        {
            _dataValidation = new DataValidation()
            {
                IsProtocol   = true,
                ProtocolHead = 2,
                ProtocolEnd  = 3,
                IsValidation = true
            };

            sp = new SerialPortEx()
            {
                BaudRate = WinApi.B19200,
                DataBit  = WinApi.BIT_8,
                StopBit  = WinApi.STOP_1,
                Parity   = WinApi.p_NONE
            };
            sp.DataReceived += SerialPortDataReceived;
            sp.PortChange   += SerialPortChange;
            sp.Start();

            SetAutoDevice(true);
        }