コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
                serialPort1.Close();
            if (!PortSet() || !PortExists())
            {
                COMPortDialog p = new COMPortDialog();
                p.ShowDialog();
                if (!Properties.Settings.Default.DialogResult)
                {
                    return;
                }
            }
            if (Properties.Settings.Default.COM_Port_Name != "None")
            {
                serialPort1.PortName = Properties.Settings.Default.COM_Port_Name;
                serialPort1.BaudRate = 115200;
                serialPort1.Open();

                byte[] d = { 48 };
                serialPort1.Write(d, 0, 1);

                serialPort1.DataReceived += serialPort1_DataReceived;
                this.StillListening = true;
                DrawRadarDisplay(pictureBox1.CreateGraphics(), pictureBox1);
            }
            else
                MessageBox.Show("Nije izabran COM port.\nIzaberite COM port i pokusajte ponovo.", "Greska!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
            }
            if (!PortSet() || !PortExists())
            {
                COMPortDialog p = new COMPortDialog();
                p.ShowDialog();
                if (!Properties.Settings.Default.DialogResult)
                {
                    return;
                }
            }
            if (Properties.Settings.Default.COM_Port_Name != "None")
            {
                serialPort1.PortName = Properties.Settings.Default.COM_Port_Name;
                serialPort1.BaudRate = 115200;
                serialPort1.Open();

                byte[] d = { 48 };
                serialPort1.Write(d, 0, 1);

                serialPort1.DataReceived += serialPort1_DataReceived;
                this.StillListening       = true;
                DrawRadarDisplay(pictureBox1.CreateGraphics(), pictureBox1);
            }
            else
            {
                MessageBox.Show("Nije izabran COM port.\nIzaberite COM port i pokusajte ponovo.", "Greska!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #3
0
        private void SwitchButton_Click(object sender, EventArgs e)
        {
            if (Switched)
            {
                SwitchButton.Image  = Properties.Resources.SwitchOn;
                this.StillListening = false;
                if (serialPort1.IsOpen)
                {
                    byte[] d = { 49 };
                    serialPort1.Write(d, 0, 1);
                    serialPort1.Close();
                }
                distance = 0;
                position = 0;
                for (int i = -90; i < 90; i += RadarInc)
                {
                    radar_data[i] = 1;
                }
                pictureBox1.Invalidate();
            }
            else
            {
                if (serialPort1.IsOpen)
                {
                    serialPort1.Close();
                }
                if (!PortSet() || !PortExists())
                {
                    COMPortDialog p = new COMPortDialog();
                    p.ShowDialog();
                    if (!Properties.Settings.Default.DialogResult)
                    {
                        return;
                    }
                }
                if (Properties.Settings.Default.COM_Port_Name != "None")
                {
                    serialPort1.PortName = Properties.Settings.Default.COM_Port_Name;
                    serialPort1.BaudRate = 115200;
                    serialPort1.Open();

                    byte[] d = { 48 };
                    serialPort1.Write(d, 0, 1);

                    serialPort1.DataReceived += serialPort1_DataReceived;
                    this.StillListening       = true;
                    SwitchButton.Image        = Properties.Resources.SwitchOff;
                }
                else
                {
                    MessageBox.Show("Nije izabran COM port.\nIzaberite COM port i pokusajte ponovo.", "Greska!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            Switched = !Switched;
        }
コード例 #4
0
        private void SwitchButton_Click(object sender, EventArgs e)
        {
            if (Switched)
            {
                SwitchButton.Image = Properties.Resources.SwitchOn;
                this.StillListening = false;
                if (serialPort1.IsOpen)
                {
                    byte[] d = { 49 };
                    serialPort1.Write(d, 0, 1);
                    serialPort1.Close();
                }
                distance = 0;
                position = 0;
                for (int i = -90; i < 90; i += RadarInc)
                {
                    radar_data[i] = 1;
                }
                pictureBox1.Invalidate();
            }
            else
            {
                if (serialPort1.IsOpen)
                    serialPort1.Close();
                if (!PortSet() || !PortExists())
                {
                    COMPortDialog p = new COMPortDialog();
                    p.ShowDialog();
                    if (!Properties.Settings.Default.DialogResult)
                    {
                        return;
                    }
                }
                if (Properties.Settings.Default.COM_Port_Name != "None")
                {
                    serialPort1.PortName = Properties.Settings.Default.COM_Port_Name;
                    serialPort1.BaudRate = 115200;
                    serialPort1.Open();

                    byte[] d = { 48 };
                    serialPort1.Write(d, 0, 1);

                    serialPort1.DataReceived += serialPort1_DataReceived;
                    this.StillListening = true;
                    SwitchButton.Image = Properties.Resources.SwitchOff;
                }
                else
                    MessageBox.Show("Nije izabran COM port.\nIzaberite COM port i pokusajte ponovo.", "Greska!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            Switched = !Switched;
        }