| | 4 | |
| | 5 | === Digital I/O === |
| | 6 | {{{ |
| | 7 | echo “L000000020000000F” > /dev/mnbd |
| | 8 | }}} |
| | 9 | This sets the state of the mainboard digital outputs. The “L” is the command, the following 8 characters or four hexadecimal bytes represent the state desired. The final 8 characters or four hexadecimal bytes represent a mask of which outputs are to be affected. In this example “F” is used as the mask to set the state of all four on-board outputs. |
| | 10 | |
| | 11 | {{{ |
| | 12 | # echo “I” > /dev/mnbd |
| | 13 | }}} |
| | 14 | This requests the status of the mainboard digital I/O. |
| | 15 | |
| | 16 | {{{ |
| | 17 | # cat < /dev/mnbd |
| | 18 | }}} |
| | 19 | response: |
| | 20 | |
| | 21 | {{{ |
| | 22 | # IA000000000 |
| | 23 | }}} |
| | 24 | The last 8 character of the response are hexadecimal digits. Of these the first 4 digits are the state of the digital inputs. The final 4 digits are the state of the outputs. If the input 1 only is active the response is: |
| | 25 | |
| | 26 | {{{ |
| | 27 | # IA000010000 |
| | 28 | }}} |
| | 29 | If inputs one and two are active the response is: |
| | 30 | |
| | 31 | {{{ |
| | 32 | # IA000030000 |
| | 33 | }}} |
| | 34 | If inputs one, two, three, and four are active the response is: |
| | 35 | |
| | 36 | {{{ |
| | 37 | # IA0000F0000 |
| | 38 | }}} |
| | 39 | Only a single hexadecimal digit is needed to represent the state of the four mainboard inputs. |
| | 40 | |
| | 41 | ||Response||Input 1||Input 2||Input 3||Input 4|| |
| | 42 | ||0||Off||Off||Off||Off|| |
| | 43 | ||1||On||Off||Off||Off|| |
| | 44 | ||2||Off||On||Off||Off|| |
| | 45 | ||3||On||On||Off||Off|| |
| | 46 | ||4||Off||Off||On||Off|| |
| | 47 | ||5||On||Off||On||Off|| |
| | 48 | ||6||Off||On||On||Off|| |
| | 49 | ||7||On||On||On||Off|| |
| | 50 | ||8||Off||Off||Off||On|| |
| | 51 | ||9||On||Off||Off||On|| |
| | 52 | ||A||Off||On||Off||On|| |
| | 53 | ||B||On||On||Off||On|| |
| | 54 | ||C||Off||Off||On||On|| |
| | 55 | ||D||On||Off||On||On|| |
| | 56 | ||E||Off||On||On||On|| |
| | 57 | ||F||On||On||On||On|| |
| | 58 | |
| | 59 | ''For additional structure formats refer to MainboardProtocol'' |
| | 60 | |
| | 61 | The lib825 library provides functions to facilitate applications performing digital I/O tasks. |
| | 62 | |
| | 63 | {{{ |
| | 64 | #!Lineno |
| | 65 | #!c |
| | 66 | extern uint32 g_nRepIOIntv; |
| | 67 | |
| | 68 | extern struct set_dio_struct mnbd_set_dio; |
| | 69 | extern struct mnbd_dio_status_struct mnbd_dio_status; |
| | 70 | |
| | 71 | // Read I/O status every 100 ms |
| | 72 | g_nRepIOIntv = 100; |
| | 73 | MnBdRequest(MNBD_DEV, MNBD_REQ_REP_IO_STATUS, NO_WAIT_ACK); |
| | 74 | |
| | 75 | sleep(1); |
| | 76 | |
| | 77 | while(1) |
| | 78 | { |
| | 79 | if(CheckIORcv(MNBD_DEV)) |
| | 80 | { |
| | 81 | if((mnbd_dio_status.inputs & 1) != 0) |
| | 82 | { |
| | 83 | // Input 1 active -- Set output 1 and break out of loop |
| | 84 | |
| | 85 | mnbd_set_dio.output = 0x01; |
| | 86 | mnbd_set_dio.mask = 0x0F; |
| | 87 | MnBdRequest(0, MNBD_REQ_SET_IO_STATUS, NO_WAIT_ACK); |
| | 88 | break; |
| | 89 | } |
| | 90 | } |
| | 91 | } |
| | 92 | |
| | 93 | // Stop repeating I/O status |
| | 94 | g_nRepIOIntv = 0; |
| | 95 | MnBdRequest(MNBD_DEV, MNBD_REQ_REP_IO_STATUS, NO_WAIT_ACK); |
| | 96 | |
| | 97 | }}} |
| | 98 | |
| | 99 | For digital I/O event operations refer to the DioEvent class. |