Changes between Version 1 and Version 2 of Docs/Prog/Manual/DeviceSupport/DIO


Ignore:
Timestamp:
11/30/09 09:19:35 (15 years ago)
Author:
Don Wilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/Prog/Manual/DeviceSupport/DIO

    v1 v2  
    22
    33== DIO ==
     4
     5=== DIO Events ===
     6
     7==== About ====
     8This document will guide the programmer through the process of creating and using a simple DIO Event using the DioEvent class provided in the standard library (lib825). DIO Events are processed by the mainboard in order to allow a level of redundancy. Should the OPI board kernel crash the mainboard will continue to provide relay functionality and will disable events when their thresholds are reached.
     9
     10==== The Code ====
     11To use a DIO event follow the example code below.
     12
     13{{{
     14#!Lineno
     15#!c
     16
     17// required include file from lib825
     18#include "DioEvent.h"
     19
     20int main() {
     21  // indicator startup (open mainboard, etc)
     22
     23  // dio example
     24  DioEvent event;
     25
     26  int scale = 1;
     27  int board = 0;
     28  int pin = 0x01;
     29  float fTarget = 250.00;
     30
     31  // set up the event
     32  int myEvent = event.addEvent(scale,EVENT_GROSS,EVENT_LESS,fTarget,board,pin);
     33
     34  // optionally add a conditional statement to it
     35  event.addCondition(myEvent,scale,EVENT_GROSS,EVENT_GREATER,0,EVENT_AND);
     36
     37  // start the individual event
     38  event.startEvent(myEvent);
     39
     40  // OR you can start all events
     41  event.startAll();
     42
     43  // indicator shutdown (close mainboard, etc)
     44  return 0;
     45}
     46}}}
     47
     48The above code would create an event that would enable board 0 (mainboard) pin 0 when the gross weight of scale 1 is less than 250.00 and greater than 0.00.
     49
     50=== DIO Counting ===
     51
     52==== Description ====
     53
     54Mainboard software 1.15 is required for counting feature. Kernel 2009-10-07 or later is required. All four inputs of the mainboard may be used for counting. The DIO cards allow any one of inputs 1 - 7 to be used for counting. Input 8 may also be used for counting. This allows for up to two inputs per DIO card to be used for counting.
     55
     56==== Example ====
     57
     58{{{
     59#!Lineno
     60#!c
     61
     62#include <stdio.h>
     63#include <stdlib.h>
     64
     65#include "kypdbeep.h"
     66#include "lcd.h"
     67#include "mnbdcomm.h"
     68
     69extern uint16 g_dio_count;
     70
     71extern int g_keycnt;
     72
     73extern uint8 g_keybuf[KEYBUF_SIZE];
     74extern struct set_dio_struct mnbd_set_dio;
     75
     76int main() {
     77
     78        char szCnt[41];
     79
     80        struct timespec delaytm;
     81        delaytm.tv_sec = 0;
     82        delaytm.tv_nsec = 1000000;  // 1 ms
     83
     84        InitLCD();
     85        ClearLCD();
     86
     87        OpenBeeper();
     88
     89        PrintLCD("DIO Counter Test\r");
     90        PrintLCD("Press '1' - '4' to toggle outputs");
     91
     92        int input;
     93
     94        // Note - all four input pins of mainboard may be used for counting, options card may use only one of inputs 1 - 7 for
     95        // counting and input 8 may always be used for counting.
     96
     97        OpenMnBd(MNBD_DEV);
     98
     99        struct {
     100                int init_cnt;
     101                int prescaler;
     102                DIOSetReg up_or_down;
     103                DIOSetReg low_or_high;
     104        } test[4] = {
     105                        // Experiment with different options to observe different counter behavior
     106                        //  Count  Prescaler    Count Up or down    Count on low to high, or high to low
     107                        {               0,      1,              dioSetCountUp,          dioSetCountLowToHigh },
     108                        {          10,          1,              dioSetCountDown,        dioSetCountLowToHigh },
     109                        {               0,              1,              dioSetCountUp,          dioSetCountHighToLow },
     110                        {         100,          2,              dioSetCountDown,        dioSetCountLowToHigh }
     111        };
     112
     113        for(input = 1; input <= 4; input++)
     114        {
     115                if(SetDIOCounter(MNBD_DEV, input, dioSetCount, test[input-1].init_cnt, WAIT_ACK) != MNBD_REQ_ACK_RCVD)
     116                {
     117                        PrintLCD("Cannot set count\r");
     118                }
     119
     120                if(SetDIOCounter(MNBD_DEV, input, dioSetPrescaler, test[input-1].prescaler, WAIT_ACK) != MNBD_REQ_ACK_RCVD)
     121                {
     122                        PrintLCD("Cannot set prescaler\r");
     123                }
     124
     125                if(SetDIOCounter(MNBD_DEV, input, test[input-1].up_or_down, 0, WAIT_ACK) != MNBD_REQ_ACK_RCVD)
     126                {
     127                        PrintLCD("Cannot set count up\r");
     128                }
     129
     130                if(SetDIOCounter(MNBD_DEV, input, test[input-1].low_or_high, 0, WAIT_ACK) != MNBD_REQ_ACK_RCVD)
     131                {
     132                        PrintLCD("Cannot set count low to high\r");
     133                }
     134
     135                if(SetDIOCounter(MNBD_DEV, input, dioEnableCounter, 0, WAIT_ACK) != MNBD_REQ_ACK_RCVD)
     136                {
     137                        PrintLCD("Cannot enable counter\r");
     138                }
     139        }
     140
     141        input = 1;
     142
     143        mnbd_set_dio.output = 0;
     144
     145        int req_cnt = 3000;
     146        int n;
     147        GetDIOCounter(MNBD_DEV, input, dioGetCount, NO_WAIT_ACK);
     148
     149        while(1)
     150        {
     151                ReadKeypad();
     152                if(g_keycnt > 0)
     153                {
     154                        g_keycnt = 0;
     155                        if(g_keybuf[0] == ESC)
     156                                break;
     157                        // Keypad keys "1" through "4" will toggle state of output which is looped back to input
     158                        // so that we can observe operation of counter
     159                        if(g_keybuf[0] >= '1' && g_keybuf[0] <= '4')
     160                        {
     161                                mnbd_set_dio.mask = 0x000F;
     162                                n = g_keybuf[0] - '1';
     163                                if(mnbd_set_dio.output & (1 << n))
     164                                {
     165                                        mnbd_set_dio.output &= ~(1 << n);
     166                                        LocateLCD(n * FONT_WIDTH * 10, FONT_HEIGHT * 3);
     167                                        PrintLCD("  ");
     168                                }
     169                                else
     170                                {
     171                                        mnbd_set_dio.output |= (1 << n);
     172                                        LocateLCD(n * FONT_WIDTH * 10, FONT_HEIGHT * 3);
     173                                        PrintLCD("on");
     174                                }
     175
     176                                MnBdRequest(MNBD_DEV, MNBD_REQ_SET_IO_STATUS, WAIT_ACK);
     177                                nanosleep(&delaytm, NULL);
     178
     179                                input = n + 1;
     180                                req_cnt = 1;
     181                        }
     182                }
     183
     184                req_cnt--;
     185                if(req_cnt == 0)
     186                {
     187                        GetDIOCounter(MNBD_DEV, input, dioGetCount, NO_WAIT_ACK);
     188                        req_cnt = 3000;
     189                }
     190
     191                nanosleep(&delaytm, NULL);
     192
     193                if(CheckDIOCountRcv(MNBD_DEV))
     194                {
     195                        sprintf(szCnt, "%6d", g_dio_count);
     196                        LocateLCD((input - 1) * FONT_WIDTH * 10, FONT_HEIGHT * 2);
     197                        PrintLCD(szCnt);
     198
     199                        if(input == 4)
     200                                input = 1;
     201                        else
     202                                input++;
     203
     204                        req_cnt = 5;
     205                }
     206        }
     207
     208        // Done - disable the counters
     209        for(input = 1; input <= 4; input++)
     210        {
     211                if(SetDIOCounter(MNBD_DEV, input, dioDisableCounter, 0, WAIT_ACK) != MNBD_REQ_ACK_RCVD)
     212                {
     213                        PrintLCD("Cannot disable counter\r");
     214                }
     215        }
     216
     217        CloseMnBd(MNBD_DEV);
     218
     219        ClearLCD();
     220
     221        return 0;
     222}
     223
     224
     225}}}
     226
     227== USB Support ==
     228The [wiki:WikiStart Cardinal 825] supports many USB devices such as Flash Drives, Printers (Cardinal supported only!), keyboards, and mice.
     229
     230=== USB Mass Storage ===
     231The 825 supports USB flash storage devices formatted with the FAT (file allocation table) and FAT32 file systems. From the serial command line when a USB storage device is inserted the display will appear similar to:
     232
     233[[Image(usb_insert.jpg)]]
     234
     235Use the mount command to access files on the USB flash drive:
     236
     237{{{
     238mount –t vfat /dev/sda1 /mnt/fl1
     239}}}
     240The files will then appear in the path /mnt/fl1 such as:
     241
     242[[Image(usb_mount.jpg)]]
     243
     244The file manager may be used to access USB flash drives. When the /mnt/fl1 folder is selected the file manager will automatically perform the mount command.
     245
     246[[Top]]
     247
     248=== USB Keyboards ===
     249As of kernel 2008-11-13 many USB keyboards should work with the 825. Simply plug the keyboard into an 825 USB connection.
     250
     251[[Image(usb_keyboard.jpg)]]
     252
     253Applications using the lib825 functions such as [[lib825:source:trunk/kypdbeep.cpp#L78 ReadKeypad]] or [[lib825:source:trunk/form.cpp#L1027 FormLCD] will automatically work with the USB keyboard. To test the keyboard without any app running type some characters on the keyboard and type:
     254
     255{{{
     256# cat /dev/usbkybd
     257}}}
     258Output:
     259
     260[[Image(usb_keyboard_test.jpg)]]
     261
     262The characters typed on the USB keyboard should show on the serial port terminal.
     263
     264[[Top]]
     265
     266=== USB Printing ===
     267usblp.ko device driver module for usb printing support. Type:
     268
     269{{{
     270# modprobe usblp
     271}}}
     272Kernel should be configured with /dev/usblp0 device node. If not type:
     273
     274{{{
     275# mknod /tmp/usblp0 c 180 0
     276}}}
     277''/dev is in read-only file system so device node can be created under /tmp instead''
     278
     279This creates the character device driver with major number 180 and minor number 0. This should work unmodified with USB printers that accept raw text for printing using a default font.
     280
     281A simple test is:
     282
     283{{{
     284# echo “ABCDEFGH” > /dev/usblp0
     285'''or'''
     286# echo “ABCDEFGH” > /tmp/usblp0
     287}}}
     288''Applications may be written to open “/dev/usblp0” to print to USB printer 0 instead of “/dev/ttyS1” to open COM2''
     289
     290==== Successful Tests ====
     291 * Okidata Microline 320 Turbo - ''Older versions of this printer do not have USB port''
     292 * Hewlett Packard !DeskJet 830C - ''Does not print page until filled so extra line feeds are required to fill the page to finish the print''
     293
     294==== Currently Developing ====
     295 * HP !LaserJet P1020
     296
     297==== Unsuccessful ====
     298 * HP !LaserJet P1006 - ''Research indicates this printer requires host to send firmware update file to printer, and does not accept raw text but requires XQX stream protocol''
     299
     300[[Top]]
     301
     302=== USB to PC communications ===
     303To load the driver for USB to PC communications type:
     304
     305{{{
     306# modprobe g_serial use_acm=1
     307}}}
     308When the 825 is connected to the PC it will be recognized by the PC and if the driver is not already installed it will prompt for it. Refer to “gadget_serial.txt”
     309
     310When the driver is installed the PC will appear to have another COM port. For testing on the PC you can then open a communications program such as HyperTerminal and set it to the appropriate COM port (which is actually a USB connection).
     311
     312On the serial connection to the indicator type:
     313
     314{{{
     315# echo “abcdefg” > /dev/ttygserial
     316}}}
     317“abcdefg” will then appear on the Hyperterm display.
     318
     319In HyperTerminal, type:
     320
     321{{{
     322123456
     323}}}
     324On the serial connection to the indicator type:
     325
     326{{{
     327# cat < /dev/ttygserial
     328}}}
     329The received characters “123456” from the PC will then be displayed.
     330
     331[[Top]]