Example #1
0
 private void btnConfigureComPort_Click(object sender, EventArgs e)
 {
     CloseComPort();
     try
     {
         comPortConfigForm.Show();
     }
     catch (Exception)
     {
         comPortConfigForm = new ComPortConfigForm(this);
         comPortConfigForm.Show();
     }
     finally
     {
         comPortConfigForm.SetComboBoxes(this.comPortName, this.baudRate, this.parity, this.dataBits, this.stopBits);
     }
 }
        private void btnConfigureComPort_Click(object sender, EventArgs e)
        {
            if (comPortConfigForm != null && comPortConfigForm.Visible)
            {
                return;
            }

            CloseComPort();
            availableComPortNames = FindAvailableComPorts();

            try
            {
                comPortConfigForm.SetComboBoxes(this.availableComPortNames, this.comPortName, this.baudRate, this.parity, this.dataBits, this.stopBits, this.handshake, this.rtsEnable, this.dtrEnable);
                comPortConfigForm.ShowDialog();
            }
            catch (Exception)
            {
                comPortConfigForm = new ComPortConfigForm(this);
                comPortConfigForm.SetComboBoxes(this.availableComPortNames, this.comPortName, this.baudRate, this.parity, this.dataBits, this.stopBits, this.handshake, this.rtsEnable, this.dtrEnable);
                comPortConfigForm.ShowDialog();
            }
        }
        public MainForm()
        {
            InitializeComponent();

               lstDisplayWindowTwo.Visible = false;
               listBoxOneSelected = true;
               comPortConfigForm = null;
               dataProcessor = new DataProcessor(this);
               lstMessageSummary.Sorted = true;
               cmbViews.Items.Add(ALL_MESSAGES);
               cmbViews.Sorted = true;
               cmbViews.SelectedIndex = 0;
               recordedMessages = new List<String>();

               initialized = false;
               stopReceiving = false;
               this.comPortName = "--";
               this.baudRate = DEFAULT_BAUD_RATE;
               this.parity = DEFAULT_PARITY;
               this.dataBits = DEFAULT_DATA_BITS;
               this.stopBits = DEFAULT_STOP_BITS;
               this.handshake = DEFAULT_HANDSHAKE;
               this.rtsEnable = DEFAULT_RTS;
               this.dtrEnable = DEFAULT_DTR;

               lblvPortName.Text = this.comPortName;
               lblvBaudRate.Text = this.baudRate.ToString();
               lblvParity.Text = this.parity.ToString();
               lblvDataBits.Text = this.dataBits.ToString();
               lblvStopBits.Text = this.stopBits.ToString();
               lblvHandshake.Text = this.handshake.ToString();
               lblvRTSEnable.Text = this.rtsEnable.ToString();
               lblvDTREnable.Text = this.dtrEnable.ToString();

               btnOpenAndClose.BackColor = Color.Red;
               btnOpenAndClose.Text = "Closed";
               comPortClosed = true;

               availableComPortNames = FindAvailableComPorts();

               if(availableComPortNames.Count > 0)
                    OpenComPort(availableComPortNames.ElementAt<String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_HANDSHAKE, DEFAULT_RTS, DEFAULT_DTR);

               Configuration config = new Configuration();

               string[] connections = config.Read();

              if (!config.IsAdministrator)
                  btnAddCompanyMessage.Enabled = false;
              else
                  isAdministrator = true;

               string errors = "";
               List<MessageFormat> messages = new List<MessageFormat>();
               foreach (string connection in connections)
               {
                   SqlMessageConnection sql = new SqlMessageConnection(connection);

                   if (sql.isConnected())
                       messages.AddRange(sql.GetMessageList());
                   else
                   {
                       try
                       {
                           errors += connection.Split(';')[0] + ';' + connection.Split(';')[1] + ';' + connection.Split(';')[2] + ";Table=" + connection.Split(';')[4] + '\n';
                       }
                       catch { }
                   }
               }

               if (errors != "")
                   MessageBox.Show("The following SQL connections could not be opened:\n\n" + errors);

               foreach (MessageFormat m in messages)
                   AddMessageFormat(m, MessageType.Company);

              initialized = true;
        }
        private void btnConfigureComPort_Click(object sender, EventArgs e)
        {
            if (comPortConfigForm != null && comPortConfigForm.Visible)
                    return;

               CloseComPort();
               availableComPortNames = FindAvailableComPorts();

               try
               {
                    comPortConfigForm.SetComboBoxes(this.availableComPortNames, this.comPortName, this.baudRate, this.parity, this.dataBits, this.stopBits, this.handshake, this.rtsEnable, this.dtrEnable);
                    comPortConfigForm.ShowDialog();
               }
               catch (Exception)
               {
                    comPortConfigForm = new ComPortConfigForm(this);
                    comPortConfigForm.SetComboBoxes(this.availableComPortNames, this.comPortName, this.baudRate, this.parity, this.dataBits, this.stopBits, this.handshake, this.rtsEnable, this.dtrEnable);
                    comPortConfigForm.ShowDialog();
               }
        }
        public MainForm()
        {
            InitializeComponent();

            lstDisplayWindowTwo.Visible = false;
            listBoxOneSelected          = true;
            comPortConfigForm           = null;
            dataProcessor            = new DataProcessor(this);
            lstMessageSummary.Sorted = true;
            cmbViews.Items.Add(ALL_MESSAGES);
            cmbViews.Sorted        = true;
            cmbViews.SelectedIndex = 0;
            recordedMessages       = new List <String>();

            initialized      = false;
            stopReceiving    = false;
            this.comPortName = "--";
            this.baudRate    = DEFAULT_BAUD_RATE;
            this.parity      = DEFAULT_PARITY;
            this.dataBits    = DEFAULT_DATA_BITS;
            this.stopBits    = DEFAULT_STOP_BITS;
            this.handshake   = DEFAULT_HANDSHAKE;
            this.rtsEnable   = DEFAULT_RTS;
            this.dtrEnable   = DEFAULT_DTR;

            lblvPortName.Text  = this.comPortName;
            lblvBaudRate.Text  = this.baudRate.ToString();
            lblvParity.Text    = this.parity.ToString();
            lblvDataBits.Text  = this.dataBits.ToString();
            lblvStopBits.Text  = this.stopBits.ToString();
            lblvHandshake.Text = this.handshake.ToString();
            lblvRTSEnable.Text = this.rtsEnable.ToString();
            lblvDTREnable.Text = this.dtrEnable.ToString();

            btnOpenAndClose.BackColor = Color.Red;
            btnOpenAndClose.Text      = "Closed";
            comPortClosed             = true;

            availableComPortNames = FindAvailableComPorts();

            if (availableComPortNames.Count > 0)
            {
                OpenComPort(availableComPortNames.ElementAt <String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_HANDSHAKE, DEFAULT_RTS, DEFAULT_DTR);
            }

            Configuration config = new Configuration();

            string[] connections = config.Read();

            if (!config.IsAdministrator)
            {
                btnAddCompanyMessage.Enabled = false;
            }
            else
            {
                isAdministrator = true;
            }

            string errors = "";
            List <MessageFormat> messages = new List <MessageFormat>();

            foreach (string connection in connections)
            {
                SqlMessageConnection sql = new SqlMessageConnection(connection);

                if (sql.isConnected())
                {
                    messages.AddRange(sql.GetMessageList());
                }
                else
                {
                    try
                    {
                        errors += connection.Split(';')[0] + ';' + connection.Split(';')[1] + ';' + connection.Split(';')[2] + ";Table=" + connection.Split(';')[4] + '\n';
                    }
                    catch { }
                }
            }

            if (errors != "")
            {
                MessageBox.Show("The following SQL connections could not be opened:\n\n" + errors);
            }

            foreach (MessageFormat m in messages)
            {
                AddMessageFormat(m, MessageType.Company);
            }

            initialized = true;
        }
