XScript Manual · Chapter 20

DIO — digital IO

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

Basic example

xscript
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 — wait for conveyor bowl detection

Wait with WaitConti until the sensor is continuously ON for 2 seconds; if it is not detected within the time limit (false), show an error dialog with ShowError and end the step. WaitConti(waitOn, timeOut, contiTime) waits up to timeOut until the signal stays in the target state continuously for contiTime; if the signal breaks midway, the duration restarts (momentary chatter is ignored).

xscript
// Wait up to 10s until the sensor is continuously ON for 2s (2000ms)
if (IO[cnvSensorName].WaitConti(true, 10000, 2000) == false)
{
    // Timeout — bowl not detected. Show an error dialog and end the step
    ShowError(EB_Reset, 100, "conveyor bowl detect timeout");
    return false;
}
 
Log($"{cnvSensorName} : bowl detected");

To only check immediately whether it is "currently ON for 2 continuous seconds" without waiting, use CheckContiOn. ShowError(buttonSet, code, message) shows an error dialog — see SYS.

Event function hook

xscript
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)Immediately checks whether it stayed ON for the last timeMsec (does not wait)
bool CheckContiOff(int timeMsec)Immediately checks whether it stayed OFF for the last timeMsec (does not wait)
bool Contains(string keyword)Name match
bool InitBoard(void)Initialize board
bool SetDelayedOn(int delay) / bool SetDelayedOff(int delay)Debounce delay (ms)
void RunEventFuncion(bool onoff)Manually trigger event
void ClearLinkModule(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().
  • To wait until a signal settles use WaitConti; to check immediately whether it is already settled use CheckContiOn·CheckContiOff.
  • With Inverse = true, the script already sees the inverted value.
  • Use SetDelayedOn/Off for hardware-level debounce.