C/C++ Sample source code
-- showing console style application for simplicity --
-----   Level 3   -----
( shows using M201_SP.INI for setting device configuration )   --




A little about this document
Quick jump to
Screenshots    .cpp code sample    .h header sample     About this document     Sngl / Multi - chan Log File sample     .INI File sample



This documentation was created using the sample application found within     .  
It's intended be used as a reference to understand the simplicity of interracting with the  Model 201   using the combination of VisualC++ and our   M201_SP.DLL   dynamically linked library. The code shown could easily be converted to the very basic ANSI C format  ( most of it already is just that )  since a console output   is used instead of a GUI interface. The Library is included in the archive linked to above and all available   function calls   are well documented.

The sample code documented here shows how to configure the device using a typical Windows  .INI  file  M201_SP.INI. That configuration file allows you to configure many parameters related scan channel selection, speed, filtering, and much more. It also shows how to use three separate function calls into the DLL:
          EX_SetDevToIniSetup( )
          EX_Run( )
          EX_Stop( )

This documention, shows the main source code file, the header file, and the data log file that is created. Follow the "Quick Jump" links just above to jump to each.
































































The Application Screenshots
Quick jump to
Screenshots    .cpp code sample    .h header sample     About this document     Sngl / Multi - chan Log File sample     .INI File sample



 
Starting Run
starts by looking for configuration within M201_SP.INI
see elsewhere for more information about the configuration file.
Running and logging to disk file
configuration was loaded from M201_SP.INI
and is now running and logging to disk file   ScanLog_0.txt
Run has stopped
log file closed
hit any key to close the DOS window

































































The C++ Source Code file
Quick jump to
Screenshots    .cpp code sample    .h header sample     About this document     Sngl / Multi - chan Log File sample     .INI File sample




// filename: mainSamp.cpp
// Demonstrates using M201_SP.INI  for startup configuration as well as the use of  "EX_Run()"  and  "EX_Stop()". 
// Also shows how to setup pointers (in header file) for calling DLL functions and the way to use those pointers.

#include <windows.h>
#include <stdlib.h>
#include <wtypes.h>
#include <conio.h>
#include <stdio.h>
#include "mainSamp.h"


BOOLEAN InitLibFuncs()
{
          hLib201 = LoadLibrary ("M201_SP.dll");   if( !hLib201 ) return FALSE;
          EX_SetDevToIniSetup = (P_DLL_EX_SetDevToIniSetup)GetProcAddress( hLib201, "EX_SetDevToIniSetup" );     if( !EX_SetDevToIniSetup ) return FALSE;
          EX_Run = (P_DLL_EX_RUN)GetProcAddress( hLib201, "EX_Run" );     if( !EX_Run ) return FALSE;
          EX_Stop = (P_DLL_EX_STOP)GetProcAddress( hLib201, "EX_Stop" );     if( !EX_Stop ) return FALSE;
          return TRUE;
}

int __cdecl main()
{
          if( !InitLibFuncs() ){ printf( "Failed to find load required DLL and/or find required functions" ); getch(); return 0;}
          printf("Success finding required functions\nStarting RUN - please wait. . .");

          if( !  EX_SetDevToIniSetup( )  ){ printf( "Failed call to read   M201_SP.INI" ); getch(); return 0;}
          if( !  EX_Run( )  ){ printf( "Failed calling EX_Run()" ); getch(); return 0;}
          printf( "\n\nRUNNING and logging to ScanLog_x.txt\nPress 'Q' to stop run and quit " );

          char cUserInputVal = NULL;
          while(( cUserInputVal != 'Q' ) && ( cUserInputVal != 'q' ))
          {
                    cUserInputVal = (char)getch();
                    switch(cUserInputVal)
                    {
                              case 'Q': case 'q':
                                        if( !  EX_Stop( )  )printf( "Failed calling EX_Stop()" );
                                        else printf( "\n\nSuccess calling EX_Stop()" );
                                        printf( "\npress any key to continue to exit\n" );   getch();   break;
                    }
          }
          return 1;
}









































The C++ Header file
Quick jump to
Screenshots    .cpp code sample    .h header sample     About this document     Sngl / Multi - chan Log File sample     .INI File sample



//filename: mainSamp.h

HMODULE hLib201 = NULL;

typedef   BOOLEAN( *P_DLL_EX_SetDevToIniSetup )  (void);
P_DLL_EX_SetDevToIniSetup   EX_SetDevToIniSetup = NULL;

typedef   BOOLEAN( *P_DLL_EX_RUN )  (void);
P_DLL_EX_RUN   EX_Run = NULL;

typedef   BOOLEAN( *P_DLL_EX_STOP )  (void);
P_DLL_EX_STOP   EX_Stop = NULL;










































Sample  M201_SP.INI  File
Quick jump to
Screenshots    .cpp code sample    .h header sample     About this document     Sngl / Multi - chan Log File sample     .INI File sample



