IOx container applications are able to access the digital IO. There is a CLI for alarm contact command.
Router(config)# alarm contact ?
<0-4> Alarm contact number (0: Alarm port, 1-4: Digital I/O)
attach-to-iox Enable Digital IO Ports access from IOX
Router (config)# alarm contact attach-to-iox
Enabling the attach-to-iox command will provide complete control of all Digital IO ports to IOx. The ports will be exposed as four character devices
/dev/dio-[1-4] to IOX applications. You can use read/write functions to get/set values of the Digital IO ports.
If you wish to update the mode, you can write the mode value to the character device file. This is accomplished by IOCTL calls
to read/write the state, change mode, and read the true analog voltage of the port. Following this method, you can attach
analog sensors to the IR1800. All ports are initially set to Input mode with voltage pulled up to 3.3v.
The following are examples of IOCTL calls:
Read Digital IO Port:
cat /dev/dio-1
Write to Digital IO Port:
echo 0 > /dev/dio-1
echo 1 > /dev/dio-1
Change mode:echo out > /dev/dio-1
echo in > /dev/dio-1
List of IOCTLs supported:
DIO_GET_STATE = 0x1001
DIO_SET_STATE = 0x1002
DIO_GET_MODE = 0x1003
DIO_SET_MODE_OUTPUT = 0x1004
DIO_SET_MODE_INPUT = 0x1005
DIO_GET_THRESHOLD 0x1006
DIO_SET_THRESHOLD = 0x1007
DIO_GET_VOLTAGE = 0x1009
Read State using IOCTL:
import fcntl, array
file = open("/dev/dio-1","rw")
state = array.array('L',[0])
fcntl.ioctl(file, DIO_GET_STATE, state)
print(state[0])
Change mode using IOCTL:
import fcntl
file = open("/dev/dio-1","rw")
fcntl.ioctl(file, DIO_SET_MODE_OUTPUT, 0)