public void Receive_Data_Check(byte[] data) { _101_function _101_Function = new _101_function(); if ((data[0] != (byte)_101_config.IEC_101_Msg.variable_state_code) && (data[0] != (byte)_101_config.IEC_101_Msg.fixed_state_code)) { return; } try { int start = 0; while (start < data.Length) { int n = _101_Function.Data_Check(data, start); byte[] databuff = new byte[n]; for (int i = 0; i < n; i++, start++) { databuff[i] = data[start]; } SerialPort_config.Analysis_msg(databuff, databuff.Length);//显示报文解析 Receive_Data_Handle(databuff); } } catch { return; } }
private void _101setting_Load(object sender, EventArgs e) { SerialPort_config Port_Config = new SerialPort_config(); //获取串口端口 Port_Config.Updata_Serialport_Name(this.comboBox5); //初始化界面值 form_init(); }
private void ToolStripMenuItem9_Click(object sender, EventArgs e) { SerialPort_config port_Config = new SerialPort_config(); if (serialPort1.IsOpen)//关闭连接 { port_Config.SerialPort_Close(serialPort1, ToolStripMenuItem9); } else//打开连接 { port_Config.SerialPort_Open(serialPort1, ToolStripMenuItem9, this.richTextBox1); //设置打开连接就发送请求连接报文--->后面需加定时器,定时发送连接报文 _101_SendOut_Data Send_Data = new _101_SendOut_Data(); _101_config.process_state = (int)_101_config.IEC_101_Process_State.UNCONNECT; Send_Data.Send_Msg_Manage_bt(); } }
private void button1_Click(object sender, EventArgs e) { SerialPort_config Port_Config = new SerialPort_config(); _101_config _101_config = new _101_config(); //保存串口设置 Port_Config.SerialPort_Save(this.comboBox5.Text, this.comboBox6.Text, this.comboBox7.Text, this.comboBox8.Text, this.comboBox9.Text); //保存101配置 _101_config._101_Save(Convert.ToInt32(this.comboBox1.Text), Convert.ToInt32(this.comboBox2.Text), Convert.ToInt32(this.comboBox3.Text), Convert.ToInt32(this.comboBox4.Text), Convert.ToInt32(this.textBox1.Text), Convert.ToInt32(this.textBox2.Text)); //保存完关闭窗口 this.Close(); }
private void Send_Data_Transmit(byte[] data, int len) { _101_function _101_Function = new _101_function(); if (data[0] == (byte)_101_config.IEC_101_Msg.fixed_state_code) { data[len++] = _101_Function.Get_CS(data, 1, 3); } else { data[len++] = _101_Function.Get_CS(data, 4, len - 4); } data[len++] = (byte)_101_config.IEC_101_Msg.end_code; SerialPort_config serialPort = new SerialPort_config(); serialPort.Send_Data(data, len); }
private void button2_Click(object sender, EventArgs e) { SerialPort_config port_Config = new SerialPort_config(); port_Config.Send_Data(serialPort1, textBox2.Text);//发送数据 }