;=============================================
;=============================================
;THIS FILE MUST BE PLACED IN WINDOWS DIRECTORY
;This file is used by file, "M201_SP.DLL"  but
; may also be used by  any  application  file.
;If you use it for your own  application avoid
; removing any of the following  entries since
; doing so may create  erroneous  behaviour of
; the the DLL.  Feel  free to add some of your 
; own entries or modify the values of the ones
; shown below to fit your needs.
;=============================================
;=============================================



[MAIN]
TXQUEUESIZE=16
RXQUEUESIZE=32000
;serial buffer sizes. Best to leave these
;as they are. (TX=16 RX=32000)


BAUD=0
;0 = 9600
;1 = 4800
;2 = 2400
;3 = 1200
;4 = 600
;5 = 300


comPort=0
;0 = COM1
;1 = COM2
;2 = COM3
;3 = COM4
;add 1 to value entered to get COM port number


remoteAvg=1
;remote averaging, in powers of 2
;valid entries limited to: 1, 2, 4, 8, 16, 32, 64, or 128


tScan=1
;type of scan 0 = single channel, 1 = normal, 2 = normal with calibration


singleChanScanMainChan=0
;main channel to use when in single-channels scan mode

singleChanScanSubChan=0
;sub channel to use when in single-channels scan mode


Rate=60
;internal data rate

ScanInterval=0
;Interval between scans.
;A value of zero will cause scanInterval to be set
; to minimum value by the DLL next time a scan is run.


channel=0
;Polled mode main channel  (0,1,2,3,4,5)

subChan=0
;Polled mode subChannel


wordCnt=3
;3 for 24 bit resolution, 2 for 16 bits


biPolar=1
;1= bipolar or 0= unipolar


filter=2
; =0 for 4 Hz filter
; =1 for 40 Hz filter
; =2 for 400 Hz filter, recommended for faster operation


gain=1
;gain factor (power of 2)
;valid entries limited to: 1, 2, 4, 8, 16, 32, 64, or 128


LogScans=1
;1 = Log scan data to disk only
;2 = Log scan data to memory only
;3 = Log scan data to memory and disk
;NOTE: the log file can become awkwardly large depending on scan rate & duration.



[SubChannels]
; Sub-Channels to scan are defined for each A/D channel.
; The sub channel values are 8-bit codes, also known as "external control codes".
; The upper nibble names the starting subchannel and the lower nibble names
;  the ending subchannel. An entry of 16 causes the channel to be skipped.
; For example, to scan sub-channels 2 through 4 first you set the low
;  channel 2 by multiplying it by 16 which causes it to shift over and
;  become the upper nibble of the channel code. Next you add on the high
;  channel 4 which sets it into the low nibble. The result of that process
;  would then be 24 HEX (note the "2 and 4"), 36 DECIMAL (hard to tell which
;  channels are set when shown in decimal format), or in binary  "0010 0100"
;  (note the "2" bit set in the upper nibble and "4" bit set in low nibble).
;  The process is the same for any channel combination - first you multiply 
;  the low channel by 16 and then add the high to it.

0 = 21	    ;equals 15 HEX so scan sub channels 1-5	
1 = 55      ;equals 37 HEX so scan sub channels 3-7
2 = 34      ;equals 22 HEX so scan sub channels 2-2  (ONLY 2 in other words)
3 = 16      ;equals 10 HEX code indicating this channel is inactive
4 = 16      ;equals 10 HEX code indicating this channel is inactive
5 = 16      ;equals 10 HEX code indicating this channel is inactive


[MISC]
IsEMF=1		; The channel labeling for the Model 201 is for programmers, and is 0 based
		; The labeling for the EMF16 is for users, so the first channel is #1
		; set to 0 for 0-based labeling.










































Sample Log File - Single Channel
Quick jump to
Screenshots    .cpp code sample    .h header sample     About this document     Sngl / Multi - chan Log File sample     .INI File sample



Time / s   	0 - 0    	
00000.0   	1.4847893	
00000.1   	1.4847744	
00000.2   	1.4847792	
00000.3   	1.4847816	
00000.3   	1.4847762	
00000.4   	1.4847774	
00000.5   	1.4847816	
00000.6   	1.4847816	
00000.7   	1.4847732	
00000.8   	1.4847816	
00000.9   	1.4847792	
00001.0   	1.4847720	
00001.0   	1.4847762	
00001.1   	1.4847726	
00001.2   	1.4847786	
00001.3   	1.4847738	
00001.4   	1.4847726	
00001.5   	1.4847762	
00001.6   	1.4847726	
00001.7   	1.4847828	
00001.7   	1.4847762	
00001.8   	1.4847792	
00001.9   	1.4847762	
00002.0   	1.4847756	
00002.1   	1.4847792	
00002.2   	1.4847780	
00002.3   	1.4847714	
00002.4   	1.4847756	
00002.4   	1.4847798	
00002.5   	1.4847756	
00002.6   	1.4847786	
00002.7   	1.4847738	
00002.8   	1.4847792	
00002.9   	1.4847786	

Minimal System Interval:	0.08678
Applied Interval:        	0.08704
Subcycles averaged:      	35
Started:                 	Fri Nov 05 14:41:36 2004
Finished:                	Fri Nov 05 14:41:39 2004
Experiment Description:  	none










































