Exemplo n.º 1
0
        private void btnDrive_Click(object sender, EventArgs e)
        {
            int  velocityLeft = 0, velocityRight = 0;
            Byte velocityLeftLSB = 0, velocityLeftMSB = 0, velocityRightLSB = 0, velocityRightMSB = 0;

            inPacketIndex = 0;

            rtbMonitor.Text = "";

            if (txtVelocity.Text == "")
            {
                txtVelocity.Text = "0";
            }
            if (txtRadius.Text == "")
            {
                txtRadius.Text = "0";
            }

            String strVelocityLeft = txtVelocity.Text;

            velocityLeft = (int)Convert.ToDecimal(strVelocityLeft);
            if (velocityLeft > 500)
            {
                velocityLeft = 500;
            }
            else if (velocityLeft < -500)
            {
                velocityLeft = -500;
            }
            strVelocityLeft  = velocityLeft.ToString();
            txtVelocity.Text = strVelocityLeft;

            String strVelocityRight = txtRadius.Text;

            velocityRight = (int)Convert.ToDecimal(strVelocityRight);
            if (velocityRight > 500)
            {
                velocityRight = 500;
            }
            else if (velocityRight < -500)
            {
                velocityRight = -500;
            }
            strVelocityRight = velocityRight.ToString();
            txtRadius.Text   = strVelocityRight;

            result.integer = (Int16)velocityLeft;
            // result = ConvertToTwosComplement(velocityLeft);

            velocityLeftLSB = result.LSBbyte;
            velocityLeftMSB = result.MSBbyte;

            // result = ConvertToTwosComplement(velocityRight);
            result.integer = (Int16)velocityRight;

            velocityRightLSB = result.LSBbyte;
            velocityRightMSB = result.MSBbyte;

            txtCommand1.Text = velocityLeftMSB.ToString();
            txtCommand2.Text = velocityLeftLSB.ToString();
            txtCommand3.Text = velocityRightMSB.ToString();
            txtCommand4.Text = velocityRightLSB.ToString();

            byte[] arrPacketData = new byte[MAXPACKET];

            arrPacketData[0] = 145;
            arrPacketData[1] = velocityLeftMSB;
            arrPacketData[2] = velocityLeftLSB;
            arrPacketData[3] = velocityRightMSB;
            arrPacketData[4] = velocityRightLSB;

            byte[] arrOutPacket = new byte[MAXPACKET];
            outPacketLength = BuildPacket(0, ref arrPacketData, 5, ref arrOutPacket);

            if (outPacketLength > 0)
            {
                UserPort1.WriteBytesToComPort(arrOutPacket, 0, outPacketLength);
            }
        }
Exemplo n.º 2
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            // rtbMonitor.Text = "";

            Byte[] arrData = new Byte[5];
            arrData[0] = STX;
            arrData[1] = ROOMBA;
            arrData[2] = RESET;
            arrData[3] = 0;
            arrData[4] = ETX;
            UserPort1.WriteBytesToComPort(arrData, 0, 5);
        }