private void YK_choise_Click(object sender, EventArgs e) { if (YK_Init()) { this.Explain.Text = ""; cot = (int)_101_config._IEC101_ASDU_COT_CODE_.EN_IEC101_ASDU_COT_ACT; se = 0x80; this.Explain.AppendText("发送遥控预置...\r\n"); _101_config.process_state = (int)_101_config.IEC_101_Process_State.YK_SELECT; _101_SendOut_Data Send_Data = new _101_SendOut_Data(); Send_Data.Send_Msg_Manage_bt(); this.timer1.Start(); } }
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(); } }
public void Jumpto_Send_Data(int i) { _101_SendOut_Data Send_Data = new _101_SendOut_Data(); switch (i) { case _101_config.General_Call_Ti100: _101_config.process_state = (int)_101_config.IEC_101_Process_State.INIT_CALL; Send_Data.Send_Msg_Manage_bt(); break; case _101_config.Read_Clock_Ti103: _101_config.process_state = (int)_101_config.IEC_101_Process_State.TIME_READ; Send_Data.Send_Msg_Manage_bt(); break; case _101_config.Synchro_Clock_Ti103: _101_config.process_state = (int)_101_config.IEC_101_Process_State.TIME_CHECK; Send_Data.Send_Msg_Manage_bt(); break; case _101_config.Link_Test_Ti104: _101_config.process_state = (int)_101_config.IEC_101_Process_State.TEST_LOOPBACK; Send_Data.Send_Msg_Manage_bt(); break; case _101_config.Heart_Test: _101_config.process_state = (int)_101_config.IEC_101_Process_State.TEST_HEART; Send_Data.Send_Msg_Manage_bt(); break; case _101_config.Reset_Ti105: _101_config.process_state = (int)_101_config.IEC_101_Process_State.RESET_LOOPBACK; Send_Data.Send_Msg_Manage_bt(); break; default: break; } }
private void Data_Handle_Fixed_bt(byte[] data) { //_101_function _101_Function = new _101_function(); _101_SendOut_Data Send_Data = new _101_SendOut_Data(); byte crtl = data[1]; int ipaddr = _101_function.octets_to_number(data, 2, _101_config.ipaddr_size); int prm = (crtl & (int)_101_config.IEC101_CONTROL_DEF.CN_CTL_LK_PRM) >> 6; if (prm == 1) {//从机为启动站发起报文,主站应回复确认 int FC = (crtl & (int)_101_config.IEC101_CONTROL_DEF.CN_CTL_LK_FUN); switch (FC) { case (int)_101_config.IEC101_CDIR_LK_CODE.FUN_AS: //从机发送请求链路状态 if ((_101_config.process == (int)_101_config.IEC_101_Process.GOING) && (_101_config.process_state == (int)_101_config.IEC_101_Process_State.RESET_LINK)) { Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_RSBS); } break; case (int)_101_config.IEC101_CDIR_LK_CODE.FUN_RST_LK: //从机发送复位远方链路 if ((_101_config.process == (int)_101_config.IEC_101_Process.GOING) && (_101_config.process_state == (int)_101_config.IEC_101_Process_State.RESET_LINK)) { Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); _101_config.process_state = (int)_101_config.IEC_101_Process_State.LINK_STAUS_END; } break; case (int)_101_config.IEC_101_Process_State.TEST_HEART: //主站收到从机的心跳测试报文 回复确认 if (_101_config.process == (int)_101_config.IEC_101_Process.END) { Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } break; default: break; } } else if (prm == 0) {//从机为从站,该报文为从机发送的确认报文,对装置发起的报文进行了应答 int FC = (crtl & (int)_101_config.IEC101_CONTROL_DEF.CN_CTL_LK_FUN); switch (FC) { case (int)_101_config.IEC101_MDIR_LK_CODE.FUN_RSBS: //从机回复链路状态 if ((_101_config.process == (int)_101_config.IEC_101_Process.GOING) && (_101_config.process_state == (int)_101_config.IEC_101_Process_State.LINK_STAUS)) { _101_config.process_state = (int)_101_config.IEC_101_Process_State.RESET_LINK; Send_Data.Send_Msg_Manage_bt(); //回复复位远方链路 } break; case (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK: switch ((int)_101_config.process_state) { case (int)_101_config.IEC_101_Process_State.RESET_LINK: //当前在复位远方链路状态 break; case (int)_101_config.IEC_101_Process_State.TEST_HEART: //心跳测试状态 _101_config.process = (int)_101_config.IEC_101_Process.END; break; default: break; } break; default: break; } } }
private void Data_Handle_Variable(byte[] data) { _101_SendOut_Data Send_Data = new _101_SendOut_Data(); int n = 4; byte crtl = data[n++]; int prm = (crtl & (int)_101_config.IEC101_CONTROL_DEF.CN_CTL_LK_PRM) >> 6; int acd = (crtl & (int)_101_config.IEC101_CONTROL_DEF.CN_CTL_LK_FCB_ACD) >> 5; int dfc = (crtl & (int)_101_config.IEC101_CONTROL_DEF.CN_CTL_LK_FCV_DFC) >> 4; int cmd = (crtl & (int)_101_config.IEC101_CONTROL_DEF.CN_CTL_LK_FUN); int ipaddr = _101_function.octets_to_number(data, n, _101_config.ipaddr_size); n += _101_config.ipaddr_size; byte type = data[n]; if (_101_config._101_balance)//平衡校验 { if (cmd != (int)_101_config.IEC101_CDIR_LK_CODE.FUN_SD) { return; } } else if (_101_config._101_unbalance)//非平衡 { if (prm != 0x00) { return; } if (cmd != (int)_101_config.IEC101_MDIR_LK_CODE.FUN_RSDT) { return; } } switch (type) { case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP070: if (_101_config._101_balance) { //平衡模式 回复确认报文 Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } if ((_101_config.process == (int)_101_config.IEC_101_Process.GOING) && (_101_config.process_state == (int)_101_config.IEC_101_Process_State.LINK_STAUS_END)) { _101_config.process = (int)_101_config.IEC_101_Process.END; // _101_config.FCB = 1; //_101_config.process_state = (int)_101_config.IEC_101_Process_State.INIT_CALL; //Send_Data.Send_Msg_Manage_bt(); } break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP100: Data_Handle_Variable_Type100(data); break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP103: if (_101_config._101_balance) { //平衡模式 回复确认报文 Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } _101_config.process = (int)_101_config.IEC_101_Process.END; break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP104: //测试命令 if (_101_config._101_balance) { //平衡模式 回复确认报文 Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } _101_config.process = (int)_101_config.IEC_101_Process.END; break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP105: //复位进程 if (_101_config._101_balance) { //平衡模式 回复确认报文 Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } _101_config.process = (int)_101_config.IEC_101_Process.END; break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP045: case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP046: //添加处理遥控 Data_Handle_Variable_YK(data); break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP001: //单点COS case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP003: //双点COS if (_101_config._101_balance) { //平衡模式 回复确认报文 Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } if (_101_config.process == (int)_101_config.IEC_101_Process.GOING) { Send_Data.Send_Msg_Manage_bt(); } break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP030: //单点SOE case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP031: //双点SOE if (_101_config._101_balance) { //平衡模式 回复确认报文 Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } if (_101_config.process == (int)_101_config.IEC_101_Process.GOING) { Send_Data.Send_Msg_Manage_bt(); } break; case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP009: //归一化遥测 case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP011: //标度化遥测 case (int)_101_config.IEC101_ASDU_MDIR_TYP_CODE.EN_IEC101_ASDU_TYP013: //浮点型遥测 if (_101_config._101_balance) { //平衡模式 回复确认报文 Send_Data.Send_Data_Fixed(0, 0, 0, (int)_101_config.IEC101_MDIR_LK_CODE.FUN_ACK); } if (_101_config.process == (int)_101_config.IEC_101_Process.GOING) { Send_Data.Send_Msg_Manage_bt(); } break; } }