Exemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();
            this.FormClosing += new FormClosingEventHandler(MainForm_FormClosing);

#if Analyzer
            btnAnalyzerPng.Enabled = true;
            btnAnalyzerPng.Visible = true;
#else
            btnAnalyzerPng.Visible = false;
            btnAnalyzerPng.Enabled = false;
            btnAnalyzerPng.BackgroundImage.Dispose();

            // Resize Comm panel to fit the whole height of the window.
            pnlComm.Size        = new Size(pnlComm.Size.Width, pnlComm.Size.Height + (pnlComm.Location.Y - btnAnalyzerPng.Location.Y));
            pnlComm.Location    = btnAnalyzerPng.Location;
            flowCommStatus.Size = new Size(flowCommStatus.Width, pnlComm.Size.Height);
#endif
            prgmInit();

            // start the CommPort selector form.
            serialportForm              = new SerialportForm();
            serialportForm.FormClosing += new FormClosingEventHandler(serialportForm_FormClosing);
            serialportForm.Show();
            serialportForm.TopMost = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Open a new port selection window to change ports.
        /// </summary>
        private void btnChangePort_Click(object sender, EventArgs e)
        {
            SerialportForm serialportForm = new SerialportForm();

            serialportForm.FormClosing += new FormClosingEventHandler(serialportChange_FormClosing);
            serialportForm.Show();
            serialportForm.TopMost = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Changes the port when a new one got selected.
        /// </summary>
        private void serialportChange_FormClosing(object sender, FormClosingEventArgs e)
        {
            SerialportForm spf = sender as SerialportForm;

            if (analyzerIsActive == false)
            {
                serialSession.ChangePort(spf.serialPort.PortName, spf.serialPort.BaudRate);
            }
            else
            {
                anaForm.changeMachinePort(new System.IO.Ports.SerialPort(spf.serialPort.PortName, spf.serialPort.BaudRate));
            }

            lblPort.Text = "Portname: " + spf.serialPort.PortName;
            lblBaud.Text = "Baudrate: " + spf.serialPort.BaudRate;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Start the serial communication.
        /// </summary>
        private void serialportForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            SerialportForm spf = sender as SerialportForm;

            serialSession = new SerialComm(spf.serialPort.PortName, spf.serialPort.BaudRate, (byte)ModuleId_t.Api_e);
            serialSession.MaxSendRepetition = 3;

            // Register all handler methods for the various comm events.
            serialSession.RegisterPacketReceivedHandler(telegramReceivedCallback);
            serialSession.RegisterPacketSentHandler(telegramSentCallback);
            serialSession.RegisterAckTimeoutHandler(ackTimeoutCallback);
            serialSession.RegisterNackFailHandler(nackFailCallback);
            serialSession.RegisterResponseTimeoutHandler(responseTimeoutCallback);
            serialSession.ackNackReceived += new SerialComm.PacketEvent(ackNackReceivedHandler);

            ApiDataReceived += new PacketCallback(API_ReceiveData);

            serialSession.Start();

            // Comm Labels
            lblPort.Text = "Portname: " + spf.serialPort.PortName;
            lblBaud.Text = "Baudrate: " + spf.serialPort.BaudRate;
        }