What you learn today
- Read ReferenceId
- l and s with an ID in a register
- ID via define
Two sensors hang in the boiler room. Both are called “Kessel” because they are averaged together. Now, though, you only want to read the one at the inlet. Names do not help here. Every device, however, has its own fixed number: the ReferenceId.
Reading the ReferenceId
The ReferenceId is a LogicType like any other, and every device can read it:
l id d0 ReferenceId # device on d0
lbn id SENSOR HASH("Einlass") ReferenceId Average # device by name
With lbn this only works if exactly one device matches. With two matches Average builds the mean of two numbers, and that is no longer a valid number. Without a match you get NaN.
l and s with an ID in a register
If a ReferenceId sits in a register, you put that register where a pin would normally go:
l temp id Temperature # reads the device with this number
s id On 1 # writes straight to it
The chip then looks up the device on the data network, without a pin and without a name. That helps when you want to address many identical devices one by one or run out of the six pins.
The ID via define
If you know the number, it may go straight into a define. A define name in the place of a device counts as a ReferenceId:
define BOILERIN 12345 # ReferenceId of the inlet sensor
l temp BOILERIN Temperature
You read the number once, for instance with s db Setting id onto the housing, and then enter it.
A ReferenceId only applies to this device in this save. If you remove the sensor and build it again, it gets a new number and your define points into nothing. Names survive a rebuild, numbers do not.
If the device for the number is missing, l stops with an error. How to check beforehand whether it is still there comes tomorrow with bdse and bdns. Until then you fetch the number anew every tick with lbn and check it with bnan.
Diagram
Exercise
Task
A gas sensor “Kessel” and an LED display “Kesselanzeige” sit on the network.
- Fetch the ReferenceId of both devices with
lbnevery tick. - Read the temperature with
lvia the ID and write it in °C withsvia the ID to the display. - If the sensor is missing: display −999. If the display is missing: write nothing. Never an error.
Hints
Hint 1
lbn disp DISPLAY HASH("Kesselanzeige") ReferenceId Average, then bnan disp start.
Hint 2
Same for the sensor, but on NaN jump to the output and set c to NOVALUE before.
Hint 3
Read with l temp id Temperature, write with s disp Setting c.
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