XScript 매뉴얼 · Chapter 20

title: "DIO — 디지털 입출력" chapter: 20 images:

  • xscript-dio-example.png

DIO — 디지털 입출력

IO["이름"] 으로 접근. IO Editor 에서 등록된 이름으로 개별 비트 단위 입출력을 읽고 씁니다. 대입 연산자(=)로도 출력을 쓸 수 있고, bool 컨텍스트에서는 자동으로 현재 값을 반환합니다.

DIO 사용 예

기본 예제

// OUTPUT 제어
IO["O_Blow1"] = OFF;
IO["O_Blow2"] = ON;
IO["O_Blow2"].ToggleBit();
 
// INPUT 체크
if (IO["I_IFReadyPrev"] == false)
{
    return false;
}
 
// 디지털 출력에 대한 조건문
if (IO["O_DigitalOutput"])
{
    // ON 인 경우
}
else
{
    // OFF 인 경우
}

실전 예제 — 컨베이어 그릇 감지 대기

센서가 2초 이상 지속 ON 될 때까지 대기하는 패턴.

if (IO[cnvSensorName].CheckContiOn(2000) == false)
{
    return false;
}
 
Log($"STEP_WaitOrder : {cnvSensorName} detected");

이벤트 함수 연결

IO Editor 에서 지정하거나 스크립트 초기화 시점에 EventFunctionName 으로 연결.

FUNCTION LinkCheckFunction()
{
    IO["I_U1CnvBowlDetect"].EventFunctionName = "IOEvent_CnvBowlSens";
    IO["I_U2CnvBowlDetect"].EventFunctionName = "IOEvent_CnvBowlSens";
}
 
FUNCTION IOEvent_CnvBowlSens(string name)
{
    if (IO[name] == ON)
    {
        // 센서 ON 시 처리
    }
    return true;
}

메서드

메서드설명
bool ReadBit(void)현재 비트 값 읽기
bool WriteBit(bool SetOn)비트 출력
bool ToggleBit(void)현재 값 반전
bool Wait(bool waitOn, int TimeOut)지정 상태가 될 때까지 대기 (ms)
bool WaitConti(bool waitOn, int TimeOut, int ContiTime)지정 상태가 ContiTime 이상 지속될 때까지 대기
bool CheckContiOn(int timeMsec)현재 ON 상태가 timeMsec 이상 지속됐는지
bool CheckContiOff(int timeMsec)현재 OFF 상태가 timeMsec 이상 지속됐는지
bool Contains(string keyword)이름에 키워드 포함 여부
bool InitBoard(void)보드 초기화
void SetDelayOn(int delay) / void SetDelayOff(int delay)ON/OFF 지연 설정 (ms)
void RunEventFunction(bool onoff)이벤트 함수 수동 실행
void ClearLinkFunction(void)연결된 이벤트 함수 해제

프로퍼티

프로퍼티타입설명
Name · ID · Descriptionstring식별
BoardType · Module · Indexstring/int물리 위치
GroupNamestring그룹
Inversebool신호 반전 여부
CheckFunctionName · EventFunctionNamestring연동 함수명
MessagestringUI 표시 메시지
SubModelstring모델 구분
InitOkbool초기화 완료
Infostring디버그 정보

  • 직접 ReadBit() 루프는 피하고 Wait(true, timeout) 사용 → CPU 점유 감소.
  • 채터링 우려 신호는 WaitConti / CheckContiOn·CheckContiOff 로 필터링.
  • Inverse = true 로 설정된 신호는 스크립트에서 이미 반전된 값으로 다뤄집니다.
  • 논리 타이밍이 중요한 곳은 SetDelayOn/Off 로 하드웨어 디바운스 시간 확보.