Skip to content

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.

Parameters: alias: string. Gives: Drive, or an error. Errors: device.type, device.unavailable, device.unknown, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.read. Cost: 16 operations.

drive, err = drives.from("gate")

drive.has(key)

Test whether the drive stores a key.

Parameters: key: string. Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.read. Cost: 16 operations.

found, err = drive.has("history")

drive.info()

Describe the drive: id, label, target, device, kind, revision, state, running and storage usage.

Gives: dict, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.read. Cost: 16 operations.

meta, err = drive.info()

drive.keys()

List the drive's stored keys.

Gives: list, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.read. Cost: 16 operations.

keys, err = drive.keys()

drive.program()

Read the drive's program source.

Gives: string, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.read. Cost: 16 operations.

source, err = drive.program()

drive.read(key)

Read a copy of one stored value. A missing key returns storage.missing.

Parameters: key: string. Gives: any value, or an error. Errors: device.type, device.unavailable, device.unknown, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied, storage.missing. Capability: drives.read. Cost: 32 operations.

history, err = drive.read("history")

drive.restart()

Request a restart of the drive's program with its saved globals.

Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.control. Cost: 16 operations.

ok, err = drive.restart()

drive.start()

Request that the drive's program start. Applied before the next scheduler tick.

Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.control. Cost: 16 operations.

ok, err = drive.start()

drive.status()

Read the program state, last error, statistics and who started it.

Gives: dict, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.read. Cost: 16 operations.

status, err = drive.status()

drive.stop()

Request that the drive's program stop, saving its globals.

Gives: bool, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.control. Cost: 16 operations.

ok, err = drive.stop()

drive.usage()

Read storage used, capacity, entries and maxEntries.

Gives: dict, or an error. Errors: device.type, device.unavailable, device.unknown, drive.busy, drive.damaged, drive.in_use, drive.missing, drive.removed, host.denied. Capability: drives.read. Cost: 16 operations.

usage, err = drive.usage()
  • 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. Ask drives.from again.
  • start, stop and restart are 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.
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()
}
}