public override void DeviceConn(SiemensPPIConfig config) { siemensPPI = new SiemensPPI(); SetPort(); siemensPPI.SerialPortInni(serialPort.PortName, serialPort.BaudRate, serialPort.DataBits, serialPort.StopBits, serialPort.Parity); siemensPPI.Open(); siemensPPI.Station = config.StationNo; siemensPPI.RtsEnable = config.RtsEnable; //OperateResult start = siemensPPI.Start(); //if (start.IsSuccess) MessageBox.Show("Start Success!"); //else MessageBox.Show(start.Message); }
private void button1_Click(object sender, EventArgs e) { if (!int.TryParse(textBox2.Text, out int baudRate)) { MessageBox.Show(DemoUtils.BaudRateInputWrong); return; } if (!int.TryParse(textBox16.Text, out int dataBits)) { MessageBox.Show(DemoUtils.DataBitsInputWrong); return; } if (!int.TryParse(textBox17.Text, out int stopBits)) { MessageBox.Show(DemoUtils.StopBitInputWrong); return; } siemensPPI?.Close( ); siemensPPI = new SiemensPPI( ); try { siemensPPI.SerialPortInni(sp => { sp.PortName = comboBox3.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 = comboBox1.SelectedIndex == 0 ? System.IO.Ports.Parity.None : (comboBox1.SelectedIndex == 1 ? System.IO.Ports.Parity.Odd : System.IO.Ports.Parity.Even); }); siemensPPI.Open( ); siemensPPI.Station = byte.Parse(textBox15.Text); siemensPPI.RtsEnable = true; button2.Enabled = true; button1.Enabled = false; panel2.Enabled = true; userControlReadWriteOp1.SetReadWriteNet(siemensPPI, "V100", false); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { if (!int.TryParse(textBox2.Text, out int baudRate)) { MessageBox.Show("波特率输入错误!"); return; } if (!int.TryParse(textBox16.Text, out int dataBits)) { MessageBox.Show("数据位输入错误!"); return; } if (!int.TryParse(textBox17.Text, out int stopBits)) { MessageBox.Show("停止位输入错误!"); return; } siemensPPI?.Close( ); siemensPPI = new SiemensPPI( ); try { siemensPPI.SerialPortInni(sp => { sp.PortName = comboBox3.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 = comboBox1.SelectedIndex == 0 ? System.IO.Ports.Parity.None : (comboBox1.SelectedIndex == 1 ? System.IO.Ports.Parity.Odd : System.IO.Ports.Parity.Even); }); siemensPPI.Open( ); siemensPPI.Station = byte.Parse(textBox15.Text); button2.Enabled = true; button1.Enabled = false; panel2.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }