======CMP One====== 단일 트리거 출력에 대한 사용법 안내 페이지입니다. ====Code==== ===C#=== using ec = ComiLib.EtherCAT.SafeNativeMethods; uint logBitAddr = 0; // 출력 채널에 대한 LogicBitAddress int method = 0; // CMP 출력 조건 int cntrType = 0; // CMP 위치 조건. Command / Feedback int logic = 0; // CMP 출력 로직. int duration = 10; // CMP 출력 유지 시간. 단위 ms. double cmpPosition = 0; static ec.CallbackFunc callBackFunc; private void btnCmpOneStart_Click(object sender, EventArgs e) { // 출력 환경을 설정한다. // CMP 출력 채널을 확인하여 LogicBitAddress로 변환 // Local 채널도 사용 가능하지만, 본 예제에서는 다루지 않는다. if (usingOutputCh) // 범용 Output 채널 사용 시 { int ch = 0; // CMP 출력 채널 logBitAddr = ec.ecdoLogBitAddr_FromGlobalChannel(netID, ch, ref errorCode); if (errorCode != 0) { // 에러처리 } } else // OnBoard(마스터 보드) DO 사용 시 { int ch = 0; logBitAddr = ec.ecdoLogBitAddr_FromOnboardChannel(netID, ch, ref errorCode); if (errorCode != 0) { // 에러처리 } } // 이전 출력 결과를 초기화한다. ec.ecmSxCmpOne_ClearOutResult(netID, axisID, ref errorCode); if (errorCode != 0) { // 에러처리 } cmpCount = 0; logic = 0; // CMP 출력 로직. 0 : Logic A. 1 : Logic B duration = 100; // CMP 출력 유지 시간. 단위 ms. // CMP 출력채널 정보를 설정한다. ec.ecmSxCmpOne_SetChannel(netID, axisID, logBitAddr, logic, duration, ref errorCode); if (errorCode != 0) { // 에러처리 } // CMP 출력조건을 설정한다. // CMP Method // 0 : Current = Reference (While Counting Down) // 1 : Current = Reference (While Counting Up) // 2 : Current = Reference // 3 : Current < Reference // 4 : Current > Reference // 5 : Current <= Reference // 6 : Current >= Reference // cntrType // 0 : Command // 1 : Feedback cmpPosition = 10000; //CMP 출력 위치 method = 6; // CMP 출력 조건 cntrType = 1; // CMP 위치 조건. ec.ecmSxCmpOne_SetCondition(netID, axisID, cntrType, method, cmpPosition, ref errorCode); if (errorCode != 0) { // 에러처리 } //이하 코드는 CMP Notify 관련 기능이다. 해당 기능을 사용하지 않는다면 생략. //CMP Notify : 출력 결과를 소프트웨어적으로 통지받고자 할때 사용하며, 단일 출력(ecmSxCmpOne_ )일때만 사용 가능하다. //본 예제에서는 message 방식과 CallBack 방식을 다룬다. switch (cbxTypeSel.SelectedIndex) { case 0: if (!ec.ecmSxCmpOne_SetHandler_MSG(netID, axisID, (int)ec.EEcmHandlerType.ecmHT_MESSAGE, this.Handle, WMU_CMPMESSAGE, this.Handle, ref errorCode)) // CMP Message 등록 { AddLog(string.Format("ecmSxCmpOne_SetHandler_MSG failed. errorCode : {0}", errorCode)); return; } break; case 1: callBackFunc = new ec.CallbackFunc(CallBackFunc); if (!ec.ecmSxCmpOne_SetHandler_CLB(netID, axisID, (int)ec.EEcmHandlerType.ecmHT_CALLBACK, callBackFunc, 0, this.Handle, ref errorCode)) // CMP Message 등록 { AddLog(string.Format("ecmSxCmpOne_SetHandler_CLB failed. errorCode : {0}", errorCode)); return; } break; } //CMP 시작 bool isEnable = true; if (!ec.ecmSxCmpOne_SetEnable(netID, axisID, isEnable, ref errorCode)) // CMP Enable { // 에러처리 } } private void btnCmpOneStop_Click(object sender, EventArgs e) { //CMP Notify 관련 설정이 되어 있다면 해당 설정을 먼저 해제한다. switch (cbxTypeSel.SelectedIndex) { case 0: if (!ec.ecmSxCmpOne_SetHandler_MSG(netID, axisID, (int)ec.EEcmHandlerType.ecmHT_DISABLE, this.Handle, WMU_CMPMESSAGE, this.Handle, ref errorCode)) { //에러처리 } break; case 1: if (!ec.ecmSxCmpOne_SetHandler_CLB(netID, axisID, (int)ec.EEcmHandlerType.ecmHT_DISABLE, callBackFunc, 0, this.Handle, ref errorCode)) { //에러처리 } break; } // CMP 기능 비활성화 bool isEnable = false; if (!ec.ecmSxCmpOne_SetEnable(netID, axisID, isEnable, ref errorCode)) { //에러처리 } } private void UpdateCmp() { // 마지막 입력된 값에 대한 설정값을 불러온다. // CmpOne 과 CmpCont 는 다른 함수를 사용한다 // 채널 관련 정보를 확인한다. ec.ecmSxCmpOne_GetChannel(netID, axisID, ref logBitAddr, ref logic, ref duration, ref errorCode); // 출력 조건을 확인한다. ec.ecmSxCmpOne_GetCondition(netID, axisID, ref cntrType, ref method, ref cmpPosition, ref errorCode); // UI 처리 } ===C++=== \\