stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 100

Day 100 of 365 · Advanced · Month 4: Network in detail

Is a device there? sdse, sdns, bdse, bdns

Before the chip reads from a pin it asks whether anything is attached there at all – with sdse, sdns, bdse and bdns.

Lesson 12 min Week 15

What you learn today

  • Check whether a pin is set
  • Avoid the DeviceNotFound error
  • Safe branch without a device

A device on a pin is gone quickly: deconstructed, moved, hit by a meteor. Then l r0 d0 Temperature reports an error, and the chip stops on exactly that line. It retries it every tick – everything after it no longer happens. The heater stays in its last state, the warning light never turns on.

Better: the chip asks first.

Anybody there? sdse and sdns

sdse r0 d0   # 1 if a device is attached to d0
sdns r1 d0   # 1 if d0 is empty

sdse stands for set if device set, sdns for set if device not set. Both return 0 or 1 and can be used like any comparison – for example straight for a warning light:

sdns missing sensor
s warning On missing

Jump away right away: bdse and bdns

Often you just want to skip a part when the device is missing:

bdns sensor start    # no sensor: back to the start
l temp sensor Temperature

bdns jumps when the device is missing, bdse when it is there. Here the jump lands on start, and because yield sits there, the chip waits politely for the next tick.

Instructiondoes
sdse r? d?r = 1 if device set
sdns r? d?r = 1 if device missing
bdse d? targetjumps if device set
bdns d? targetjumps if device missing

A register holding a ReferenceId works as the device too – more on that yesterday with the ReferenceId.

And on the data network?

For devices you address via lbn you do not need this check: if the device is missing there, Average returns NaN, and you catch that with snan. The pin check is for everything attached to d0 to d5.

Tip

The order matters: check first, then read. A check after the l comes too late – the error has already happened.

Note

bdseal and bdnsal additionally jump into a subroutine with a return address. They come in week 19.

Diagram

Reading with l, writing with s Gas sensor (d0) Temperature 293.15 IC10 r0 = 293.15 Wall light (d1) On 1 l r0 d0 Temperature device → register s d1 On 1 value → device
l fetches a value from the device. If the device on the pin is missing, the chip gets stuck on that line – a check in front prevents it.

Exercise

Task

d0 holds a gas sensor, d1 a warning light, d2 an LED display.

  • Sensor present: warning light off, the display shows the temperature in °C
  • Sensor missing: warning light on, the display keeps its last value
  • The chip must never stop with an error

Use sdse or sdns and bdse or bdns.

Hints

Hint 1

First sdse present sensor, then flip it with seqz and write it to the warning light.

Hint 2

Before the l: bdns sensor start – if the sensor is missing, go back to the start.

Hint 3

The display is only written when the sensor is there – that way it keeps the last value.

Quiz

4 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere