www.riscos.com Technical Support: |
|
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:
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
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.
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
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:
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.
The printer: device allows various special fields, to refer to the different types of printers. These are:
You can open multiple files on printer:, provided they are on different devices and using different buffers.
You can open as many files as you wish on the other output devices, which are:
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.
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.