XScript Manual · Chapter 20

title: "DIO — digital IO" chapter: 20 images:

  • xscript-dio-example.png

DIO — digital IO

IO["name"] accesses a bit registered in the IO Editor. Assignment writes, bool context reads.

DIO usage

Basic example

IO["O_Blow1"] = OFF;
IO["O_Blow2"] = ON;
IO["O_Blow2"].ToggleBit();
 
if (IO["I_IFReadyPrev"] == false)
{
    return false;
}
 
if (IO["O_DigitalOutput"])
{
    // ON
}
else
{
    // OFF
}

Real-world — continuous-ON wait

From Unit.xms: wait until the sensor is continuously ON for 2 seconds.

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

Event function hook

FUNCTION LinkCheckFunction()
{
    IO["I_U1CnvBowlDetect"].EventFunctionName = "IOEvent_CnvBowlSens";
    IO["I_U2CnvBowlDetect"].EventFunctionName = "IOEvent_CnvBowlSens";
}
 
FUNCTION IOEvent_CnvBowlSens(string name)
{
    if (IO[name] == ON)
    {
        // handle rising edge
    }
    return true;
}

Methods

MethodDescription
bool ReadBit(void)Read current bit
bool WriteBit(bool SetOn)Write bit
bool ToggleBit(void)Flip current value
bool Wait(bool waitOn, int TimeOut)Wait for target state (ms)
bool WaitConti(bool waitOn, int TimeOut, int ContiTime)Wait until held for ContiTime
bool CheckContiOn(int timeMsec)Currently ON for at least timeMsec
bool CheckContiOff(int timeMsec)Currently OFF for at least timeMsec
bool Contains(string keyword)Name match
bool InitBoard(void)Initialize board
void SetDelayOn(int delay) / void SetDelayOff(int delay)Debounce delay (ms)
void RunEventFunction(bool onoff)Manually trigger event
void ClearLinkFunction(void)Detach event hook

Properties

PropertyTypeDescription
Name · ID · DescriptionstringIdentity
BoardType · Module · IndexPhysical
GroupNamestringGrouping
InverseboolInvert signal
CheckFunctionName · EventFunctionNamestringHooks
MessagestringUI hint
SubModelstringModel code
InitOkboolInit complete
InfostringDebug info

Tips

  • Prefer Wait(true, timeout) over busy-looping ReadBit().
  • Filter chatter with WaitConti / CheckContiOn·CheckContiOff.
  • With Inverse = true, the script already sees the inverted value.
  • Use SetDelayOn/Off for hardware-level debounce.