示例#1
0
 private void scanning(object sender, DoWorkEventArgs e)
 {
     for (int opakuj = 0; opakuj < 10; opakuj++)
     {
         for (int poc_com = 0; poc_com < 20; poc_com++)
         {
             if (Isobot_com.IsOpen == true)
             {
                 Isobot_com.Close();
             }
             Isobot_com.PortName = "COM" + poc_com.ToString();
             try
             {
                 Isobot_com.Open();
                 System.Threading.Thread.Sleep(200);
                 Isobot_com.Write("A");
                 Isobot_com.ReadTimeout = 500;
                 if (Isobot_com.ReadByte() == 5)
                 {
                     MessageBox.Show("Connection established");
                     poc_com = 21;
                     opakuj  = 11;
                 }
             }
             catch { }
         }
     }
     if (Isobot_com.IsOpen == false)
     {
         MessageBox.Show("Connection has not been established");
     }
 }
示例#2
0
 void Send_onlycommand(string command)
 {
     try
     {
         byte[] pomocny = new byte[1];
         pomocny[0] = Convert.ToByte(command);
         Isobot_com.Write(pomocny, 0, 1);
     }
     catch
     {
         MessageBox.Show("Connection has not been established");
     }
 }
示例#3
0
 void Send_command(string command, string[] parameter)
 {
     try
     {
         byte[] pomocny = new byte[1];
         pomocny[0] = Convert.ToByte(command);
         Isobot_com.WriteTimeout = 100;
         Isobot_com.Write(pomocny, 0, 1);
         System.Threading.Thread.Sleep(2);
         //-----------------------------------------------
         for (int p = 0; p < parameter.Length; p++)
         {
             pomocny[0] = Convert.ToByte(parameter[p]);
             Isobot_com.Write(pomocny, 0, 1);
             System.Threading.Thread.Sleep(2);
         }
     }
     catch
     {
         MessageBox.Show("Connection has not been established");
     }
 }
示例#4
0
 private void ADC_refresh_Tick(object sender, EventArgs e)
 {
     if (Isobot_com.IsOpen == true)
     {
         if (ADC0_radiobutton.Checked == true)
         {
             Send_onlycommand("5");
             try
             {
                 ADC0_box.Text          = Isobot_com.ReadByte().ToString();
                 ADC0_progressbar.Value = Convert.ToInt16(ADC0_box.Text);
             }
             catch
             {
                 ADC_refresh.Enabled = false;
                 ADC_ON_OFF.Checked  = false;
                 MessageBox.Show("Connection lost");
             }
         }
         else if (ADC1_radiobutton.Checked == true)
         {
             Send_onlycommand("6");
             try
             {
                 ADC1_box.Text          = Isobot_com.ReadByte().ToString();
                 ADC1_progressbar.Value = Convert.ToInt16(ADC1_box.Text);
             }
             catch
             {
                 ADC_refresh.Enabled = false;
                 ADC_ON_OFF.Checked  = false;
                 MessageBox.Show("Connection lost");
             }
         }
         else if (ADC2_radiobutton.Checked == true)
         {
             Send_onlycommand("7");
             try
             {
                 ADC2_box.Text          = Isobot_com.ReadByte().ToString();
                 ADC2_progressbar.Value = Convert.ToInt16(ADC2_box.Text);
             }
             catch
             {
                 ADC_refresh.Enabled = false;
                 ADC_ON_OFF.Checked  = false;
                 MessageBox.Show("Connection lost");
             }
         }
         else if (ADC3_radiobutton.Checked == true)
         {
             Send_onlycommand("8");
             try
             {
                 ADC3_box.Text          = Isobot_com.ReadByte().ToString();
                 ADC3_progressbar.Value = Convert.ToInt16(ADC3_box.Text);
             }
             catch
             {
                 ADC_refresh.Enabled = false;
                 ADC_ON_OFF.Checked  = false;
                 MessageBox.Show("Connection lost");
             }
         }
         else if (ADC4_radiobutton.Checked == true)
         {
             Send_onlycommand("9");
             try
             {
                 ADC4_box.Text          = Isobot_com.ReadByte().ToString();
                 ADC4_progressbar.Value = Convert.ToInt16(ADC4_box.Text);
             }
             catch
             {
                 ADC_refresh.Enabled = false;
                 ADC_ON_OFF.Checked  = false;
                 MessageBox.Show("Connection lost");
             }
         }
         else
         {
             Send_onlycommand("10");
             try
             {
                 ADC5_box.Text          = Isobot_com.ReadByte().ToString();
                 ADC5_progressbar.Value = Convert.ToInt16(ADC5_box.Text);
             }
             catch {
                 ADC_refresh.Enabled = false;
                 ADC_ON_OFF.Checked  = false;
                 MessageBox.Show("Connection lost");
             }
         }
     }
 }
示例#5
0
 private void GPIO_refresh_Tick(object sender, EventArgs e)
 {
     if (Isobot_com.IsOpen == true)
     {
         Send_onlycommand("11");
         try
         {
             int PINC = Isobot_com.ReadByte();
             if ((PINC & 0x20) == 0x20)
             {
                 PINC5.Checked = true;
             }
             else
             {
                 PINC5.Checked = false;
             }
             if ((PINC & 0x10) == 0x10)
             {
                 PINC4.Checked = true;
             }
             else
             {
                 PINC4.Checked = false;
             }
             if ((PINC & 0x08) == 0x08)
             {
                 PINC3.Checked = true;
             }
             else
             {
                 PINC3.Checked = false;
             }
             if ((PINC & 0x04) == 0x04)
             {
                 PINC2.Checked = true;
             }
             else
             {
                 PINC2.Checked = false;
             }
             if ((PINC & 0x02) == 0x02)
             {
                 PINC1.Checked = true;
             }
             else
             {
                 PINC1.Checked = false;
             }
             if ((PINC & 0x01) == 0x01)
             {
                 PINC0.Checked = true;
             }
             else
             {
                 PINC0.Checked = false;
             }
         }
         catch {}
         Send_onlycommand("4");
         try{
             int PINB = Isobot_com.ReadByte();
             if ((PINB & 0x20) == 0x20)
             {
                 PINB5.Checked = true;
             }
             else
             {
                 PINB5.Checked = false;
             }
             if ((PINB & 0x10) == 0x10)
             {
                 PINB4.Checked = true;
             }
             else
             {
                 PINB4.Checked = false;
             }
             if ((PINB & 0x08) == 0x08)
             {
                 PINB3.Checked = true;
             }
             else
             {
                 PINB3.Checked = false;
             }
             if ((PINB & 0x04) == 0x04)
             {
                 PINB2.Checked = true;
             }
             else
             {
                 PINB2.Checked = false;
             }
             if ((PINB & 0x02) == 0x02)
             {
                 PINB1.Checked = true;
             }
             else
             {
                 PINB1.Checked = false;
             }
             if ((PINB & 0x01) == 0x01)
             {
                 PINB0.Checked = true;
             }
             else
             {
                 PINB0.Checked = false;
             }
         }
         catch {
             GPIO_refresh.Enabled = false;
             GPIO_ON_OFF.Checked  = false;
             MessageBox.Show("Connection lost");
         }
     }
 }