Drives from a computer
A computer program can look into the drive installed in a programmable device on its network: read its program and stored data, check its status, and ask it to start, stop or restart. It cannot write or delete the drive’s data.
drives.from(alias)
Resolve the drive installed in a named programmable device.
drive, err = drives.from("gate")Drive methods
Section titled “Drive methods”drive.has(key)
Test whether the drive stores a key.
found, err = drive.has("history")drive.info()
Describe the drive: id, label, target, device, kind, revision, state, running and storage usage.
meta, err = drive.info()drive.keys()
List the drive's stored keys.
keys, err = drive.keys()drive.program()
Read the drive's program source.
source, err = drive.program()drive.read(key)
Read a copy of one stored value. A missing key returns storage.missing.
history, err = drive.read("history")drive.restart()
Request a restart of the drive's program with its saved globals.
ok, err = drive.restart()drive.start()
Request that the drive's program start. Applied before the next scheduler tick.
ok, err = drive.start()drive.status()
Read the program state, last error, statistics and who started it.
status, err = drive.status()drive.stop()
Request that the drive's program stop, saving its globals.
ok, err = drive.stop()drive.usage()
Read storage used, capacity, entries and maxEntries.
usage, err = drive.usage()Behavior
Section titled “Behavior”- The handle names the drive, not the device. If the drive is removed, even if another drive is put in, the handle
fails with
drive.removed. Askdrives.fromagain. start,stopandrestartare requests. They run before the next tick, never during the current handler, and are limited per tick (drive.busy). A remote start uses the network owner’s access.- The device must be a reachable member of the computer’s network.
Example
Section titled “Example”on timer.every(1200) { drive, err = drives.from("gate") if err is not nil { print("Gate drive: " + err.code) return } status = drive.status() if not status.running { print("The gate program stopped: " + str(status.error)) drive.restart() }}