コード例 #1
0
        public override void DeviceConn(OmronHostLinkConfig config)
        {
            OmronHostLink hostLink = new OmronHostLink();

            SetPort();
            hostLink.SerialPortInni(serialPort.PortName, serialPort.BaudRate, serialPort.DataBits, serialPort.StopBits, serialPort.Parity);
            hostLink.UnitNumber = config.StationNo;
            hostLink.SID        = config.SID;
            hostLink.DA2        = config.DA2;
            hostLink.SA2        = config.SA2;
            hostLink.ByteTransform.DataFormat = (HslCommunication.Core.DataFormat)config.ByteTransformDataFormat;
            hostLink.Open();
            NetworkDevice = hostLink;
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!int.TryParse(textBox19.Text, out int baudRate))
            {
                MessageBox.Show(DemoUtils.BaudRateInputWrong);
                return;
            }

            if (!int.TryParse(textBox18.Text, out int dataBits))
            {
                MessageBox.Show(DemoUtils.DataBitsInputWrong);
                return;
            }

            if (!int.TryParse(textBox2.Text, out int stopBits))
            {
                MessageBox.Show(DemoUtils.StopBitInputWrong);
                return;
            }

            if (!byte.TryParse(textBox1.Text, out byte Station))
            {
                MessageBox.Show("PLC Station input wrong!");
                return;
            }

            if (!byte.TryParse(textBox15.Text, out byte SID))
            {
                MessageBox.Show("PLC SID input wrong!");
                return;
            }


            if (!byte.TryParse(textBox16.Text, out byte DA2))
            {
                MessageBox.Show("PLC DA2 input wrong!");
                return;
            }

            if (!byte.TryParse(textBox17.Text, out byte SA2))
            {
                MessageBox.Show("PC SA2 input wrong");
                return;
            }

            omronHostLink?.Close( );
            omronHostLink = new OmronHostLink( );

            try
            {
                omronHostLink.SerialPortInni(sp =>
                {
                    sp.PortName = textBox20.Text;
                    sp.BaudRate = baudRate;
                    sp.DataBits = dataBits;
                    sp.StopBits = stopBits == 0 ? System.IO.Ports.StopBits.None : (stopBits == 1 ? System.IO.Ports.StopBits.One : System.IO.Ports.StopBits.Two);
                    sp.Parity   = comboBox2.SelectedIndex == 0 ? System.IO.Ports.Parity.None : (comboBox2.SelectedIndex == 1 ? System.IO.Ports.Parity.Odd : System.IO.Ports.Parity.Even);
                });
                omronHostLink.UnitNumber = Station;
                omronHostLink.SID        = SID;
                omronHostLink.DA2        = DA2;
                omronHostLink.SA2        = SA2;
                omronHostLink.ByteTransform.DataFormat = (HslCommunication.Core.DataFormat)comboBox1.SelectedItem;


                omronHostLink.Open( );
                button2.Enabled = true;
                button1.Enabled = false;
                panel2.Enabled  = true;

                userControlCurve1.ReadWriteNet = omronHostLink;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }