RISCOS.com

www.riscos.com Technical Support:
Programmer's Reference Manual

 

System devices


System devices

The SystemDevices module provides a number of system devices, which behave like files in some ways. You can use them anywhere you would normally use a file name as a source of input, or as a destination for output. They include:

System devices suitable for input

kbd: - the keyboard, reading a line at a time using OS_ReadLine (this allows editing using Delete, Ctrl-U, and other keys)

rawkbd: - the keyboard, reading a character at a time using OS_ReadC

null: - the 'null device', which effectively gives no input

System devices suitable for output

vdu: - the screen, using GSRead format passed to OS_WriteC

rawvdu: - the screen, via the VDU drivers and OS_WriteC

printer: - the currently configured printer

netprint: - the currently configured network printer driver (provided by the NetPrint module)

null: - the 'null device', which swallows all output

An error is given if the specified system device is not present; for example, if the SystemDevices module is not present.

Other devices

There are also two devices provided as a part of the DeviceFS system:

serial: - serial port; see the chapter entitled Serial device

parallel: - parallel port; see the chapter entitled Parallel device

Redirection

These system devices can be useful with commands such as *Copy, and the redirection operators (> and <):

*Copy myfile printer: - Send myfile to the printer

*Cat { > printer: } - List the files in the current directory to the printer

Note: When using *Copy to send a file to the printer: system device, you should ensure you are using the F copy option. For example:

*Copy myfile printer: ~CF~V

Suppressing output using null:

You can use the system device null: to suppress unwanted output from a command script or program:

*myprogram { > null: } - Run myprogram with no output

Input devices

You can only open one file for input on kbd: at once as it has buffered input; normal line editing facilities are available. If you try to open kbd: a second time whilst the first file is open, you will get returned a handle of 0, or an error if the appropriate bit is set in the open mode passed to FileSwitch. Ctrl-D in the input line will yield EOF when it is read from the buffer.

You can open rawkbd: as many times as you like, even if a file is open on kbd:. It uses XOS_ReadC (without echoing to the screen) to read characters. No EOF condition exists on rawkbd:; the program reading it must detect an input value/pattern and stop on that.

No files exist on any of these devices. If you call OS_File 5 on the devices it will always return object type 0, so you cannot use them for input to programs that need to load an entire file at once for processing.

netprint:

The netprint: system device is more sophisticated than other ones. As well as using it in place of file names, you can also use it with certain commands that normally use the name of a filing system.

printer:

The printer: device allows various special fields, to refer to the different types of printers. These are:

  • printer#sink: and printer#null:, which are synonyms
  • printer#parallel: and printer#centronics:, which are synonyms
  • printer#serial: and printer#rs423:, which are synonyms
  • printer#user:, which refers to printer type 3
  • printer#n:, which refers to printer type n, where n is in the range 0 - 255.

You can open multiple files on printer:, provided they are on different devices and using different buffers.

Other output devices

You can open as many files as you wish on the other output devices, which are:

null:, vdu:, and rawvdu:

For example:

H% = OPENOUT "rawvdu:"
SYS "OS_Byte",199,H%,0
type here...
*Spool

When you type everything is sent to the vdu, which outputs it and then uses XOS_BPut to send it to the spool file handle. This in turn sends it (through another mechanism, OS_PrintChar) to the screen again! The *Spool at the end clears up.

In addition to byte-oriented operations, you are allowed to perform file save operations on the output devices.

The difference between vdu: and rawvdu: is that the former is filtered using the configured DumpFormat, whereas the latter sends its characters straight to the VDU drivers.

The RISC OS 2 serial device

RISC OS 2 provided its serial port device as a part of the SystemDevices module. It has since been reimplemented as a device; see the chapter entitled Serial device.

The RISC OS 2 serial device (serial:) is bidirectional, has no EOF condition, and allows multiple files to be opened.

This edition Copyright © 3QD Developments Ltd 2015
Last Edit: Tue,03 Nov 2015