The I/O module supports the following functions:
Send a command to a techage block via the I/O module (see commands).
- port is the I/O module port number
- topic specifies the data to be sent and is a numeric value.
- payload is used for additional data.
If not needed, you can provide an empty string (
""
).-
topic < 64: payload is an array
-
topic >= 64: payload is a string
-
send_cmnd(port, topic, payload)
send_cmnd
returns:
0
if successful1
if destination is unknown2
if topic or payload is unknown or invalid3
if command failed for other reasons
Request information from a techage block. The response is return by reference in form of an array or string. See commands.
- port is the I/O module port number
- *topic specifies the data to be read and is a numeric value.
- payload is an array and is used for additional data.
If not needed, you can provide
NULL
. - response is an array for the response data. The array must be defined large enough to hold the response data.
request_data(port, topic, payload, response)
request_data
returns:
0
if successful1
if destination is unknown2
if topic or payload is unknown or invalid3
if command failed for other reasons
The Input module supports the following functions:
Read the port number of the input module that received a command. Each command sent to an input module triggers an event on the controller and provides the port number of the received command.
get_next_inp_port()
The function returns a port number or 0xffff
if there is no pending event.
Read an input value from the given port.
- port is the Input Module port number
input(port)
The function returns the received value.
Clear the display.
- port is the I/O module port number
clear_screen(port)
Add a new line to the display.
- port is the I/O module port number
- text is the text for one line
append_line(port, text)
Overwrite a text line with the given string.
- port is the I/O module port number
- row ist the display line/row (1-5)
- text is the text for one line
write_line(port, row, text)
The following examples require ine I/O Module connected to the Beduino controller.
Note
Octal strings can be used as alternative to an array:
"\001\002"
corresponds to{1, 2}
Signal tower on port #1:
import "lib/techage.c"
func init() {
}
func loop() {
send_cmnd(1, 2, "\000"); // off
sleep(5); // sleep 5 cycles
send_cmnd(1, 2, "\001"); // green
sleep(5);
send_cmnd(1, 2, "\002"); // amber
sleep(5);
send_cmnd(1, 2, "\003"); // red
sleep(5);
}
Example to play a sound with Sound Block on port #0:
import "sys/stdlib.asm"
import "lib/techage.c"
const CMD_SOUND_BLOCK = 14;
const CMD_START_STOP = 1;
var sound[] = {2, 36};
var volume[] = {1, 5};
var start[] = {1};
func init() {
send_cmnd(0, CMD_SOUND_BLOCK, sound);
send_cmnd(0, CMD_SOUND_BLOCK, volume);
send_cmnd(0, CMD_START_STOP, start);
}
func loop() {
halt();
}
The same example in compact form (based on octal strings):
import "sys/stdlib.asm"
import "lib/techage.c"
func init() {
send_cmnd(0, 14, "\002\044"); // select sound file
send_cmnd(0, 14, "\001\005"); // set volume
send_cmnd(0, 1, "\001"); // play sound
}
func loop() {
halt();
}
Example to read the machine state on port #2:
import "sys/stdio.asm"
import "lib/techage.c"
func init() {
setstdout(1); // use terminal windows for stdout
}
func loop() {
var resp;
var sts;
sts = request_data(2, 129, 0, &resp);
if(sts == 0) {
putnum(resp);
} else{
putstr("err ");
putnum(sts);
}
putstr("\n");
sleep(5);
}