XScript Manual · Chapter 21
title: "AIO — analog IO" chapter: 21 images:
- xscript-aio-example.png
AIO — analog IO
IO["name"] also accesses analog inputs and outputs (load cells, pressure
sensors, servo references). Projects commonly use AI_ / AO_ name prefixes
to distinguish them.
캡처 대기
public/manual/gui/xscript-aio-example.pngBasic example
IO["I_LoadCell"].SetAnalogRange(-5, 5);
double analogMin = 0;
double analogMax = 0;
IO["I_LoadCell"].GetAnalogRange(analogMin, analogMax);
Log("Analog Range // Min = {0}, Max = {1}", analogMin, analogMax);
IO["I_ForceModule"].SetAnalogVoltage(5.0);
double volt = 0.0;
IO["I_LoadCell"].GetAnalogVoltage(volt);Real-world — load-cell stabilization
From ViewSetup.xms. Consecutive reads until the delta drops below a threshold.
double preValue;
bool stable = OFF;
int STABLE_DIFF = 30;
for (i, 0, 4)
{
preValue = TestBowlWeight;
IO[loadcell].GetAnalogValue(TestBowlWeight);
if (i > 0 && MATH.Abs(TestBowlWeight - preValue) < STABLE_DIFF)
{
Log($"LoadCell Stable PASS >> i={i}, weight={TestBowlWeight}");
stable = ON;
break;
}
Sleep(1000);
}
if (stable == OFF)
{
LogError($"LoadCell Stable FAILED: {TestBowlWeight}");
return false;
}Methods
| Signature | Description |
|---|---|
bool SetAnalogRange(double min, double max) | Configure IO voltage range (V) |
bool GetAnalogRange(double &min, double &max) | Read current range |
bool SetAnalogVoltage(double value) | Drive analog output (V) |
bool GetAnalogVoltage(double &value) | Read current voltage |
bool GetAnalogValue(ref double value) | Read scaled physical value (g, kPa, …) |
bool SetAnalogScale(double scale) | Voltage → physical-unit scale factor |
bool SetAnalogTareClear(void) | Tare (zero) |
Tips
- Configure
SetAnalogRangebefore writing to avoid scaling errors. - For load cells, sample repeatedly and accept only when deltas fall below a threshold.
- Zero with
SetAnalogTareClear()while empty — subsequent reads use the corrected baseline. - Voltages exceeding board limits clamp, they don't throw.