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. You can also enable/disable the output buffer of the line with the io.enabled property (see Controlling Output Buffers). Here is a code example:

Tibbo C
low_high x = LOW;													// Declare a variable of type low_high
io.num = PL_IO_NUM_5;											// Select line #5
io.enabled = YES;      											// Enable this line
io.state = HIGH;       											// Set this line to HIGH
sys.debugprintline("I/O Line 5 State: " + io.state);	// Print the state of the line
io.state = LOW;													// Now set this line to LOW
sys.debugprintline("I/O Line 5 State: " + io.state);	// Print the state of the line
io.enabled = NO;													// Configure the line as input now
x = io.state;														// Read the state of the line
sys.debugprintline("I/O Line 5 State: " + io.state);	// Print the state of the line

Which would give you this output:

I/O Line 5 State: 1
I/O Line 5 State: 0
I/O Line 5 State: 1

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

Tibbo C
io.portnum = PL_IO_PORT_NUM_2;					// Select port #2
io.portenabled = 0xFF;								// This means that every port line's output buffer
															// will be enabled (&hFF=&b11111111)
io.portstate = 0x55;									// Output &h55: port lines 0, 2, 4, and 6 will be at HIGH,
															// the four remaining lines will be at LOW (&h55=&b01010101)
x = io.portstate;										// Read the port state
sys.debugprintline("I/O Port 2: 0x%X", x);	// Print the port state
x = io.portstate;										// Read the port state
io.portstate = 0;										// Output another value
 
sys.debugprintline("I/O Port 2: 0x%X", x);	// Print the port state
x = io.portstate;										// Read the port state
 
sys.debugprintline("I/O Port 2: 0x%X", x);	// Print the port state
 
io.portenabled = 0;									// Configure the port for input 
x = io.portstate;										// Read the port state
sys.debugprintline("I/O Port 2: 0x%X", x);	// Print the port state

Which would give you this output:

I/O Port 2: 0x55
I/O Port 2: 0x55
I/O Port 2: 0x0
I/O Port 2: 0xff

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.

I/O line and port names are defined by the pl_io_num and pl_io_port_num enums, respectively.

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.