
The Moxa misc driver supported to access the relay/DI/DO, on board uart interface and programable LED control on DA-720, DA-682B, MC-1100, series embedded computer.
the driver is based on GPIO sysfs.

To use sysfs/gpio, you can write script to export/unexport

*** Manage GPIO from command line or script:

From the user level side this "operation" for reserve the GPIO is called "export" the GPIO. For make this export operation you simply need to echo the GPIO number you are interested to a special path as follow (change XX with the GPIO number you need):

** Export Example:
#!/bin/sh
export_gpio() {
    local TARGET_GPIOCHIP=moxa-gpio
    local GPIOCHIP_NAME=gpiochip
    local GPIO_FS_PATH=/sys/class/gpio
    local GPIO_EXPORT="export"

    if [ x"$1" == x"unexport" ]; then
        GPIO_EXPORT="unexport"
    fi

    #
    # Export GPIOs
    #
    ls $GPIO_FS_PATH | grep $GPIOCHIP_NAME | while read -r chip ; do
        GPIO_LABEL=$(cat $GPIO_FS_PATH/$chip/label)
        if [[ "$GPIO_LABEL" != *"$TARGET_GPIOCHIP"* ]]; then
            continue
        fi

        pinstart=$(echo $chip | sed s/$GPIOCHIP_NAME/\\n/g)
        count=$(cat $GPIO_FS_PATH/$chip/ngpio)
        for (( i=0; i<${count}; i++ )); do
            echo $((${pinstart}+${i})) > $GPIO_FS_PATH/$GPIO_EXPORT 2>/dev/null
        done
    done
}

# export
export_gpio

# unexport
export_gpio unexport

** Example to turn on/off programmable LED:
echo 1 > /sys/class/gpio/pled1/value
echo 0 > /sys/class/gpio/pled1/value

** Example to turn on/off relay:
echo 1 > /sys/class/gpio/relay1/value
echo 0 > /sys/class/gpio/relay1/value

** Example to turn on/off DO:
echo 1 > /sys/class/gpio/do1/value
echo 0 > /sys/class/gpio/do1/value

** Example get the current value:
cat /sys/class/gpio/pled1/value
cat /sys/class/gpio/di1/value

*** The convenience setinterface script to set /dev/ttySn, n=1,2, ... as RS-232/422/485 mode
** You can put this script to /usr/local/bin/:

# setinterface -h
Usage: /usr/bin/setinterface device-node [interface-no]
	device-node     - /dev/ttySn, n = 0, 1, ... . 
	interface-no    - following:
	none - to view now setting
	0 - set to RS232 interface
	1 - set to RS485-2WIRES interface
	2 - set to RS422 or RS485-4WIRES interface

** Set /dev/ttyS0 as RS485-2WIRES interface
# setinterface /dev/ttyS0 1

** Get /dev/ttyS0 interface
# setinterface /dev/ttyS0 
Now setting is RS485-2WIRES interface.

*** Manage GPIO in a C program:
** Set Example:
sprintf(buf, "/sys/class/gpio/pled1/value", gpio);

fd = open(buf, O_WRONLY);

// Set GPIO high status
write(fd, "1", 1); 
// Set GPIO low status 
write(fd, "0", 1); 

close(fd);


