DOS / Windows Starter Software

    for SiliconSoft Data Acquisition Hardware

    If you just can not stay away from getting your hands dirty with low-level code, we have this starter package of DOS and Windows software. The C library and DLL lets you control the data acquisition hardware directly. You can create all those special functions you want, such as, digital averaging, triggering on a level, vectored playback table, etc. If you want to use Visual Basic see this example program. See example C code for typical use of the library.

    Programmer's Kit
    The kit consists of 3.5" media and Programmer's Guide and includes source code of the Data Acquisition example program and description and use of the APIs and DLL for hardware control.

    Description of the files in the Windows / DOS starter code package:

      Windows library files:
    • ADC12AWN.DLL Windows DLL (place this in your \windows\system directory)
    • ADC12AWN.LIB Library for Windows ADC12AWN.DLL export functions
    • ADC12AWN.DEF Module definition file.
      DOS library files:
    • ADC12AMS.LIB DOS library for Microsoft Visual C v1.5 (compiler v8.0)
    • ADC12ABC.LIB DOS library for Borland C V4.5
      Windows / DOS Sample Code files:
    • ADCSAMP.C DOS Sample source file to demonstrate the use of the library functions for the AdcDongle 12A hardware. Make the executable using either of the DOS libraries.
    • ADC12AMS.LIB Microsoft Visual C or ADC12ABC.LIB for Borland C.
    • ADC12A_C.H Header file - protoypes for C.
    • ADCSAMP.MAK DOS make file to use with NMAKE.EXE utility for Microsoft Visual C.
    • MKSAMPBC.BAT DOS batch file to make the sample program using Borland C.
      Visual Basic files:
    • ADONG12A.EXE Compiled Visual Basic example.
    • ADNG001.FRM Example code for AdcDongle 12A
    • ADONG12A.MAK Make file for Visual Basic.

    The functions in the guide show you typical use to Initialize a hardware port, Calibrate a port, Power up the A/D, Get a sample, and Shut down the A/D.


    Microsoft C Example Code
    //*************************************************************************
    // adcsamp.c
    // Example code of using  the DOS library "adc12ams.lib" to get a sample
    // from the Adcdongle 12A.
    //*************************************************************************
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    #include <ctype.h>
    
    #include "adc12a_c.h"
    
    //** Function Prototypes **
    void main(void);
    int getportnbr(void);
    
    
    int samples[2000];
    
    
    //************************************************************************
    //*                     Start of main
    //************************************************************************
    
    void main()
    {
        int i, ret, portno;
        int cablelen = 6;           // length of cable from PC to Adcdongle is 6 feet.
        char ch, tmp[80];
        char fname[80];
        FILE *fptr;
    
        portno = getportnbr();
        
        printf("\nDoing port calibration.");
        ret = DoPortCalib12A(portno,cablelen);
        if (ret != 0) 
        { printf("\nInvalid port number, could not calibrate port");
          exit(0);
        }
        
        printf("\nInitialing COM port for use with AdcDongle.");
        Dacq12ACOMInit(portno);
    
        printf("\nTurning on power to AdcDongle 12A module.");
        Dacq12ACOMPowOn(portno);
    
    
        printf("\n\nReady to sample 2000 samples from channel 1 and store in array.");
        printf("\nPress a key when ready to start sampling.");
        getch();
    
        for (i=0; i<2000; i++)
           samples[i] = Get12ASampComPort(0,portno);
    
        printf("\nDone sampling, turning off power");
        Dacq12ACOMPowOff(portno);
    
        printf("\n\nEnter filename to save samples in: ");
        gets(fname);
    
        //* open file for read to see if file already exists.
    
        ch = 'Y';
        if((fptr = fopen(fname, "rb" )) != NULL )
        {  fclose(fptr);
           printf("\nFile %s already exists, ",fname);
           do
           {  printf("do you want to overwrite it? (Y/N): ");
              ch = _toupper(getch());
           } while ((ch != 'Y') && (ch != 'N'));
        }
    
        if (ch == 'Y')
        {  if ((fptr = fopen(fname, "wb" )) != NULL)
           {  printf("\n\nWriting samples to file %s",fname);
              fwrite(samples, sizeof(int), 2000, fptr);
              printf("\nDone writing sample, closing file.");
              fflush(fptr);
              fclose(fptr);
           }
           else
              printf("\nERROR: Could not open file: %s",fname);
       }
    
    }
    
    
    
    //**************************************************************************
    //* int getportnbr(void)
    //*
    //* This example function just prompts for and gets the port number,
    //* then checks the port number against a list of known COM ports.
    //**************************************************************************
    
    int getportnbr()
    {   
       char tmp[80];
       unsigned int portno;
    
       do
       { printf("\n\nWhat COM port is the AdcDongle 12A hardware attached? ");
         printf("\n\tCOM1: %4u (%X hex),\n\tCOM2: %4u (%X hex),\n\tCOM3: %4u (%X hex),\n\tCOM4: %4u (%X hex)? ",
          COMPORT1,COMPORT1,COMPORT2,COMPORT2,COMPORT3,COMPORT3,COMPORT4,COMPORT4);
         printf("\nPlease enter the decimal port number: ");
         gets(tmp);
         portno = atoi(tmp);
         switch(portno)
         {  case COMPORT1:
            case COMPORT2:
            case COMPORT3: 
            case COMPORT4: //* these are valid ports **
                           break;
    
            default:       //* Don't recognize port number **
                           portno = 0;
         }
    
         if (portno == 0)
         {  printf("\nThe Port number you entered is an invalid port number.");
            printf("\nPlease enter a different port number, or press CNTL-C to exit.");
            printf("\n");
         } 
       } while(portno == 0);
       
       return(portno);
    }
    // ******************************** End of C Example *********************
    
    '************************* Visual Basic Example ************
    ' This code segment example sets up the AdcDongle for a selected 
    ' COM port and starts the sampling process.
    '***********************************************************
    Option Explicit
    '*** Call this function once before using any Com Port ***
    Declare Function DoPortCalib12A% Lib "adc12awn.dll" (ByVal Port%, ByVal CableLen%)
    
    '*** Call this sub once before using selected Com Port ***
    Declare Sub Dacq12AComInit Lib "adc12awn.dll" (ByVal Port%)
    
    '*** Call this sub just before getting a sample from idled A/D
    Declare Sub Dacq12AComPowOn Lib "adc12awn.dll" (ByVal Port%)
    
    '*** Call this sub to idle A/D
    Declare Sub Dacq12AComPowOff Lib "adc12awn.dll" (ByVal Port%)
    
    '*** Call this function to get integer sample form A/D
    Declare Function Get12ASampComPort% Lib "adc12awn.dll" (ByVal Chan%, ByVal Port%)
    
    Dim Sample(7, 10000) As Integer      '8 channels x MaxSamples samples array
    Const MaxSamples = 10000
    Dim SampleNum&
    Dim SampleCount&         ' current sample
    Dim SampRate$            ' sampling timer setting
    Dim RecFlag%             ' ready to record?
    Dim RecPort%             ' input port
    Dim RecPortLabel$        ' input port label
    Dim RecPortNo$           ' relative port # 1- x
    Dim Msg$                 ' message box string
    Dim ret%                 ' function return value
    Dim StartTime$           ' start of recording
    Dim ProgramDir$          ' path to program
    Dim DataExt              ' data file count
    Dim UpdateDisplay
    Const ProgramName$ = "ADONG12A"
    'File open error codes
    Const Err_DeviceUnavailable = 68
    Const Err_DiskNotReady = 71, Err_FileAlreadyExists = 58
    Const Err_TooManyFiles = 67, Err_RenameAcrossDisks = 74
    Const Err_Path_FileAccessError = 75, Err_DeviceIO = 57
    Const Err_DiskFull = 61, Err_BadFileName = 64
    Const Err_BadFileNameOrNumber = 52, Err_FileNotFound = 53
    Const Err_PathDoesNotExist = 76, Err_BadFileMode = 54
    Const Err_FileAlreadyOpen = 55, Err_InputPastEndOfFile = 62
    Const MB_EXCLAIM = 48, MB_STOP = 16
    Declare Function GetModuleHandle Lib "Kernel" (ByVal lpModuleName As String) As Integer
    Declare Function GetModuleUsage% Lib "Kernel" (ByVal hProgram%)
    Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule%, ByVal FileName$, ByVal nSize%) As Integer
    
    Sub GetAdcData ()  ' Get a sample from selected channels
        ' and print and plot to screen.
        Dim AdcSamp&, ChNo%
        SampleCount& = SampleCount& + 1
        If SampleCount& > MaxSamples Then
            SampleCount& = 1
                Msg = "The sampled data buffer is full. "
                Msg = Msg + "Do you want to save to a file?"
                If MsgBox(Msg, 1, "Save Data?") = 2 Then
                    Exit Sub
                End If
            OpenFile (DataFileName)  'Save the test data
        End If
        If RecFlag% = False Then Exit Sub
        For ChNo% = 0 To 7
            AdcSamp& = Get12ASampComPort%(ChNo%, RecPort%)
            SampleTotal.Caption = SampleCount&
            If PodCh(ChNo%).Value = True Then       'show if Ch is selected
                If UpdateDisplay = 0 Then
                    gauge(ChNo%).Value = AdcSamp&
                    ch(ChNo%).Caption = Format(AdcSamp& / 1000, "#0.000 V")
                End If
                Sample(ChNo%, SampleCount&) = AdcSamp&
            Else
                If UpdateDisplay = 0 Then
                    gauge(ChNo%).Value = 0              'reset to 0
                    ch(ChNo%).Caption = "off"
                End If
               ' Sample(ChNo%, SampleCount&) = 0
            End If
        Next ChNo%
        DoEvents                                    'update gauges
    End Sub
    
    
    Sub InputPort_Load ()     'load list of possible PC serial ports
        RecordPort.AddItem "Com1: 3F8 hex", 0
        RecordPort.AddItem "Com2: 2F8 hex", 1
        RecordPort.AddItem "Com3: 3E8 hex", 2
        RecordPort.AddItem "Com4: 2E8 hex", 3
    End Sub
    
    
    Sub RecCntrl_click ()     'Start recording
        If RecPort% = 0 Then      'which port?
            MsgBox "No port selected."
            Exit Sub
        End If
        '************** Test port once before the first use. ****
        ret% = DoPortCalib12A(RecPort%, 0)   'test the port
        If ret% = -1 Then
            MsgBox "Port number is not valid."
            Exit Sub
        End If
        Erase Sample          'clear array
        RecFlag% = True            'start recording
        '************** Set up Com Port for I/O *****************
        Dacq12AComInit (RecPort%)  'set up selected port
    
        '************** Activate A/D ****************************
        Dacq12AComPowOn (RecPort%) 'Power up A/D
        
        PowerLbl.Caption = "On"
        SampleCount& = 0           'reset count
        StartTime$ = Time$
        SampleStartTime.Caption = StartTime$
        SampleStopTime.Caption = ""
    End Sub
    
    Sub RecordPort_Change ()
        'RecordPort.List
        Select Case RecordPort.ListIndex
            Case 0
               RecPortNo$ = "1"   'Com1
               RecPortLabel$ = "Serial Port 3F8"
               RecPort% = &H3F8
            Case 1
               RecPortNo$ = "2"   'Com2
               RecPortLabel$ = "Serial Port 2F8"
               RecPort% = &H2F8
            Case 2
               RecPortNo$ = "3"   'Com3
               RecPortLabel$ = "Serial Port 3E8"
               RecPort% = &H3E8
            Case 3
               RecPortNo$ = "4"   'Com4
               RecPortLabel$ = "Serial Port 2E8"
               RecPort% = &H2E8
        End Select
    End Sub
    
    Sub RecordPort_Click ()   'update selection
        RecordPort_Change
    End Sub
    
    Sub SampleRate_Click (Index As Integer, Value As Integer)
        Select Case Index
            Case 0
                Timer1.Interval = 1         '1000 samples/sec
                SampRate$ = "1000 samples/sec"
            Case 1
                Timer1.Interval = 10        '100 samples/sec
                SampRate$ = "100 samples/sec"
            Case 2
                Timer1.Interval = 100       '10 samples/sec
                SampRate$ = "10 samples/sec"
            Case 3
                Timer1.Interval = 1000      '1 sample/sec
                SampRate$ = "1 sample/sec"
            Case 4
                Timer1.Interval = 2000     '1 sample/2 secs
                SampRate$ = "1 sample/2 secs"
            Case 5
                Timer1.Interval = 5000    '1 sample/5 secs
                SampRate$ = "1 sample/5 secs"
            Case 6
                Timer1.Interval = 10000    '1 sample/10 secs
                SampRate$ = "1 sample/10 secs"
        End Select
        
        Dim RecTimeMS, RecTimeHr, RecTimeMin, RecTimeSec, RecTimeSecTotal
        Dim RecHr$, RecMin$, RecSec$
        RecTimeMS = MaxSamples * Timer1.Interval
        RecTimeSecTotal = (RecTimeMS / 1000)
        RecTimeSec = (RecTimeSecTotal Mod 60)
        RecTimeMin = (Fix(RecTimeSecTotal / 60)) Mod 60
        RecTimeHr = (Fix(RecTimeSecTotal / 3600)) Mod 60
        RecHr$ = Format(RecTimeHr, "00")
        RecMin$ = Format(RecTimeMin, "00")
        RecSec$ = Format(RecTimeSec, "00")
        MaxRecTime.Caption = RecHr$ + ":" + RecMin$ + ":" + RecSec$
    End Sub
    
    Sub StopCntrl_Click ()  ' Stop the recording
        RecFlag% = False
    
        '********** Idle A/D and Com Port ******************
        Dacq12AComPowOff (RecPort%)    'idle A/D
        
        PowerLbl.Caption = "Off"
        SampleStopTime.Caption = Time$
    End Sub
    
    '******************************* End of VB Example *********
    

    Contact:
    SiliconSoft Inc.
    www.siliconsoft.com
    San Jose, CA  USA
    
    Support Lines:
    Email: siliconsoft@pacbell.net
    Phone: (408)446-4521
    


    © Copyright 2000 by SiliconSoft Inc., San Jose, CA.