Example #1
0
        private async void SendALineFromTextFileEverySecond()
        {
            string         filepath       = String.Empty;
            String         fileExt        = String.Empty;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                filepath = openFileDialog.FileName;
                fileExt  = Path.GetExtension(filepath);
                Console.WriteLine(filepath + " " + fileExt);
                try
                {
                    StreamReader reader = new StreamReader(filepath);

                    string line = "";
                    while ((line = reader.ReadLine()) != null && ComboBox1.GetItemText(ComboBox1.SelectedItem) == "Text File")
                    {
                        rxString = line + "\n";
                        this.Invoke(new EventHandler(UpdateWidgets));
                        await Task.Delay(1000);
                    }
                    DataStream.AppendText("EOF");
                    reader.Close();
                }
                catch (Exception ex) {
                    Console.WriteLine(ex);
                }
            }
        }
Example #2
0
File: Form1.cs Project: IlyaBOT/AMC
        private void connectToArduino()                                          // Connect function
        {
            isConnected = true;                                                  // Переменную подключения ставим равной true.
            string selectedPort = ComboBox1.GetItemText(ComboBox1.SelectedItem); // Ставим значние переменной selectedPort равной выбранному COM-порту.

            SerialPort1.PortName = selectedPort;                                 // Устанавливаем выбранный COM-порт.
            SerialPort1.Open();                                                  // Подключаемся к выбранному COM-порту.
            Button4.Text = "Disconnect";                                         // Надпись на кнопке подключения ставим: Disconnect (Отключиться).
            toolStripStatusLabel2.Text = "Connected";                            // В статус баре пишем: Connected (Подключено).
            toolStripStatusLabel5.Text = SerialPort1.PortName;                   // Пишем в статус бар номер подключенного порта.
        }
Example #3
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs _)
        {
            string dropdownText = ComboBox1.GetItemText(ComboBox1.SelectedItem);

            if (dropdownText == "Text File")
            {
                SendALineFromTextFileEverySecond();
            }
            else
            {
                tryToConnectToCOM(dropdownText);
            }
        }
    //BUTTON FOR SHOWING TABELS IN DATAGRIDVIEW
    private void ShowTbl_Click(object sender, EventArgs e)
    {
        string        selected   = this.ComboBox1.GetItemText(this.ComboBox1.SelectedItem);
        string        DBselected = this.comboBox2.GetItemText(this.comboBox2.SelectedItem);
        SqlConnection con        = new SqlConnection(@"Data Source=SERVER_NAME;Initial Catalog =" + DBselected + "; User ID=USER;Password=PASS;");

        sda = new SqlDataAdapter(@"SELECT *  FROM dbo.[" + selected + "]", con);
        dt  = new DataTable();
        sda.Fill(dt);
        dataGridView1.DataSource = dt;
        string ComboBoxSelected = ComboBox1.GetItemText(ComboBox1.SelectedItem);

        con.Close();
    }
Example #5
0
        private async void ComPortConnetionRenewer()
        {
            while (true)
            {
                await Task.Delay(1000);

                if ((SerialPort1 == null || !SerialPort1.IsOpen) &&
                    ComboBox1.GetItemText(ComboBox1.SelectedItem) != "" &&
                    ComboBox1.GetItemText(ComboBox1.SelectedItem) != "Text File")
                {
                    string dropdownText = ComboBox1.GetItemText(ComboBox1.SelectedItem);
                    DataStream.AppendText("Connecting to " + dropdownText + "\n");
                    tryToConnectToCOM(dropdownText);
                }
            }
        }