Beispiel #1
0
        private void sendAck()
        {
            sendDataitem sendFrame = new sendDataitem();

            sendFrame.Type       = (byte)(LKSensorCmd.FRAME_TYPE.ACK);
            sendFrame.id         = (byte)(LKSensorCmd.FRAME_AckID.downLoadBegin);
            sendFrame.ifHeadOnly = true;  //含有数据帧
            serial.SendMsg(sendFrame);
        }
Beispiel #2
0
        private void sendPakagedFrame(byte[] buff, byte id)
        {
            sendDataitem sendFrame = new sendDataitem();

            sendFrame.Type       = (byte)(LKSensorCmd.FRAME_TYPE.Upload);
            sendFrame.id         = id;
            sendFrame.ifHeadOnly = false;               //含有数据帧
            sendFrame.sendbuf    = buff;
            sendFrame.len        = (UInt16)buff.Length; //数据帧字节长度
            serial.SendMsg(sendFrame);
        }
 public void SendMsg(sendDataitem sendMsg)
 {
     if (check())
     {
         object lockThis = LockThis;
         lock (lockThis)
         {
             sendMsg.sendFrame = lk_sendHandle.sendFrame_compend(sendMsg);
             int send_lens = sendMsg.sendFrame.Length;
             zSerPort.Write(sendMsg.sendFrame, 0, send_lens);
         }
     }
 }
Beispiel #4
0
        public byte[] sendFrame_compend(sendDataitem sendMsg)
        {
            id = sendMsg.isRsponse ? sendMsg.id : getNextID();
            //add listener
            sendBuf.Enqueue(sofbyte);
            sendBuf.Enqueue(id);
            sendBuf.Enqueue((byte)(sendMsg.len >> 8));
            sendBuf.Enqueue((byte)(sendMsg.len));
            sendBuf.Enqueue(sendMsg.Type);
            sendChecksum.crcReset();
            UInt16 head_crc = sendChecksum.crc16(sendBuf.ToArray());
            byte   high_crc = (byte)(head_crc >> 8);
            byte   low_crc  = (byte)head_crc;

            sendBuf.Enqueue(high_crc);
            sendBuf.Enqueue(low_crc);
            if (!sendMsg.ifHeadOnly)
            {
                byte[] data = new byte[sendMsg.len];
                for (int i = 0; i < sendMsg.len; i++)
                {
                    data[i] = sendMsg.sendbuf[i];
                    sendBuf.Enqueue(sendMsg.sendbuf[i]);
                }
                sendChecksum.crcReset();
                UInt16 data_crc      = sendChecksum.crc16(data);
                byte   high_data_crc = (byte)(data_crc >> 8);
                byte   low_data_crc  = (byte)data_crc;

                sendBuf.Enqueue(high_data_crc);
                sendBuf.Enqueue(low_data_crc);
            }
            else
            {
                sendMsg.len = 0;
            }
            byte[] re_buf = sendBuf.ToArray();
            sendBuf.Clear();
            return(re_buf);
        }