コード例 #1
0
        private void metroTextButton1_Click(object sender, EventArgs e)
        {
            //Database.DBStat stat = Database.DBStat.GetDataById(1);

            //if (stat.STAT != "okla") {
            //    MessageBox.Show("Error in loading the system, please contact the administrator!");
            //    Environment.Exit(0);
            //}

            if (metroComboBox1.SelectedIndex > -1 && metroComboBox2.SelectedIndex > -1)
            {
                //port = SimPortsConnection.OpenPort(metroComboBox1.SelectedItem.ToString());

                comm = new GsmCommMain(metroComboBox1.SelectedItem.ToString(), 115200, 300);

                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    comm.Open();

                    if (chkReceived.Checked == true)
                    {
                        comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);
                        comm.EnableMessageNotifications();
                    }
                    metroTextButton1.Enabled ^= true;
                    metroTextButton2.Enabled ^= true;
                    metroComboBox1.Enabled   ^= true;
                    metroComboBox2.Enabled   ^= true;
                    selectedNetwork           = metroComboBox2.SelectedItem.ToString();
                    limit  = int.Parse(txtLimit.Text);
                    thread = new Thread(Process);
                    thread.Start();
                    thread2 = new Thread(TransactProcess);
                    thread2.Start();
                    richTextBox1.Text += "Ok. Ready...\n";

                    Cursor.Current = Cursors.Default;
                }
                catch (Exception ex)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Error opening port! " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("No Port / Network selected");
            }
        }
コード例 #2
0
 private void chkReceived_CheckedChanged(object sender, EventArgs e)
 {
     if (comm != null && comm.IsOpen() == true)
     {
         if (chkReceived.Checked == true)
         {
             comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);
             comm.EnableMessageNotifications();
         }
         else
         {
             comm.DisableMessageNotifications();
         }
     }
 }
コード例 #3
0
        private void CheckConnection()
        {
            comm = new GsmCommMain(Comm_Port, Comm_BaudRate, Comm_TimeOut);

            comm.Open();
            if (comm.IsConnected())
            {
                ConnectionStatusMenuItem.Text = "Connected";
            }
            else
            {
                ConnectionStatusMenuItem.Text = "Not Connected";
            }

            comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);
            comm.EnableMessageNotifications();
        }
コード例 #4
0
        private void metroTextButton1_Click(object sender, EventArgs e)
        {
            //SimPortsConnection = new SimPortsConnection();
            //SMSCommands = new SMSCommands();
            //port = new SerialPort();

            if (metroComboBox1.SelectedIndex > -1)
            {
                //port = SimPortsConnection.OpenPort(metroComboBox1.SelectedItem.ToString());
                comm = new GsmCommMain(metroComboBox1.SelectedItem.ToString(), 115200, 200);
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    comm.Open();
                    comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);
                    comm.EnableMessageNotifications();

                    Cursor.Current            = Cursors.Default;
                    metroTextButton1.Enabled ^= true;
                    metroTextButton2.Enabled ^= true;
                    metroComboBox1.Enabled   ^= true;
                    Read_message();
                    thread = new Thread(Process);
                    thread.Start();
                    richTextBox1.Text += "Receiving...\n";
                }
                catch
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("not available");
                }
            }
            else
            {
                MessageBox.Show("No port selected");
            }
        }
コード例 #5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // Prompt user for connection settings
            string portName = "COM12";
            int    baudRate = GsmCommMain.DefaultBaudRate;
            int    timeout  = GsmCommMain.DefaultTimeout;

            frmConnection dlg = new frmConnection();

            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.SetData(portName, baudRate, timeout);
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                dlg.GetData(out portName, out baudRate, out timeout);
            }
            else
            {
                Close();
                return;
            }

            Cursor.Current          = Cursors.WaitCursor;
            comm                    = new GsmCommMain(portName, baudRate, timeout);
            Cursor.Current          = Cursors.Default;
            comm.PhoneConnected    += new EventHandler(comm_PhoneConnected);
            comm.PhoneDisconnected += new EventHandler(comm_PhoneDisconnected);
            comm.MessageReceived   += new MessageReceivedEventHandler(comm_MessageReceived);

            bool retry;

            do
            {
                retry = false;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    comm.Open();
                    Cursor.Current = Cursors.Default;
                    Output("Соединение", portName);

                    try
                    {
                        comm.DeleteMessages(DeleteScope.All, PhoneStorageType.Sim);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(this, "Не вставлена сим-карта. Вставьте сим-карту и запустите программу снова.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Close();
                        return;
                    }
                }
                catch (Exception)
                {
                    Cursor.Current = Cursors.Default;

                    if (MessageBox.Show(this, "Не получаеться открыть порт", "Ошибка",
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
                    {
                        retry = true;
                    }
                    else
                    {
                        Close();
                        return;
                    }
                }
            }while (retry);
            comm.EnableMessageNotifications();
        }