Beispiel #1
0
        public void LoadConnection()
        {
            // Prompt user for connection settings
            string     portName = GsmCommMain.DefaultPortName;
            int        baudRate = GsmCommMain.DefaultBaudRate;
            int        timeout  = GsmCommMain.DefaultTimeout;
            connection dlg      = new connection();

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


            comm = new GsmCommMain(portName, baudRate, timeout);

            comm.PhoneConnected    += new EventHandler(comm_PhoneConnected);
            comm.PhoneDisconnected += new EventHandler(comm_PhoneDisconnected);

            bool retry;

            do
            {
                retry = false;
                try
                {
                    comm.Open();
                }
                catch (Exception)
                {
                    if (MessageBox.Show(this, "Unable to open the port.", "Error",
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
                    {
                        retry = true;
                    }
                    else
                    {
                        Close();
                        return;
                    }
                }
            }while (retry);

            // Add custom commands
            ProtocolCommand[] commands = new ProtocolCommand[]
            {
                new ProtocolCommand("Send", true, false, false),                   // NeedsData
                new ProtocolCommand("Receive", false, false, false),
                new ProtocolCommand("ExecCommand", true, false, false),            // NeedsData
                new ProtocolCommand("ExecCommand2", true, false, true),            // NeedsData, NeedsError
                new ProtocolCommand("ExecAndReceiveMultiple", true, false, false), // NeedsData
                new ProtocolCommand("ExecAndReceiveAnything", true, true, false),  // NeedsData, NeedsPattern
                new ProtocolCommand("ReceiveMultiple", false, false, false),
                new ProtocolCommand("ReceiveAnyhing", false, true, false)          // NeedsPattern
            };
        }