模板網(wǎng)站也可以做優(yōu)化廣東公司搜索seo哪家強(qiáng)
2.5 C#視覺程序開發(fā)實例1----IO_Manager實現(xiàn)切換程序
1 IO_Manager中輸入實現(xiàn)
1.0 IO_Manager中輸入部分引腳定義
// 設(shè)定index 目的是為了今后可以配置這些參數(shù)、
// 輸入引腳定義
private int index_trig0 = 0; // trig index
private int index_cst = 7; //cst index
private int[] index_ProNO = new int[8];// 程序號indexfor (int i = 0; i < 8; i++)index_ProNO[i] = 8 + i;
1.1 IO_Manager中獲取Trig0 信號
public bool get_Trig0()
{return Inputs[index_trig0];
}
1.2 IO_Manager中獲取Pro_NO
public ushort get_ProgramNO()
{ushort Pro_no = 0;if (Inputs[index_ProNO[0]]) Pro_no += 1;if (Inputs[index_ProNO[1]]) Pro_no += 2;if (Inputs[index_ProNO[2]]) Pro_no += 4;if (Inputs[index_ProNO[3]]) Pro_no += 8;if (Inputs[index_ProNO[4]]) Pro_no += 16;if (Inputs[index_ProNO[5]]) Pro_no += 32;if (Inputs[index_ProNO[5]]) Pro_no += 64;if (Inputs[index_ProNO[6]]) Pro_no += 128;return Pro_no;
}
1.3 IO_Manager中獲取Pro_CST程序切換信號
public bool get_CST()
{return Inputs[index_cst];
}
2 IO_Manager中輸出實現(xiàn)
2.0 IO_Manager中輸出部分引腳定義
// 輸出引腳定義private int index_online = 0;// 聯(lián)機(jī)信號private int index_sto = 1;// STO 輸出private int index_ok = 2;// OK輸出private int index_ng = 3;// NG輸出private int index_CST_Acomm = 7;// 程序切換成功
2.1 IO_Manager中輸出CST_AComm
public void Out_CST_AComm(bool state)
{lock (_mutex){Outputs[index_CST_Acomm] = state;}
}
2.2 IO_Manager中輸出Online信號
public void Out_Onlie(bool state)
{lock(_mutex){Outputs[index_online] = state;}
}
3 Form_vision 主程序中添加代碼實現(xiàn)程序號切換和相機(jī)觸發(fā)
3.0 添加program_no 變量
/// <summary>/// 當(dāng)前程序號/// </summary>public int program_No = 0
3.1 IO_Circle中實現(xiàn)程序號的切換和CST_Acom的返回
private void IO_Circle()
{bool pro_cst_cur = false;bool pro_cst_last = false;while (true){ // readInputs// writeOutputs System.Threading.Thread.Sleep(20);ContextManager.get_IOCtx().Read();ContextManager.get_IOCtx().Write();//更新程序號// CST Accom 信號 pro_cst_cur = ContextManager.get_IOCtx().get_CST();if (pro_cst_cur && !pro_cst_last) //判斷上升沿觸發(fā){program_No = ContextManager.get_IOCtx().get_ProgramNO();//toDO 代碼,程序切換ContextManager.get_IOCtx().Out_CST_AComm(true); } pro_cst_last = pro_cst_cur;// CST_AComm 復(fù)位if(!pro_cst_cur)ContextManager.get_IOCtx().Out_CST_AComm(false);if (StopProgramEvent.WaitOne(0, true)) break;}//end while
}
3.2 Timer_Ticker中實現(xiàn)當(dāng)前程序號的更新顯示
private void timer1_Tick(object sender, EventArgs e)
{/// 更新程序號到控件Util_Helper.Set_NumberControl_Value(num_programNO, program_No);iO_Monitors1.update_status(true,true);
}
4 效果展示
4.1 IO_Client.exe先準(zhǔn)備好程序號31到端口上
4.2 IO_Client.exe 輸出CST 信號
Vision 接受到CST上升沿后,立刻執(zhí)行程序切換,并且輸出CST_Acomm信號給IO_Client