Exemplo n.º 1
0
        /* 接続ボタン */
        private void connectButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (iwS940Component1.IsConnected == true)
                {
                    connectButton.Text = "接続";
                    iwS940Component1.Close();
                }
                else
                {
                    PortSelectDialog ps_dlg = new PortSelectDialog();
                    ps_dlg.ShowDialog();

                    if (ps_dlg.DialogResult != DialogResult.Cancel)
                    {
                        iwS940Component1.Open(ps_dlg.PortName);
                        connectButton.Text = "切断";
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }

            //serial_get();
        }
Exemplo n.º 2
0
        private void serial_get()
        {
            try
            {
                if (Flg_cb == true)
                {
                    iSerialPort.Close();
                    iSerialPort.DataReceived -= DataReceivedHandler;
                    Timer.Enabled             = false;
                    connectButton.Text        = "接続";
                    Flg_cb = false;
                }
                else
                {
                    PortSelectDialog ps_dlg = new PortSelectDialog();
                    ps_dlg.ShowDialog();

                    if (ps_dlg.DialogResult != DialogResult.Cancel)
                    {
                        iSerialPort           = new SerialPort(ps_dlg.PortName);
                        iSerialPort.BaudRate  = 38400;
                        iSerialPort.Parity    = Parity.None;
                        iSerialPort.StopBits  = StopBits.One;
                        iSerialPort.DataBits  = 8;
                        iSerialPort.Handshake = Handshake.None;
                        iSerialPort.RtsEnable = true;
                        iSerialPort.Open();
                        iSerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

                        //Timer.Enabled = true;
                        connectButton.Text = "切断";
                        Flg_cb             = true;
                    }
                }
                chart1.ChartAreas[0].AxisY.Maximum = 600D;
                chart1.ChartAreas[0].AxisY.Minimum = 400D;

                //chart1.ChartAreas[0].AxisY.Maximum = 5D;
                //chart1.ChartAreas[0].AxisY.Minimum = 0D;
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }
        }
Exemplo n.º 3
0
        /* 接続1ボタン */
        private void connectButton1_Click(object sender, EventArgs e)
        {
            try
            {
                if (Flg == true)
                {
                    oSerialPort.Close();
                    connectButton1.Text = "接続";
                    portName            = "未接続";
                }
                else
                {
                    PortSelectDialog ps_dlg = new PortSelectDialog();
                    ps_dlg.ShowDialog();

                    if (ps_dlg.DialogResult != DialogResult.Cancel)
                    {
                        oSerialPort           = new SerialPort(ps_dlg.PortName);
                        oSerialPort.BaudRate  = 9600;
                        oSerialPort.Parity    = Parity.None;
                        oSerialPort.StopBits  = StopBits.One;
                        oSerialPort.DataBits  = 8;
                        oSerialPort.Handshake = Handshake.None;
                        oSerialPort.RtsEnable = true;
                        oSerialPort.Open();

                        portName            = ps_dlg.PortName;
                        Flg                 = true;
                        connectButton1.Text = "切断";
                    }
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }
        }