Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Communication.SetSpeedPacket sendFrame = new Communication.SetSpeedPacket();

            sendFrame.Header = new byte[2] {
                0xAA, 0xFF
            };
            sendFrame.CheckSum     = new byte[2];
            sendFrame.FunctionCode = 0xAC;
            sendFrame.AGVID        = 0x01;
            sendFrame.Kp           = Convert.ToSingle("2.0");
            sendFrame.Ki           = Convert.ToSingle("2.0");
            sendFrame.Kd           = Convert.ToSingle("0.015");
            sendFrame.Velocity     = Convert.ToSingle("15.0");
            // calculate check sum
            //sCRC16_Calculator(sendFrame.ToArrayCRC(), sendFrame.CheckSum);
            //   sendFrame.CheckSum = crc;
            sendFrame.EndOfFrame = new byte[2] {
                0x0A, 0x0D
            };
            if (!Communication.SerialPort.IsOpen)
            {
                return;
            }
            try { Communication.SerialPort.Write(sendFrame.ToArray(), 0, sendFrame.ToArray().Length); }
            catch { };
        }
        public static void sendSpeedFrame()
        {
            Communication.SetSpeedPacket sendFrame = new Communication.SetSpeedPacket();

            sendFrame.Header = new byte[2] {
                0xAA, 0xFF
            };
            sendFrame.CheckSum     = new byte[2];
            sendFrame.FunctionCode = 0xAC;
            sendFrame.AGVID        = 0x01;
            sendFrame.Kp           = Convert.ToSingle("2.0");
            sendFrame.Ki           = Convert.ToSingle("2.0");
            sendFrame.Kd           = Convert.ToSingle("0.015");
            sendFrame.Velocity     = Convert.ToSingle("15.0");
            sendFrame.CheckSum     = new byte[2];
            // calculate check sum
            CRC16_Calculator(sendFrame.ToArrayCRC(), sendFrame.CheckSum);
            //   sendFrame.CheckSum = crc;
            sendFrame.EndOfFrame = new byte[2] {
                0x0A, 0x0D
            };
            if (!Communication.SerialPort.IsOpen)
            {
                return;
            }
            try { Communication.SerialPort.Write(sendFrame.ToArray(), 0, sendFrame.ToArray().Length); }
            catch { };
            if (timerToSendSpeedAgain.Enabled == false)
            {
                timerToSendSpeedAgain.Start();
            }
        }