Example #6
0
        public MainForm()
        {
            InitializeComponent();

            comPortConfigForm     = null;
            dataProcessor         = new DataProcessor(this);
            numberOfStatusEntries = 0;
            numberOfEntries       = 0;
            totalNumberOfMessages = 0;

            PrintStatusMessage("Start Initialization");
            initialized = false;

            availablePortNames = new List <String>();
            String[] portNames = SerialPort.GetPortNames();
            foreach (String name in portNames)
            {
                if (name.StartsWith("COM"))
                {
                    PrintStatusMessage("Add Com Port " + name);
                    availablePortNames.Add(name);
                }
            }
            availablePortNames.Sort();

            OpenComPort(availablePortNames.ElementAt <String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS);

            PrintStatusMessage("Remaining List");
            foreach (String name in availablePortNames)
            {
                PrintStatusMessage(name);
            }

            initialized = true;

            PrintStatusMessage("End Initialization");

            PrintStatusMessage("Start Configuration");
            Configuration config = new Configuration();

            string[] connections = config.Read();
            PrintStatusMessage("Configuration read complete. Found " + connections.Length + " connection(s).");

            if (!config.IsAdministrator)
            {
                btnAddCompanyMessage.Hide();
            }
            else
            {
                isAdministrator = true;
            }

            PrintStatusMessage("End Configuration");
            PrintStatusMessage("Start SQL Import");

            List <MessageFormat> messages = new List <MessageFormat>();

            foreach (string connection in connections)
            {
                messages.AddRange(new SqlMessageConnection(connection).GetMessageList());
            }

            foreach (MessageFormat m in messages)
            {
                AddMessageFormat(m, MessageType.Company);
            }

            PrintStatusMessage("End SQL Import. " + companyMessages.Count + " custom messages loaded.");

            /*
             * Format testing. form is the format string, b is the random data array.
             * Prints raw data and formatted data to console.
             * string form = "g * 2 h";
             * byte[] b = new byte[13];
             * (new Random()).NextBytes(b);
             *
             * string s = "";
             * foreach (byte a in b)
             *  s += a.ToString() + " ";
             * Console.WriteLine(s);
             * Console.WriteLine(FormatParser.Parse(form, b));
             */
        }
        public MainForm()
        {
            InitializeComponent();

               comPortConfigForm = null;
               dataProcessor = new DataProcessor(this);
               numberOfStatusEntries = 0;
               numberOfEntries = 0;
               totalNumberOfMessages = 0;

               PrintStatusMessage("Start Initialization");
               initialized = false;

               availablePortNames = new List<String>();
               String[] portNames = SerialPort.GetPortNames();
               foreach (String name in portNames)
               {
                    if (name.StartsWith("COM"))
                    {
                         PrintStatusMessage("Add Com Port " + name);
                         availablePortNames.Add(name);
                    }
               }
               availablePortNames.Sort();

               OpenComPort(availablePortNames.ElementAt<String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS);

               PrintStatusMessage("Remaining List");
               foreach (String name in availablePortNames)
               {
                    PrintStatusMessage(name);
               }

               initialized = true;

               PrintStatusMessage("End Initialization");

               PrintStatusMessage("Start Configuration");
               Configuration config = new Configuration();

               string[] connections = config.Read();
              PrintStatusMessage("Configuration read complete. Found " + connections.Length + " connection(s).");

              if (!config.IsAdministrator)
                  btnAddCompanyMessage.Hide();
              else
                  isAdministrator = true;

               PrintStatusMessage("End Configuration");
               PrintStatusMessage("Start SQL Import");

               List<MessageFormat> messages = new List<MessageFormat>();
               foreach (string connection in connections)
                   messages.AddRange(new SqlMessageConnection(connection).GetMessageList());

               foreach (MessageFormat m in messages)
                   AddMessageFormat(m, MessageType.Company);

              PrintStatusMessage("End SQL Import. " + companyMessages.Count + " custom messages loaded.");

              /*
               * Format testing. form is the format string, b is the random data array.
               * Prints raw data and formatted data to console.
              string form = "g * 2 h";
              byte[] b = new byte[13];
              (new Random()).NextBytes(b);

              string s = "";
              foreach (byte a in b)
                  s += a.ToString() + " ";
              Console.WriteLine(s);
              Console.WriteLine(FormatParser.Parse(form, b));
               */
        }
 private void btnConfigureComPort_Click(object sender, EventArgs e)
 {
     CloseComPort();
        try
        {
             comPortConfigForm.Show();
        }
        catch (Exception)
        {
             comPortConfigForm = new ComPortConfigForm(this);
             comPortConfigForm.Show();
        }
        finally
        {
             comPortConfigForm.SetComboBoxes(this.comPortName, this.baudRate, this.parity, this.dataBits, this.stopBits);
        }
 }