Sample Log File - Multiple Channels
Quick jump to
Screenshots    .cpp code sample    .h header sample     About this document     Sngl / Multi - chan Log File sample     .INI File sample



Time / s   	0 - 1    	0 - 2    	0 - 3    	0 - 4    	0 - 5    	1 - 3    	1 - 4    	2 - 2    	
00000.0   	1.4851362	1.4851309	1.4851213	1.4851291	1.4851160	-0.0000129	-0.0000087	-0.0000153	
00000.6   	1.4851189	1.4851160	1.4851172	1.4851130	1.4851148	-0.0000147	-0.0000171	-0.0000153	
00001.3   	1.4851225	1.4851160	1.4851082	1.4851124	1.4851225	-0.0000087	-0.0000117	-0.0000117	
00001.9   	1.4851201	1.4851130	1.4851160	1.4851112	1.4851082	-0.0000147	-0.0000290	-0.0000248	
00002.6   	1.4851166	1.4851130	1.4851070	1.4851070	1.4851183	-0.0000153	-0.0000189	-0.0000189	
00003.2   	1.4851130	1.4851094	1.4851219	1.4851082	1.4851124	-0.0000189	-0.0000242	-0.0000171	
00003.9   	1.4851118	1.4851070	1.4851160	1.4851154	1.4851124	-0.0000189	-0.0000153	-0.0000171	
00004.5   	1.4851160	1.4851046	1.4851130	1.4851082	1.4851136	-0.0000165	-0.0000195	-0.0000129	
00005.2   	1.4851136	1.4851172	1.4851094	1.4851136	1.4851124	-0.0000165	-0.0000177	-0.0000189	
00005.8   	1.4851028	1.4851070	1.4851118	1.4851183	1.4851130	-0.0000171	-0.0000165	-0.0000147	
00006.5   	1.4851100	1.4851118	1.4851178	1.4851070	1.4851118	-0.0000177	-0.0000189	-0.0000195	
00007.1   	1.4851011	1.4851118	1.4851112	1.4851076	1.4851058	-0.0000219	-0.0000272	-0.0000219	
00007.8   	1.4851100	1.4851106	1.4851052	1.4851124	1.4851058	-0.0000248	-0.0000231	-0.0000296	
00008.4   	1.4850951	1.4851058	1.4851046	1.4851100	1.4850939	-0.0000272	-0.0000213	-0.0000266	
00009.1   	1.4851011	1.4850969	1.4851118	1.4851112	1.4851005	-0.0000231	-0.0000201	-0.0000272	
00009.7   	1.4850969	1.4851183	1.4851070	1.4851118	1.4851118	-0.0000272	-0.0000201	-0.0000296	
00010.4   	1.4851100	1.4851040	1.4851100	1.4851124	1.4851017	-0.0000225	-0.0000296	-0.0000254	
00011.0   	1.4851130	1.4851005	1.4851028	1.4851094	1.4851124	-0.0000201	-0.0000195	-0.0000177	
00011.6   	1.4851028	1.4851106	1.4851118	1.4851100	1.4851118	-0.0000189	-0.0000213	-0.0000266	
00012.3   	1.4851058	1.4851130	1.4851058	1.4851183	1.4851154	-0.0000266	-0.0000296	-0.0000201	
00012.9   	1.4851070	1.4851106	1.4851100	1.4851118	1.4851094	-0.0000248	-0.0000308	-0.0000278	
00013.6   	1.4851052	1.4851106	1.4851118	1.4851028	1.4851070	-0.0000266	-0.0000302	-0.0000266	
00014.2   	1.4850981	1.4851058	1.4851040	1.4850987	1.4851011	-0.0000201	-0.0000278	-0.0000320	
00014.9   	1.4850969	1.4851040	1.4850963	1.4851094	1.4851058	-0.0000213	-0.0000308	-0.0000308	
00015.5   	1.4850993	1.4851100	1.4851118	1.4851094	1.4851100	-0.0000171	-0.0000266	-0.0000171	
00016.2   	1.4851023	1.4851142	1.4851088	1.4851094	1.4851148	-0.0000177	-0.0000213	-0.0000254	
00016.8   	1.4850981	1.4851005	1.4851094	1.4851118	1.4851094	-0.0000225	-0.0000266	-0.0000308	
00017.5   	1.4850981	1.4851017	1.4851112	1.4851118	1.4851100	-0.0000225	-0.0000254	-0.0000272	
00018.1   	1.4850981	1.4851100	1.4851118	1.4850951	1.4851106	-0.0000266	-0.0000272	-0.0000296	
00018.8   	1.4851005	1.4850981	1.4851094	1.4851011	1.4850951	-0.0000266	-0.0000332	-0.0000290	

Minimal System Interval:	0.64640
Applied Interval:        	0.64691
Subcycles averaged:      	31
Started:                 	Tue Nov 09 11:58:34 2004
Finished:                	Tue Nov 09 11:58:58 2004
Experiment Description:  	none
















Contact us for sales or technical assistance
lawsnlab@lawsonlabs.com

on the web
www.lawsonlabs.com

© Lawson Labs Inc. All rights reserved
Last modified 11-8-04 Tim Van Dusen