차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
platform:ethercat:70_users_guide:00_cookbook:20_systeminit:20_fullcode [2021/05/14 09:50] winoars |
platform:ethercat:70_users_guide:00_cookbook:20_systeminit:20_fullcode [2024/07/08 18:23] (현재) |
||
---|---|---|---|
줄 1: | 줄 1: | ||
- | ======System Initialize : Code====== | + | ======Code====== |
<alert type=" | <alert type=" | ||
디바이스 로드, 알람 클리어, 홈복귀 등을 수행하여 시스템이 이송 가능한 상태가 되도록 초기화합니다. | 디바이스 로드, 알람 클리어, 홈복귀 등을 수행하여 시스템이 이송 가능한 상태가 되도록 초기화합니다. | ||
줄 95: | 줄 95: | ||
int netID = 0; | int netID = 0; | ||
+ | uint slaveCount = 0; | ||
int errorCode = 0; | int errorCode = 0; | ||
byte[] axisList = new byte[32]; | byte[] axisList = new byte[32]; | ||
List< | List< | ||
CancellationTokenSource cts; | CancellationTokenSource cts; | ||
- | #region AddLog | + | |
+ | | ||
private void AddLog(int errorCode) | private void AddLog(int errorCode) | ||
줄 115: | 줄 117: | ||
} | } | ||
- | #endregion | + | |
void Stop() | void Stop() | ||
줄 121: | 줄 123: | ||
IsStop = true; | IsStop = true; | ||
} | } | ||
+ | |||
/// < | /// < | ||
/// Master Device를 초기화합니다. | /// Master Device를 초기화합니다. | ||
줄 126: | 줄 129: | ||
/// < | /// < | ||
private bool InitMasterDevice() | private bool InitMasterDevice() | ||
+ | { | ||
+ | //마스터 디바이스를 로드합니다. | ||
+ | if (!DeviceLoad()) | ||
+ | return false; | ||
+ | |||
+ | // 설정 된 슬레이브 개수와 연결 된 슬레이브 개수가 동일한지 확인합니다. | ||
+ | if(!CompareSlaveCount()) | ||
+ | return false; | ||
+ | |||
+ | // SW Version(FW, WDM, SDK)이 서로 호환되는 버전인지 확인합니다. | ||
+ | if (!GetVersionCompResult()) | ||
+ | { | ||
+ | AddLog(" | ||
+ | return false; | ||
+ | } | ||
+ | AddLog(" | ||
+ | |||
+ | // 슬레이브의 Input / Output이 반대로 연결된 모듈이 있는지 확인합니다. | ||
+ | if (!CheckReveseConnection()) | ||
+ | { | ||
+ | AddLog(" | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | // Network의 alStatus를 OP로 설정합니다. | ||
+ | if (!SetAlStateToOP()) | ||
+ | return false; | ||
+ | |||
+ | AddLog(" | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | private bool DeviceLoad() | ||
{ | { | ||
try | try | ||
줄 146: | 줄 182: | ||
return false; | return false; | ||
} | } | ||
+ | |||
+ | return true; | ||
} | } | ||
catch (BadImageFormatException) | catch (BadImageFormatException) | ||
줄 162: | 줄 200: | ||
return false; | return false; | ||
} | } | ||
+ | } | ||
+ | private bool CompareSlaveCount() | ||
+ | { | ||
// Config된 slave 수를 확인합니다. | // Config된 slave 수를 확인합니다. | ||
// Configuration 단계에서 설정된 슬레이브의 수로 현재 연결된 슬레이브 수와는 관련이 없습니다. | // Configuration 단계에서 설정된 슬레이브의 수로 현재 연결된 슬레이브 수와는 관련이 없습니다. | ||
줄 190: | 줄 231: | ||
return false; | return false; | ||
} | } | ||
+ | return true; | ||
+ | } | ||
- | // SW Version(FW, WDM, SDK)이 서로 호환되는 버전인지 확인합니다. | + | private bool SetAlStateToOP() |
- | // 호환되지 않는 버전이 설치되어 있는 경우 오동작 할 수 있습니다. | + | { |
- | if (!GetVersionCompResult()) | + | |
- | | + | |
- | AddLog(" | + | |
- | return false; | + | |
- | } | + | |
- | AddLog(" | + | |
- | + | ||
- | // 슬레이브의 Input / Output이 반대로 연결된 모듈이 있는지 확인합니다. | + | |
- | if (!CheckReveseConnection()) | + | |
- | { | + | |
- | AddLog(" | + | |
- | return false; | + | |
- | } | + | |
- | + | ||
- | // Network의 alStatus를 OP로 설정합니다. | + | |
// alStatus : https:// | // alStatus : https:// | ||
ec.ecNet_SetAlState(netID, | ec.ecNet_SetAlState(netID, | ||
줄 230: | 줄 258: | ||
while (sw.ElapsedMilliseconds < 10000 && !isSuccess) | while (sw.ElapsedMilliseconds < 10000 && !isSuccess) | ||
{ | { | ||
- | if (IsStop) | + | if (IsStop) |
{ | { | ||
AddLog(" | AddLog(" | ||
줄 261: | 줄 289: | ||
} | } | ||
- | AddLog(" | ||
return true; | return true; | ||
} | } | ||
줄 341: | 줄 368: | ||
private bool GetVersionCompResult() | private bool GetVersionCompResult() | ||
{ | { | ||
+ | // SW Version(FW, WDM, SDK)이 서로 호환되는 버전인지 확인합니다. | ||
+ | // 호환되지 않는 버전이 설치되어 있는 경우 오동작 할 수 있습니다. | ||
ec.TEcFileVerInfo_SDK sdkInfo = new ec.TEcFileVerInfo_SDK(); | ec.TEcFileVerInfo_SDK sdkInfo = new ec.TEcFileVerInfo_SDK(); | ||
ec.TEcFileVerInfo_WDM driverInfo = new ec.TEcFileVerInfo_WDM(); | ec.TEcFileVerInfo_WDM driverInfo = new ec.TEcFileVerInfo_WDM(); | ||
줄 635: | 줄 664: | ||
// MotState == 0 인 경우, Stop 명령에 의해 정지했다는 의미입니다. | // MotState == 0 인 경우, Stop 명령에 의해 정지했다는 의미입니다. | ||
int motState = ec.ecmSxSt_GetMotState(netID, | int motState = ec.ecmSxSt_GetMotState(netID, | ||
- | AddLog(errorCode); | + | AddLog(errorCode); |
- | + | ||
} | } | ||
줄 644: | 줄 672: | ||
} | } | ||
} | } | ||
- | |||
</ | </ |