Line/Port Manipulation With Preselection

I/O line manipulation with preselection works like this: you first select the line you want to work with using the io.num property. You can then read and set the state of this line using the io.state property. On certain platforms, you can also enable/disable the output buffer of the line with the io.enabled property — more on this in the Controlling Output Buffers topic. Here is a code example:

Tibbo BASIC
io.num=PL_IO_NUM_5 'select line #5
io.enabled=YES 'enable this line
io.state=HIGH 'set this line to HIGH
io.state=LOW 'now set this line to LOW
io.enabled=NO 'configure the line as input now
x=io.state 'read the state of the line

The same can be done with ports — use the io.portnum, io.portstate, and io.portenabled properties to achieve this:

Tibbo BASIC
io.portnum=2 'select port #2
io.portenabled=&hFF 'this means that every port line's output buffer will be enabled (&hFF=&b11111111)
'output &h55: port lines 0, 2, 4, and 6 will be at HIGH, 4 remaining lines will be at LOW (&h55=&b01010101)
io.portstate=&h55
'output another value
op.portstate=0
'configure the port for input and read its state
io.portenabled=0
x=io.portstate

This way of controlling the lines/ports of your device is good when you are going to manipulate the same line/port repeatedly. Performance is improved because you select the line/port once and then address this line/port as many times as you need.

Note that I/O line and port names are platform-specific and are defined by the pl_io_num  and pl_io_port_num enums, respectively. The declarations for these enums can be found in your device's platform documentation (for example, the EM1000's is here).

On many devices, a number of I/O lines may be shared with inputs/outputs of special function blocks (serial ports, etc.). When a special function block is enabled, the I/O lines it uses cannot (should not) be manipulated though the io. object.