<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Das Problem beim Kompilieren]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich entwickele das vollständige richtige Programm , um in DLL umwandeln und weiterhin damit auf LabView umstellen zu können. Aber beim Kompilieren kommen immer die Fehlermeldungen , die mich verwirren</p>
<pre><code>//#define PLAY_WITH_KEEPALIVE
#include &quot;C:\Programme\National Instruments\LabVIEW 7.0\cintools\extcode.h&quot;
#pragma comment(lib, &quot;libnodave.lib&quot;)
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#define BCCWIN
#include &quot;nodavesimple.h&quot;
#include &quot;openSocket.h&quot;

#ifdef LINUX
#include &lt;unistd.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;fcntl.h&gt;
#define UNIX_STYLE
#endif

#ifdef BCCWIN
#include &lt;time.h&gt;
void usage(void);
void wait(void);

#define WIN_STYLE    
#endif

#ifdef PLAY_WITH_KEEPALIVE
#include &lt;sys/socket.h&gt;
#endif
#include &lt;errno.h&gt;
//************************************************************************
void readSZL(daveConnection *dc,int id, int index)
{
    int res, SZLid, indx, SZcount, SZlen,i,j,len;
    uc * d,*dd;
    uc ddd[3000];
    printf(&quot;Trying to read SZL-ID %04X index %02X.\n&quot;,id,index);
    res=daveReadSZL(dc,id,index, ddd, 3000);
    printf(&quot;Function result: %d %s len:%d\n&quot;,res,daveStrerror(res),dc-&gt;AnswLen);
//    _daveDump(&quot;Data&quot;,dc-&gt;resultPointer,dc-&gt;AnswLen);
    _daveDump(&quot;Data&quot;,ddd,dc-&gt;AnswLen);

    if ((dc-&gt;AnswLen)&gt;=4) {
	d=ddd;
        dd=ddd;
	dd+=8;
	len=dc-&gt;AnswLen-8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    if(len&gt;0){
	    for (i=0;i&lt;SZcount;i++){
		if(len&gt;0){
		for (j=0; j&lt;SZlen; j++){
		    if(len&gt;0){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		    }
		    len--;
		}
		printf(&quot;\n&quot;);
		}
	    }
	    }
	}
    }
    printf(&quot;\n&quot;);
}    

void readSZLAll(daveConnection *dc) {
    uc SzlList[1000];
    int res, SZLid, indx, SZcount, SZlen,i,j, rid, rind;
    uc * d,*dd;

    res=daveReadSZL(dc,0,0,SzlList, 1000);
    printf(&quot;%d %d\n&quot;,res,dc-&gt;AnswLen);
    if ((dc-&gt;AnswLen)&gt;=4) {
	d=dc-&gt;resultPointer;
        dd=SzlList;
	dd+=8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    for (i=0;i&lt;SZcount;i++){
//		rind=*dd;
//		rid=*(dd+1); 
		rid=*(dd+1)+256*(*dd); 
		rind=0;
		printf(&quot;ID:%04X Index:%02X\n&quot;,rid,rind);
		readSZL(dc, rid, rind);
		for (j=0; j&lt;SZlen; j++){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		}
		printf(&quot;\nID:%04X Index:%02X\n&quot;,rid,rind);

	    }
	}
    }
    printf(&quot;\n&quot;);
}

void wait() {
    uc c;
    printf(&quot;Press return to continue.\n&quot;);
#ifdef UNIX_STYLE
    read(0,&amp;c,1);
#endif
}    
 void usage()
{
    printf(&quot;Usage: testISO_TCP [-d] [-w] IP-Address of CP\n&quot;);
    printf(&quot;-2 uses a protocol variant for the CP243. You need to set it, if you use such a CP.\n&quot;);
    printf(&quot;-w will try to write to Flag words. It will overwrite FB0 to FB15 (MB0 to MB15) !\n&quot;);
    printf(&quot;-d will produce a lot of debug messages.\n&quot;);
    printf(&quot;-b will run benchmarks. Specify -b and -w to run write benchmarks.\n&quot;);
    printf(&quot;-m will run a test for multiple variable reads.\n&quot;);
    printf(&quot;-c will write 0 to the PLC memory used in write tests.\n&quot;);
    printf(&quot;-z will read some SZL list items (diagnostic information).\n&quot;
	    &quot;  Works 300 and 400 family only.\n&quot;);
    printf(&quot;-s stops the PLC.\n&quot;);
    printf(&quot;-r tries to put the PLC in run mode.\n&quot;);
    printf(&quot;--readout read program and data blocks from PLC.\n&quot;);
    printf(&quot;--readoutall read all program and data blocks from PLC. Includes SFBs and SFCs.\n&quot;);
    printf(&quot;--slot=&lt;number&gt; sets slot for PLC (default is 2).\n&quot;);
    printf(&quot;--debug=&lt;number&gt; will set daveDebug to number.\n&quot;);
    printf(&quot;Example: testISO_TCP -w 192.168.19.1\n&quot;);
}

void loadBlocksOfType(daveConnection * dc, int blockType) {
    int j, i, uploadID, len, more;
#ifdef UNIX_STYLE
    int fd;
#endif	        
#ifdef WIN_STYLE	    
    HANDLE fd;
    unsigned long res;
#endif	        
    char blockName [20];
    uc blockBuffer[20000],*bb;
    daveBlockEntry dbe[256];   
    j=daveListBlocksOfType(dc, blockType, dbe);
    if (j&lt;0) {
	printf(&quot;error %d = %s\n&quot;,-j,daveStrerror(-j));
	return;
    }
    printf(&quot;%d blocks of type %s\n&quot;,j,daveBlockName(blockType));
    for (i=0; i&lt;j; i++) {
	printf(&quot;%s%d  %d %d\n&quot;,
	    daveBlockName(blockType),
	    dbe[i].number, dbe[i].type[0],dbe[i].type[1]);	
	bb=blockBuffer;
	len=0;
	if (0==initUpload(dc, blockType, dbe[i].number, &amp;uploadID)) {
    	    do {
		doUpload(dc,&amp;more,&amp;bb,&amp;len,uploadID);
	    } while (more);
	    sprintf(blockName,&quot;%s%d.mc7&quot;,daveBlockName(blockType), dbe[i].number);	
#ifdef UNIX_STYLE
    	    fd=open(blockName,O_RDWR|O_CREAT|O_TRUNC,0644);
    	    write(fd, blockBuffer, len);
    	    close(fd);
#endif	    
#ifdef WIN_STYLE
	    fd = CreateFile(blockName,
    	      GENERIC_WRITE, 0, 0, 2,
    		FILE_FLAG_WRITE_THROUGH, 0);
    	    WriteFile(fd, blockBuffer, len, &amp;res, NULL);
    	    CloseHandle(fd);
#endif	    

    	    endUpload(dc,uploadID);
	}    
    }
}

#include &quot;benchmark.c&quot;

int main(int argc, char **argv) {
  int const start = 12;
  int a,b,c,menu,dbnr,area,bit,byte,bitp,bytep,adrPos,doWrite,doBenchmark, doSZLread, doMultiple, doClear,
	res, useProtocol,doSZLreadAll, doRun, doStop, doReadout, doSFBandSFC,
	doNewfunctions, saveDebug,
	useSlot;
#ifdef PLAY_WITH_KEEPALIVE    	
    int opt;
#endif    
    float d;
    daveInterface * di;
    daveConnection * dc;
    _daveOSserialType fds;
    PDU p;
    daveResultSet rs;

    daveSetDebug(daveDebugPrintErrors);
    adrPos=1;
    doWrite=0;
    doBenchmark=0;
    doMultiple=0;
    doClear=0;
    doSZLread=0;
    doSZLreadAll=0;
    doRun=0;
    doStop=0;
    doReadout=0;
    doSFBandSFC=0;
    doNewfunctions=0;

    useProtocol=daveProtoISOTCP;
    useSlot=2;

    if (argc&lt;2) {
	usage();
	exit(-1);
    }    

    while (argv[adrPos][0]=='-') {
	if (strcmp(argv[adrPos],&quot;-2&quot;)==0) {
	    useProtocol=daveProtoISOTCP243;
	} else	if (strncmp(argv[adrPos],&quot;--debug=&quot;,8)==0) {
	    daveSetDebug(atol(argv[adrPos]+8));
	    printf(&quot;setting debug to: 0x%lx\n&quot;,atol(argv[adrPos]+8));
	} else if (strcmp(argv[adrPos],&quot;-s&quot;)==0) {
	    doStop=1;
	} else if (strcmp(argv[adrPos],&quot;-r&quot;)==0) {
	    doRun=1;
	} else if (strncmp(argv[adrPos],&quot;--readoutall&quot;,12)==0) {
	    doReadout=1;
	    doSFBandSFC=1;
	} else if (strncmp(argv[adrPos],&quot;--readout&quot;,9)==0) {
	    doReadout=1;
	} else if (strncmp(argv[adrPos],&quot;--slot=&quot;,7)==0) {
	    useSlot=atol(argv[adrPos]+7);
	} else if (strcmp(argv[adrPos],&quot;-d&quot;)==0) {
	    daveSetDebug(daveDebugAll);
	} else if (strcmp(argv[adrPos],&quot;-n&quot;)==0) {
	    doNewfunctions=1;
	} else
	if (strcmp(argv[adrPos],&quot;-w&quot;)==0) {
	    doWrite=1;
	} else
	if (strcmp(argv[adrPos],&quot;-b&quot;)==0) {
	    doBenchmark=1;
	} else
	if (strcmp(argv[adrPos],&quot;-z&quot;)==0) {
	    doSZLread=1;
	} else
	if (strcmp(argv[adrPos],&quot;-a&quot;)==0) {
	    doSZLreadAll=1;
	} else
	if (strcmp(argv[adrPos],&quot;-m&quot;)==0) {
	    doMultiple=1;
	}
	adrPos++;
	if (argc&lt;=adrPos) {
	    usage();
	    exit(-1);
	}	
    }    

    fds.rfd=openSocket(102, argv[adrPos]);
#ifdef PLAY_WITH_KEEPALIVE
    errno=0;    
    opt=1;
    res=setsockopt(fds.rfd, SOL_SOCKET, SO_KEEPALIVE, &amp;opt, 4);
    LOG3(&quot;setsockopt %s %d\n&quot;, strerror(errno),res);
#endif
    fds.wfd=fds.rfd;

    if (fds.rfd&gt;0) { 
	di =daveNewInterface(fds,&quot;IF1&quot;,0, useProtocol, daveSpeed187k);
	daveSetTimeout(di,5000000);
	dc =daveNewConnection(di,2,0,useSlot);  // insert your rack and slot here

	if (0==daveConnectPLC(dc)) {
	    printf(&quot;Connected.\n&quot;);
//	    di-&gt;timeout=1000;
/*		
	printf(&quot;Trying to read 1 byte from system data,address 0x1e3 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0x1e3,1,NULL);

	printf(&quot;Trying to read 20 bytes from system data,address 0 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0,20,NULL);
*
	printf(&quot;Trying to read 64 bytes (16 dwords) from data block 1.\n&quot;);
	wait();
	res=daveReadBytes(dc,daveDB,1,0,64,NULL);
        if(0==res) {
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW0: %d\n&quot;,a);
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW1: %d\n...\n&quot;,a);
	    a=daveGetU16At(dc,62);
	    printf(&quot;DB1:DW32: %d\n&quot;,a);
	} else 
	    printf(&quot;failed! (%d)\n&quot;,res);  
	printf(&quot;Trying to read 16 bytes from FW0.\n&quot;);
	wait();
/*
 * Some comments about daveReadBytes():
 *
 * Here we read flags and not data blocks, because we cannot know which data blocks will
 * exist in a user's PLC, but flags are always present. To read from data block 5 use:
 * 	daveReadBytes(dc, daveDB, 5, 0, 16, NULL);
 * to read DBD68 and DBW72 use:
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, NULL);
 * to read DBD68 and DBW72 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, appBuffer);
 * to read DBD68 and DBD78 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 14, appBuffer);
 * this reads DBD68 and DBD78 and everything in between and fills the range
 * appBuffer+4 to appBuffer+9 with unwanted bytes, but is much faster than:
 *	daveReadBytes(dc, daveDB, 5, 68, 4, appBuffer);
 *	daveReadBytes(dc, daveDB, 5, 78, 4, appBuffer+4);
 *
 * Users of the 200 family please note:
 * The 200 family PLCs have the V area. This is accessed like a datablock with number 1.
 * This is not a quirk or convention introduced by libnodave, but the command transmitted 
 * to the PLC is exactly the same that would read from DB1 off a 300 or 400.
 *
 *	
	res=daveReadBytes(dc,daveFlags,0,0,16,NULL);
	if (0==res) { 
/
 *	daveGetU32(dc); reads a word (2 bytes) from the current buffer position and increments
 *	an internal pointer by 2, so next daveGetXXX() wil read from the new position behind that
 *	word. If you want to read from a position you specify, use daveGetU16at(dc, position).	
 *	
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	}  else 
	    printf(&quot;failed! (%d)\n&quot;,res);  */

	if(doSZLread) {
	    readSZL(dc,0xA0,0x0);
	    readSZL(dc,0x92,0x0);
	    readSZL(dc,0xB4,0x1024);
	    readSZL(dc,0x111,0x1);
	    readSZL(dc,0x111,0x2);
	    readSZL(dc,0xD91,0x0);
	    readSZL(dc,0x232,0x4);
	    readSZL(dc,0x1A0,0x0);
	}    
	if(doSZLreadAll) {
	    readSZLAll(dc);
	}    
	if(doMultiple) {
    	    printf(&quot;Now testing read multiple variables.\n&quot;
		&quot;This will read 1 Byte from inputs,\n&quot;
		&quot;4 bytes from flags, 2 bytes from DB6\n&quot;
		&quot; and other 2 bytes from flags\n&quot;);
    	    wait();
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,12,2);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    printf(&quot;Input Byte 0 &quot;);
	    res=daveUseResult(dc, &amp;rs, 0); // first result
	    if (res==0) {
		a=daveGetU8(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag DWord 0 &quot;);	
	    res=daveUseResult(dc, &amp;rs, 1); // 2nd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;DB 6 Word 20: &quot;);	
	    res=daveUseResult(dc, &amp;rs, 2); // 3rd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag Word 12: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 3); // 4th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));	

	    printf(&quot;non existing result: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 4); // 5th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));		
	    daveFreeResults(&amp;rs);	

/*	    
	    for (i=0; i&lt;rs.numResults;i++) {
		r2=&amp;(rs.results[i]);
		printf(&quot;result: %s length:%d\n&quot;,daveStrerror(r2-&gt;error), r2-&gt;length);
		res=daveUseResult(dc, &amp;rs, i);
		if (r2-&gt;length&gt;0) _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
		if (r2-&gt;bytes!=NULL) {
	    	    _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
	            d=daveGetFloat(dc);
	            printf(&quot;FD12: %f\n&quot;,d);
		}	 
	    }
*/	    
	}	    

	if(doWrite) {
    	    printf(&quot;\n           @@@ Hier werden die gewuenschte 'area' ueberschrieben. @@@\n&quot;);
	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen vor dem Schreiben\n&quot;);

	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);

	   // Hauptmenu
          printf(&quot;\nSie sind in der Hauptmenu:\n&quot;);
	    printf(&quot;\nBitte geben Sie die gewuenschte 'Schreibweise':\n \n Bit  = 1\n Byte = 2\n Wort = 3\n\n&quot;);
          scanf(&quot;\n%d&quot;, &amp;menu);   

          switch (menu) {

           case 1:       {
            printf(&quot;\nBitte geben die Position der Bit ein Bsp: E0.0=0 und E1.0=8 sowie E2.0=16 ...\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bitp);    
            printf(&quot;\nBitte geben Sie der binaer-wert '0' oder '1'\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bit);
            printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBits(dc, daveOutputs, 0, bitp,1, &amp;bit);
                         break;
                      case 2:
                        res=daveWriteBits(dc, daveInputs, 0, bitp,1, &amp;bit);
                         break;
                      case 3:
                        res=daveWriteBits(dc, daveFlags, 0, bitp,1, &amp;bit);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBits(dc, daveDB, dbnr, bitp,1, &amp;bit);
                         break;
                      case 5:
                        res=daveWriteBits(dc, daveTimer, 0, bitp,1, &amp;bit);
                          break;
                       case 6:
                        res=daveWriteBits(dc, daveCounter, 0, bitp,1, &amp;bit);
                          break;

                                        }
		    break;  }

                case 2:  {
                  printf(&quot;\nBitte geben die Byte-Position ein Bsp: Byte0 = 0, Byte1 = 1 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der byte\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,1, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,1, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,1, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,1, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,1, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,1, &amp;byte);
                          break;

                                        }
		    break;  }

                  case 3:  {
                  printf(&quot;\nBitte geben die Byte-Position (an welche der Wort startet)  ein Bsp: Byte0 = 0, Byte4 = 4 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der Wort\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,4, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,4, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,4, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,4, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,4, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,4, &amp;byte);
                          break;

                                        }
		    break;    }

                                 }

	   printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen nach dem Schreiben\n&quot;);
	   res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
    	   printf(&quot;\nErgebnis:%d=%s\n&quot;, res, daveStrerror(res));	  

	} // doWrite
	if(doClear) {
    	    printf(&quot;Now writing 0 to the bytes FB0...FB15.\n&quot;);
    	    wait();
	    a=0;
    	    daveWriteBytes(dc,daveFlags,0,0,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,4,4,&amp;a);
	    daveWriteBytes(dc,daveFlags,0,8,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,12,4,&amp;a);
	    daveReadBytes(dc,daveFlags,0,0,16,NULL);
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	} // doClear

	if(doNewfunctions) {
	    saveDebug=daveGetDebug();

	    printf(&quot;\nTrying to read two consecutive bits from DB11.DBX0.1 (supposed to fail)\n&quot;);;
	    res=daveReadBits(dc, daveDB, 11, 1, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read no bit (length 0) from DB17.DBX0.1 (supposed to fail)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 1, 0,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    daveSetDebug(daveGetDebug()|daveDebugPDU); 
	    printf(&quot;\nTrying to read a single bit from DB17.DBX0.3 (supposed to work if you have a DB17)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 3, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read a single bit from E0.2 (supposed to work)\n&quot;);
	    res=daveReadBits(dc, daveInputs, 0, 2, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=0;
	    printf(&quot;\nWriting 0 to EB0 (supposed to work)\n&quot;);
	    res=daveWriteBytes(dc, daveOutputs, 0, 0, 1, &amp;a);

	    a=1;
	    printf(&quot;\nTrying to set single bit E0.5 (supposed to work)\n&quot;);
	    res=daveWriteBits(dc, daveOutputs, 0, 5, 1, &amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 1 byte from AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveReadBytes(dc, daveAnaIn, 0, 0, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=2341;
	    printf(&quot;\nTrying to write 1 word (2 bytes) to AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveWriteBytes(dc, daveAnaOut, 0, 0, 2,&amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 4 items from Timers (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveTimer, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetSeconds(dc)\n&quot;);
		d=daveGetSeconds(dc);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot; %0.3f\n&quot;,d);
		printf(&quot;\nShowing the same results using daveGetSecondsAt(dc,position)\n&quot;);
		d=daveGetSecondsAt(dc,0);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,2);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,4);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,6);
		printf(&quot; %0.3f\n&quot;,d);
	    }
	    printf(&quot;\nTrying to read 4 items from Counters (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveCounter, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));
	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetCounterValue(dc)\n&quot;);
		c=daveGetCounterValue(dc);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot; %d\n&quot;,c);

		printf(&quot;\nShowing the same results using daveGetCounterValueAt(dc, position)\n&quot;);
		c=daveGetCounterValueAt(dc,0);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValueAt(dc,2);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,4);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,6);
		printf(&quot; %d\n&quot;,c);
	    }

	    printf(&quot;\nTrying to read multiple items with multiple variable read. (1st 2 supposed to work ok, rests may debend on CPU type and contents)\n&quot;);
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,2,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,2,4);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    daveSetDebug(saveDebug);
	}

	if(doStop) {
	    daveStop(dc);
	}
	if(doRun) {
	    daveStart(dc);
	}
	if(doReadout) {
	    printf(&quot;\nDie 8 Byte Eingaenge werden byteweise gelesen\n&quot;);
	//wait();
	res=daveReadBytes(dc,daveInputs,0,0,8,NULL);

	    a=daveGetU8(dc);
	    printf(&quot;\nE0.0:E0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E1.0:E1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E2.0:E2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E3.0:E3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nE4.0:E4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E5.0:E5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E6.0:E6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E7.0:E7.7: %d\n&quot;,a);

	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen\n&quot;);

	//wait();
	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

             a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
	    /*a=daveGetU16At(dc,4);        Diese Variante mit Byte-Offset
	    printf(&quot;DB1:DW32: %d\n&quot;,a);*/

}

	if(doBenchmark) {
	    if(useProtocol==daveProtoISOTCP243) { // we have a 200 CPU, use V memory
		rBenchmark(dc, daveDB);
	        if(doWrite) {
		    wBenchmark(dc, daveDB);
	        } // doWrite
	    } else {				// we have a 300/400 CPU, use Flags(Merkers)
		rBenchmark(dc, daveFlags);
		if(doWrite) {
		    wBenchmark(dc, daveFlags);
		} // doWrite
	    }	
	} // doBenchmark

	printf(&quot;Finished.\n&quot;);
	return 0;
	} else {
	    printf(&quot;Couldn't connect to PLC.\n Please make sure you use the -2 option with a CP243 but not with CPs 343 or 443.\n&quot;);	
	    return -2;
	}
    } else {
	printf(&quot;Couldn't open TCP port. \nPlease make sure a CP is connected and the IP address is ok. \n&quot;);	
    	return -1;
    }    
}

/*
    Changes: 
    07/19/04  removed unused vars.
    09/09/04  applied patch for variable Profibus speed from Andrew Rostovtsew.
    09/09/04  removed unused includes byteswap.h. Made some code to test TCP keepalive conditional.
    03/03/05  added slot select option.
    03/28/05  changed code to use flag (M) area for write. Was DB17.
    04/09/05  removed CYGWIN defines. As there were no more differences against LINUX, it should 
	      work with LINUX defines.
*/
//#define PLAY_WITH_KEEPALIVE
#include &quot;C:\Programme\National Instruments\LabVIEW 7.0\cintools\extcode.h&quot;
#pragma comment(lib, &quot;libnodave.lib&quot;)
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#define BCCWIN
#include &quot;nodavesimple.h&quot;
#include &quot;openSocket.h&quot;

#ifdef LINUX
#include &lt;unistd.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;fcntl.h&gt;
#define UNIX_STYLE
#endif

#ifdef BCCWIN
#include &lt;time.h&gt;
void usage(void);
void wait(void);

#define WIN_STYLE    
#endif

#ifdef PLAY_WITH_KEEPALIVE
#include &lt;sys/socket.h&gt;
#endif
#include &lt;errno.h&gt;
//************************************************************************
void readSZL(daveConnection *dc,int id, int index)
{
    int res, SZLid, indx, SZcount, SZlen,i,j,len;
    uc * d,*dd;
    uc ddd[3000];
    printf(&quot;Trying to read SZL-ID %04X index %02X.\n&quot;,id,index);
    res=daveReadSZL(dc,id,index, ddd, 3000);
    printf(&quot;Function result: %d %s len:%d\n&quot;,res,daveStrerror(res),dc-&gt;AnswLen);
//    _daveDump(&quot;Data&quot;,dc-&gt;resultPointer,dc-&gt;AnswLen);
    _daveDump(&quot;Data&quot;,ddd,dc-&gt;AnswLen);

    if ((dc-&gt;AnswLen)&gt;=4) {
	d=ddd;
        dd=ddd;
	dd+=8;
	len=dc-&gt;AnswLen-8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    if(len&gt;0){
	    for (i=0;i&lt;SZcount;i++){
		if(len&gt;0){
		for (j=0; j&lt;SZlen; j++){
		    if(len&gt;0){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		    }
		    len--;
		}
		printf(&quot;\n&quot;);
		}
	    }
	    }
	}
    }
    printf(&quot;\n&quot;);
}    

void readSZLAll(daveConnection *dc) {
    uc SzlList[1000];
    int res, SZLid, indx, SZcount, SZlen,i,j, rid, rind;
    uc * d,*dd;

    res=daveReadSZL(dc,0,0,SzlList, 1000);
    printf(&quot;%d %d\n&quot;,res,dc-&gt;AnswLen);
    if ((dc-&gt;AnswLen)&gt;=4) {
	d=dc-&gt;resultPointer;
        dd=SzlList;
	dd+=8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    for (i=0;i&lt;SZcount;i++){
//		rind=*dd;
//		rid=*(dd+1); 
		rid=*(dd+1)+256*(*dd); 
		rind=0;
		printf(&quot;ID:%04X Index:%02X\n&quot;,rid,rind);
		readSZL(dc, rid, rind);
		for (j=0; j&lt;SZlen; j++){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		}
		printf(&quot;\nID:%04X Index:%02X\n&quot;,rid,rind);

	    }
	}
    }
    printf(&quot;\n&quot;);
}

void wait() {
    uc c;
    printf(&quot;Press return to continue.\n&quot;);
#ifdef UNIX_STYLE
    read(0,&amp;c,1);
#endif
}    
 void usage()
{
    printf(&quot;Usage: testISO_TCP [-d] [-w] IP-Address of CP\n&quot;);
    printf(&quot;-2 uses a protocol variant for the CP243. You need to set it, if you use such a CP.\n&quot;);
    printf(&quot;-w will try to write to Flag words. It will overwrite FB0 to FB15 (MB0 to MB15) !\n&quot;);
    printf(&quot;-d will produce a lot of debug messages.\n&quot;);
    printf(&quot;-b will run benchmarks. Specify -b and -w to run write benchmarks.\n&quot;);
    printf(&quot;-m will run a test for multiple variable reads.\n&quot;);
    printf(&quot;-c will write 0 to the PLC memory used in write tests.\n&quot;);
    printf(&quot;-z will read some SZL list items (diagnostic information).\n&quot;
	    &quot;  Works 300 and 400 family only.\n&quot;);
    printf(&quot;-s stops the PLC.\n&quot;);
    printf(&quot;-r tries to put the PLC in run mode.\n&quot;);
    printf(&quot;--readout read program and data blocks from PLC.\n&quot;);
    printf(&quot;--readoutall read all program and data blocks from PLC. Includes SFBs and SFCs.\n&quot;);
    printf(&quot;--slot=&lt;number&gt; sets slot for PLC (default is 2).\n&quot;);
    printf(&quot;--debug=&lt;number&gt; will set daveDebug to number.\n&quot;);
    printf(&quot;Example: testISO_TCP -w 192.168.19.1\n&quot;);
}

void loadBlocksOfType(daveConnection * dc, int blockType) {
    int j, i, uploadID, len, more;
#ifdef UNIX_STYLE
    int fd;
#endif	        
#ifdef WIN_STYLE	    
    HANDLE fd;
    unsigned long res;
#endif	        
    char blockName [20];
    uc blockBuffer[20000],*bb;
    daveBlockEntry dbe[256];   
    j=daveListBlocksOfType(dc, blockType, dbe);
    if (j&lt;0) {
	printf(&quot;error %d = %s\n&quot;,-j,daveStrerror(-j));
	return;
    }
    printf(&quot;%d blocks of type %s\n&quot;,j,daveBlockName(blockType));
    for (i=0; i&lt;j; i++) {
	printf(&quot;%s%d  %d %d\n&quot;,
	    daveBlockName(blockType),
	    dbe[i].number, dbe[i].type[0],dbe[i].type[1]);	
	bb=blockBuffer;
	len=0;
	if (0==initUpload(dc, blockType, dbe[i].number, &amp;uploadID)) {
    	    do {
		doUpload(dc,&amp;more,&amp;bb,&amp;len,uploadID);
	    } while (more);
	    sprintf(blockName,&quot;%s%d.mc7&quot;,daveBlockName(blockType), dbe[i].number);	
#ifdef UNIX_STYLE
    	    fd=open(blockName,O_RDWR|O_CREAT|O_TRUNC,0644);
    	    write(fd, blockBuffer, len);
    	    close(fd);
#endif	    
#ifdef WIN_STYLE
	    fd = CreateFile(blockName,
    	      GENERIC_WRITE, 0, 0, 2,
    		FILE_FLAG_WRITE_THROUGH, 0);
    	    WriteFile(fd, blockBuffer, len, &amp;res, NULL);
    	    CloseHandle(fd);
#endif	    

    	    endUpload(dc,uploadID);
	}    
    }
}

#include &quot;benchmark.c&quot;

int main(int argc, char **argv) {
  int const start = 12;
  int a,b,c,menu,dbnr,area,bit,byte,bitp,bytep,adrPos,doWrite,doBenchmark, doSZLread, doMultiple, doClear,
	res, useProtocol,doSZLreadAll, doRun, doStop, doReadout, doSFBandSFC,
	doNewfunctions, saveDebug,
	useSlot;
#ifdef PLAY_WITH_KEEPALIVE    	
    int opt;
#endif    
    float d;
    daveInterface * di;
    daveConnection * dc;
    _daveOSserialType fds;
    PDU p;
    daveResultSet rs;

    daveSetDebug(daveDebugPrintErrors);
    adrPos=1;
    doWrite=0;
    doBenchmark=0;
    doMultiple=0;
    doClear=0;
    doSZLread=0;
    doSZLreadAll=0;
    doRun=0;
    doStop=0;
    doReadout=0;
    doSFBandSFC=0;
    doNewfunctions=0;

    useProtocol=daveProtoISOTCP;
    useSlot=2;

    if (argc&lt;2) {
	usage();
	exit(-1);
    }    

    while (argv[adrPos][0]=='-') {
	if (strcmp(argv[adrPos],&quot;-2&quot;)==0) {
	    useProtocol=daveProtoISOTCP243;
	} else	if (strncmp(argv[adrPos],&quot;--debug=&quot;,8)==0) {
	    daveSetDebug(atol(argv[adrPos]+8));
	    printf(&quot;setting debug to: 0x%lx\n&quot;,atol(argv[adrPos]+8));
	} else if (strcmp(argv[adrPos],&quot;-s&quot;)==0) {
	    doStop=1;
	} else if (strcmp(argv[adrPos],&quot;-r&quot;)==0) {
	    doRun=1;
	} else if (strncmp(argv[adrPos],&quot;--readoutall&quot;,12)==0) {
	    doReadout=1;
	    doSFBandSFC=1;
	} else if (strncmp(argv[adrPos],&quot;--readout&quot;,9)==0) {
	    doReadout=1;
	} else if (strncmp(argv[adrPos],&quot;--slot=&quot;,7)==0) {
	    useSlot=atol(argv[adrPos]+7);
	} else if (strcmp(argv[adrPos],&quot;-d&quot;)==0) {
	    daveSetDebug(daveDebugAll);
	} else if (strcmp(argv[adrPos],&quot;-n&quot;)==0) {
	    doNewfunctions=1;
	} else
	if (strcmp(argv[adrPos],&quot;-w&quot;)==0) {
	    doWrite=1;
	} else
	if (strcmp(argv[adrPos],&quot;-b&quot;)==0) {
	    doBenchmark=1;
	} else
	if (strcmp(argv[adrPos],&quot;-z&quot;)==0) {
	    doSZLread=1;
	} else
	if (strcmp(argv[adrPos],&quot;-a&quot;)==0) {
	    doSZLreadAll=1;
	} else
	if (strcmp(argv[adrPos],&quot;-m&quot;)==0) {
	    doMultiple=1;
	}
	adrPos++;
	if (argc&lt;=adrPos) {
	    usage();
	    exit(-1);
	}	
    }    

    fds.rfd=openSocket(102, argv[adrPos]);
#ifdef PLAY_WITH_KEEPALIVE
    errno=0;    
    opt=1;
    res=setsockopt(fds.rfd, SOL_SOCKET, SO_KEEPALIVE, &amp;opt, 4);
    LOG3(&quot;setsockopt %s %d\n&quot;, strerror(errno),res);
#endif
    fds.wfd=fds.rfd;

    if (fds.rfd&gt;0) { 
	di =daveNewInterface(fds,&quot;IF1&quot;,0, useProtocol, daveSpeed187k);
	daveSetTimeout(di,5000000);
	dc =daveNewConnection(di,2,0,useSlot);  // insert your rack and slot here

	if (0==daveConnectPLC(dc)) {
	    printf(&quot;Connected.\n&quot;);
//	    di-&gt;timeout=1000;
/*		
	printf(&quot;Trying to read 1 byte from system data,address 0x1e3 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0x1e3,1,NULL);

	printf(&quot;Trying to read 20 bytes from system data,address 0 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0,20,NULL);
*
	printf(&quot;Trying to read 64 bytes (16 dwords) from data block 1.\n&quot;);
	wait();
	res=daveReadBytes(dc,daveDB,1,0,64,NULL);
        if(0==res) {
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW0: %d\n&quot;,a);
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW1: %d\n...\n&quot;,a);
	    a=daveGetU16At(dc,62);
	    printf(&quot;DB1:DW32: %d\n&quot;,a);
	} else 
	    printf(&quot;failed! (%d)\n&quot;,res);  
	printf(&quot;Trying to read 16 bytes from FW0.\n&quot;);
	wait();
/*
 * Some comments about daveReadBytes():
 *
 * Here we read flags and not data blocks, because we cannot know which data blocks will
 * exist in a user's PLC, but flags are always present. To read from data block 5 use:
 * 	daveReadBytes(dc, daveDB, 5, 0, 16, NULL);
 * to read DBD68 and DBW72 use:
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, NULL);
 * to read DBD68 and DBW72 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, appBuffer);
 * to read DBD68 and DBD78 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 14, appBuffer);
 * this reads DBD68 and DBD78 and everything in between and fills the range
 * appBuffer+4 to appBuffer+9 with unwanted bytes, but is much faster than:
 *	daveReadBytes(dc, daveDB, 5, 68, 4, appBuffer);
 *	daveReadBytes(dc, daveDB, 5, 78, 4, appBuffer+4);
 *
 * Users of the 200 family please note:
 * The 200 family PLCs have the V area. This is accessed like a datablock with number 1.
 * This is not a quirk or convention introduced by libnodave, but the command transmitted 
 * to the PLC is exactly the same that would read from DB1 off a 300 or 400.
 *
 *	
	res=daveReadBytes(dc,daveFlags,0,0,16,NULL);
	if (0==res) { 
/
 *	daveGetU32(dc); reads a word (2 bytes) from the current buffer position and increments
 *	an internal pointer by 2, so next daveGetXXX() wil read from the new position behind that
 *	word. If you want to read from a position you specify, use daveGetU16at(dc, position).	
 *	
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	}  else 
	    printf(&quot;failed! (%d)\n&quot;,res);  */

	if(doSZLread) {
	    readSZL(dc,0xA0,0x0);
	    readSZL(dc,0x92,0x0);
	    readSZL(dc,0xB4,0x1024);
	    readSZL(dc,0x111,0x1);
	    readSZL(dc,0x111,0x2);
	    readSZL(dc,0xD91,0x0);
	    readSZL(dc,0x232,0x4);
	    readSZL(dc,0x1A0,0x0);
	}    
	if(doSZLreadAll) {
	    readSZLAll(dc);
	}    
	if(doMultiple) {
    	    printf(&quot;Now testing read multiple variables.\n&quot;
		&quot;This will read 1 Byte from inputs,\n&quot;
		&quot;4 bytes from flags, 2 bytes from DB6\n&quot;
		&quot; and other 2 bytes from flags\n&quot;);
    	    wait();
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,12,2);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    printf(&quot;Input Byte 0 &quot;);
	    res=daveUseResult(dc, &amp;rs, 0); // first result
	    if (res==0) {
		a=daveGetU8(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag DWord 0 &quot;);	
	    res=daveUseResult(dc, &amp;rs, 1); // 2nd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;DB 6 Word 20: &quot;);	
	    res=daveUseResult(dc, &amp;rs, 2); // 3rd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag Word 12: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 3); // 4th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));	

	    printf(&quot;non existing result: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 4); // 5th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));		
	    daveFreeResults(&amp;rs);	

/*	    
	    for (i=0; i&lt;rs.numResults;i++) {
		r2=&amp;(rs.results[i]);
		printf(&quot;result: %s length:%d\n&quot;,daveStrerror(r2-&gt;error), r2-&gt;length);
		res=daveUseResult(dc, &amp;rs, i);
		if (r2-&gt;length&gt;0) _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
		if (r2-&gt;bytes!=NULL) {
	    	    _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
	            d=daveGetFloat(dc);
	            printf(&quot;FD12: %f\n&quot;,d);
		}	 
	    }
*/	    
	}	    

	if(doWrite) {
    	    printf(&quot;\n           @@@ Hier werden die gewuenschte 'area' ueberschrieben. @@@\n&quot;);
	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen vor dem Schreiben\n&quot;);

	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);

	   // Hauptmenu
          printf(&quot;\nSie sind in der Hauptmenu:\n&quot;);
	    printf(&quot;\nBitte geben Sie die gewuenschte 'Schreibweise':\n \n Bit  = 1\n Byte = 2\n Wort = 3\n\n&quot;);
          scanf(&quot;\n%d&quot;, &amp;menu);   

          switch (menu) {

           case 1:       {
            printf(&quot;\nBitte geben die Position der Bit ein Bsp: E0.0=0 und E1.0=8 sowie E2.0=16 ...\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bitp);    
            printf(&quot;\nBitte geben Sie der binaer-wert '0' oder '1'\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bit);
            printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBits(dc, daveOutputs, 0, bitp,1, &amp;bit);
                         break;
                      case 2:
                        res=daveWriteBits(dc, daveInputs, 0, bitp,1, &amp;bit);
                         break;
                      case 3:
                        res=daveWriteBits(dc, daveFlags, 0, bitp,1, &amp;bit);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBits(dc, daveDB, dbnr, bitp,1, &amp;bit);
                         break;
                      case 5:
                        res=daveWriteBits(dc, daveTimer, 0, bitp,1, &amp;bit);
                          break;
                       case 6:
                        res=daveWriteBits(dc, daveCounter, 0, bitp,1, &amp;bit);
                          break;

                                        }
		    break;  }

                case 2:  {
                  printf(&quot;\nBitte geben die Byte-Position ein Bsp: Byte0 = 0, Byte1 = 1 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der byte\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,1, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,1, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,1, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,1, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,1, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,1, &amp;byte);
                          break;

                                        }
		    break;  }

                  case 3:  {
                  printf(&quot;\nBitte geben die Byte-Position (an welche der Wort startet)  ein Bsp: Byte0 = 0, Byte4 = 4 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der Wort\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,4, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,4, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,4, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,4, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,4, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,4, &amp;byte);
                          break;

                                        }
		    break;    }

                                 }

	   printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen nach dem Schreiben\n&quot;);
	   res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
    	   printf(&quot;\nErgebnis:%d=%s\n&quot;, res, daveStrerror(res));	  

	} // doWrite
	if(doClear) {
    	    printf(&quot;Now writing 0 to the bytes FB0...FB15.\n&quot;);
    	    wait();
	    a=0;
    	    daveWriteBytes(dc,daveFlags,0,0,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,4,4,&amp;a);
	    daveWriteBytes(dc,daveFlags,0,8,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,12,4,&amp;a);
	    daveReadBytes(dc,daveFlags,0,0,16,NULL);
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	} // doClear

	if(doNewfunctions) {
	    saveDebug=daveGetDebug();

	    printf(&quot;\nTrying to read two consecutive bits from DB11.DBX0.1 (supposed to fail)\n&quot;);;
	    res=daveReadBits(dc, daveDB, 11, 1, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read no bit (length 0) from DB17.DBX0.1 (supposed to fail)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 1, 0,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    daveSetDebug(daveGetDebug()|daveDebugPDU); 
	    printf(&quot;\nTrying to read a single bit from DB17.DBX0.3 (supposed to work if you have a DB17)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 3, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read a single bit from E0.2 (supposed to work)\n&quot;);
	    res=daveReadBits(dc, daveInputs, 0, 2, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=0;
	    printf(&quot;\nWriting 0 to EB0 (supposed to work)\n&quot;);
	    res=daveWriteBytes(dc, daveOutputs, 0, 0, 1, &amp;a);

	    a=1;
	    printf(&quot;\nTrying to set single bit E0.5 (supposed to work)\n&quot;);
	    res=daveWriteBits(dc, daveOutputs, 0, 5, 1, &amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 1 byte from AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveReadBytes(dc, daveAnaIn, 0, 0, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=2341;
	    printf(&quot;\nTrying to write 1 word (2 bytes) to AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveWriteBytes(dc, daveAnaOut, 0, 0, 2,&amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 4 items from Timers (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveTimer, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetSeconds(dc)\n&quot;);
		d=daveGetSeconds(dc);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot; %0.3f\n&quot;,d);
		printf(&quot;\nShowing the same results using daveGetSecondsAt(dc,position)\n&quot;);
		d=daveGetSecondsAt(dc,0);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,2);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,4);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,6);
		printf(&quot; %0.3f\n&quot;,d);
	    }
	    printf(&quot;\nTrying to read 4 items from Counters (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveCounter, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));
	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetCounterValue(dc)\n&quot;);
		c=daveGetCounterValue(dc);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot; %d\n&quot;,c);

		printf(&quot;\nShowing the same results using daveGetCounterValueAt(dc, position)\n&quot;);
		c=daveGetCounterValueAt(dc,0);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValueAt(dc,2);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,4);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,6);
		printf(&quot; %d\n&quot;,c);
	    }

	    printf(&quot;\nTrying to read multiple items with multiple variable read. (1st 2 supposed to work ok, rests may debend on CPU type and contents)\n&quot;);
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,2,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,2,4);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    daveSetDebug(saveDebug);
	}

	if(doStop) {
	    daveStop(dc);
	}
	if(doRun) {
	    daveStart(dc);
	}
	if(doReadout) {
	    printf(&quot;\nDie 8 Byte Eingaenge werden byteweise gelesen\n&quot;);
	//wait();
	res=daveReadBytes(dc,daveInputs,0,0,8,NULL);

	    a=daveGetU8(dc);
	    printf(&quot;\nE0.0:E0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E1.0:E1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E2.0:E2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E3.0:E3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nE4.0:E4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E5.0:E5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E6.0:E6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E7.0:E7.7: %d\n&quot;,a);

	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen\n&quot;);

	//wait();
	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

             a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
	    /*a=daveGetU16At(dc,4);        Diese Variante mit Byte-Offset
	    printf(&quot;DB1:DW32: %d\n&quot;,a);*/

}

	if(doBenchmark) {
	    if(useProtocol==daveProtoISOTCP243) { // we have a 200 CPU, use V memory
		rBenchmark(dc, daveDB);
	        if(doWrite) {
		    wBenchmark(dc, daveDB);
	        } // doWrite
	    } else {				// we have a 300/400 CPU, use Flags(Merkers)
		rBenchmark(dc, daveFlags);
		if(doWrite) {
		    wBenchmark(dc, daveFlags);
		} // doWrite
	    }	
	} // doBenchmark

	printf(&quot;Finished.\n&quot;);
	return 0;
	} else {
	    printf(&quot;Couldn't connect to PLC.\n Please make sure you use the -2 option with a CP243 but not with CPs 343 or 443.\n&quot;);	
	    return -2;
	}
    } else {
	printf(&quot;Couldn't open TCP port. \nPlease make sure a CP is connected and the IP address is ok. \n&quot;);	
    	return -1;
    }    
}

/*
    Changes: 
    07/19/04  removed unused vars.
    09/09/04  applied patch for variable Profibus speed from Andrew Rostovtsew.
    09/09/04  removed unused includes byteswap.h. Made some code to test TCP keepalive conditional.
    03/03/05  added slot select option.
    03/28/05  changed code to use flag (M) area for write. Was DB17.
    04/09/05  removed CYGWIN defines. As there were no more differences against LINUX, it should 
	      work with LINUX defines.
*/
</code></pre>
<p>//************************Fehler Fehlermeldungen***************************</p>
<p>1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) void __stdcall _daveDump(char *,unsigned char *,int)&quot; (__imp_?_daveDump@@YGXPADPAEH@Z)&quot; in Funktion &quot;&quot;void __cdecl readSZL(struct _daveConnection *,int,int)&quot; (?readSZL@@YAXPAU_daveConnection@@HH@Z)&quot;.<br />
1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) char * __stdcall daveStrerror(int)&quot; (__imp_?daveStrerror@@YGPADH@Z)&quot; in Funktion &quot;&quot;void __cdecl readSZL(struct _daveConnection *,int,int)&quot; (?readSZL@@YAXPAU_daveConnection@@HH@Z)&quot;.<br />
1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) int __stdcall daveReadSZL(struct _daveConnection *,int,int,void *,int)&quot; (__imp_?daveReadSZL@@YGHPAU_daveConnection@@HHPAXH@Z)&quot; in Funktion &quot;&quot;void __cdecl readSZL(struct _daveConnection *,int,int)&quot; (?readSZL@@YAXPAU_daveConnection@@HH@Z)&quot;.<br />
1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) int __stdcall endUpload(struct _daveConnection *,int)&quot; (__imp_?endUpload@@YGHPAU_daveConnection@@H@Z)&quot; in Funktion &quot;&quot;void __cdecl loadBlocksOfType(struct _daveConnection *,int)&quot; (?loadBlocksOfType@@YAXPAU_daveConnection@@H@Z)&quot;.</p>
<p>*****************************************************************************<br />
<a href="http://sourceforge.net/project/showfiles.php?group_id=61026" rel="nofollow">http://sourceforge.net/project/showfiles.php?group_id=61026</a> Davon können die nötigen headerdatein in &quot;libnodave 0.8.2&quot; unterladen werden.</p>
<p>Das Problem kann ich immer nicht lösen , ich hoffe , dass jemand mir hilft. Danke im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/180384/das-problem-beim-kompilieren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 08:24:58 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/180384.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 May 2007 08:02:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Das Problem beim Kompilieren on Wed, 02 May 2007 08:02:14 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich entwickele das vollständige richtige Programm , um in DLL umwandeln und weiterhin damit auf LabView umstellen zu können. Aber beim Kompilieren kommen immer die Fehlermeldungen , die mich verwirren</p>
<pre><code>//#define PLAY_WITH_KEEPALIVE
#include &quot;C:\Programme\National Instruments\LabVIEW 7.0\cintools\extcode.h&quot;
#pragma comment(lib, &quot;libnodave.lib&quot;)
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#define BCCWIN
#include &quot;nodavesimple.h&quot;
#include &quot;openSocket.h&quot;

#ifdef LINUX
#include &lt;unistd.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;fcntl.h&gt;
#define UNIX_STYLE
#endif

#ifdef BCCWIN
#include &lt;time.h&gt;
void usage(void);
void wait(void);

#define WIN_STYLE    
#endif

#ifdef PLAY_WITH_KEEPALIVE
#include &lt;sys/socket.h&gt;
#endif
#include &lt;errno.h&gt;
//************************************************************************
void readSZL(daveConnection *dc,int id, int index)
{
    int res, SZLid, indx, SZcount, SZlen,i,j,len;
    uc * d,*dd;
    uc ddd[3000];
    printf(&quot;Trying to read SZL-ID %04X index %02X.\n&quot;,id,index);
    res=daveReadSZL(dc,id,index, ddd, 3000);
    printf(&quot;Function result: %d %s len:%d\n&quot;,res,daveStrerror(res),dc-&gt;AnswLen);
//    _daveDump(&quot;Data&quot;,dc-&gt;resultPointer,dc-&gt;AnswLen);
    _daveDump(&quot;Data&quot;,ddd,dc-&gt;AnswLen);

    if ((dc-&gt;AnswLen)&gt;=4) {
	d=ddd;
        dd=ddd;
	dd+=8;
	len=dc-&gt;AnswLen-8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    if(len&gt;0){
	    for (i=0;i&lt;SZcount;i++){
		if(len&gt;0){
		for (j=0; j&lt;SZlen; j++){
		    if(len&gt;0){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		    }
		    len--;
		}
		printf(&quot;\n&quot;);
		}
	    }
	    }
	}
    }
    printf(&quot;\n&quot;);
}    

void readSZLAll(daveConnection *dc) {
    uc SzlList[1000];
    int res, SZLid, indx, SZcount, SZlen,i,j, rid, rind;
    uc * d,*dd;

    res=daveReadSZL(dc,0,0,SzlList, 1000);
    printf(&quot;%d %d\n&quot;,res,dc-&gt;AnswLen);
    if ((dc-&gt;AnswLen)&gt;=4) {
	d=dc-&gt;resultPointer;
        dd=SzlList;
	dd+=8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    for (i=0;i&lt;SZcount;i++){
//		rind=*dd;
//		rid=*(dd+1); 
		rid=*(dd+1)+256*(*dd); 
		rind=0;
		printf(&quot;ID:%04X Index:%02X\n&quot;,rid,rind);
		readSZL(dc, rid, rind);
		for (j=0; j&lt;SZlen; j++){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		}
		printf(&quot;\nID:%04X Index:%02X\n&quot;,rid,rind);

	    }
	}
    }
    printf(&quot;\n&quot;);
}

void wait() {
    uc c;
    printf(&quot;Press return to continue.\n&quot;);
#ifdef UNIX_STYLE
    read(0,&amp;c,1);
#endif
}    
 void usage()
{
    printf(&quot;Usage: testISO_TCP [-d] [-w] IP-Address of CP\n&quot;);
    printf(&quot;-2 uses a protocol variant for the CP243. You need to set it, if you use such a CP.\n&quot;);
    printf(&quot;-w will try to write to Flag words. It will overwrite FB0 to FB15 (MB0 to MB15) !\n&quot;);
    printf(&quot;-d will produce a lot of debug messages.\n&quot;);
    printf(&quot;-b will run benchmarks. Specify -b and -w to run write benchmarks.\n&quot;);
    printf(&quot;-m will run a test for multiple variable reads.\n&quot;);
    printf(&quot;-c will write 0 to the PLC memory used in write tests.\n&quot;);
    printf(&quot;-z will read some SZL list items (diagnostic information).\n&quot;
	    &quot;  Works 300 and 400 family only.\n&quot;);
    printf(&quot;-s stops the PLC.\n&quot;);
    printf(&quot;-r tries to put the PLC in run mode.\n&quot;);
    printf(&quot;--readout read program and data blocks from PLC.\n&quot;);
    printf(&quot;--readoutall read all program and data blocks from PLC. Includes SFBs and SFCs.\n&quot;);
    printf(&quot;--slot=&lt;number&gt; sets slot for PLC (default is 2).\n&quot;);
    printf(&quot;--debug=&lt;number&gt; will set daveDebug to number.\n&quot;);
    printf(&quot;Example: testISO_TCP -w 192.168.19.1\n&quot;);
}

void loadBlocksOfType(daveConnection * dc, int blockType) {
    int j, i, uploadID, len, more;
#ifdef UNIX_STYLE
    int fd;
#endif	        
#ifdef WIN_STYLE	    
    HANDLE fd;
    unsigned long res;
#endif	        
    char blockName [20];
    uc blockBuffer[20000],*bb;
    daveBlockEntry dbe[256];   
    j=daveListBlocksOfType(dc, blockType, dbe);
    if (j&lt;0) {
	printf(&quot;error %d = %s\n&quot;,-j,daveStrerror(-j));
	return;
    }
    printf(&quot;%d blocks of type %s\n&quot;,j,daveBlockName(blockType));
    for (i=0; i&lt;j; i++) {
	printf(&quot;%s%d  %d %d\n&quot;,
	    daveBlockName(blockType),
	    dbe[i].number, dbe[i].type[0],dbe[i].type[1]);	
	bb=blockBuffer;
	len=0;
	if (0==initUpload(dc, blockType, dbe[i].number, &amp;uploadID)) {
    	    do {
		doUpload(dc,&amp;more,&amp;bb,&amp;len,uploadID);
	    } while (more);
	    sprintf(blockName,&quot;%s%d.mc7&quot;,daveBlockName(blockType), dbe[i].number);	
#ifdef UNIX_STYLE
    	    fd=open(blockName,O_RDWR|O_CREAT|O_TRUNC,0644);
    	    write(fd, blockBuffer, len);
    	    close(fd);
#endif	    
#ifdef WIN_STYLE
	    fd = CreateFile(blockName,
    	      GENERIC_WRITE, 0, 0, 2,
    		FILE_FLAG_WRITE_THROUGH, 0);
    	    WriteFile(fd, blockBuffer, len, &amp;res, NULL);
    	    CloseHandle(fd);
#endif	    

    	    endUpload(dc,uploadID);
	}    
    }
}

#include &quot;benchmark.c&quot;

int main(int argc, char **argv) {
  int const start = 12;
  int a,b,c,menu,dbnr,area,bit,byte,bitp,bytep,adrPos,doWrite,doBenchmark, doSZLread, doMultiple, doClear,
	res, useProtocol,doSZLreadAll, doRun, doStop, doReadout, doSFBandSFC,
	doNewfunctions, saveDebug,
	useSlot;
#ifdef PLAY_WITH_KEEPALIVE    	
    int opt;
#endif    
    float d;
    daveInterface * di;
    daveConnection * dc;
    _daveOSserialType fds;
    PDU p;
    daveResultSet rs;

    daveSetDebug(daveDebugPrintErrors);
    adrPos=1;
    doWrite=0;
    doBenchmark=0;
    doMultiple=0;
    doClear=0;
    doSZLread=0;
    doSZLreadAll=0;
    doRun=0;
    doStop=0;
    doReadout=0;
    doSFBandSFC=0;
    doNewfunctions=0;

    useProtocol=daveProtoISOTCP;
    useSlot=2;

    if (argc&lt;2) {
	usage();
	exit(-1);
    }    

    while (argv[adrPos][0]=='-') {
	if (strcmp(argv[adrPos],&quot;-2&quot;)==0) {
	    useProtocol=daveProtoISOTCP243;
	} else	if (strncmp(argv[adrPos],&quot;--debug=&quot;,8)==0) {
	    daveSetDebug(atol(argv[adrPos]+8));
	    printf(&quot;setting debug to: 0x%lx\n&quot;,atol(argv[adrPos]+8));
	} else if (strcmp(argv[adrPos],&quot;-s&quot;)==0) {
	    doStop=1;
	} else if (strcmp(argv[adrPos],&quot;-r&quot;)==0) {
	    doRun=1;
	} else if (strncmp(argv[adrPos],&quot;--readoutall&quot;,12)==0) {
	    doReadout=1;
	    doSFBandSFC=1;
	} else if (strncmp(argv[adrPos],&quot;--readout&quot;,9)==0) {
	    doReadout=1;
	} else if (strncmp(argv[adrPos],&quot;--slot=&quot;,7)==0) {
	    useSlot=atol(argv[adrPos]+7);
	} else if (strcmp(argv[adrPos],&quot;-d&quot;)==0) {
	    daveSetDebug(daveDebugAll);
	} else if (strcmp(argv[adrPos],&quot;-n&quot;)==0) {
	    doNewfunctions=1;
	} else
	if (strcmp(argv[adrPos],&quot;-w&quot;)==0) {
	    doWrite=1;
	} else
	if (strcmp(argv[adrPos],&quot;-b&quot;)==0) {
	    doBenchmark=1;
	} else
	if (strcmp(argv[adrPos],&quot;-z&quot;)==0) {
	    doSZLread=1;
	} else
	if (strcmp(argv[adrPos],&quot;-a&quot;)==0) {
	    doSZLreadAll=1;
	} else
	if (strcmp(argv[adrPos],&quot;-m&quot;)==0) {
	    doMultiple=1;
	}
	adrPos++;
	if (argc&lt;=adrPos) {
	    usage();
	    exit(-1);
	}	
    }    

    fds.rfd=openSocket(102, argv[adrPos]);
#ifdef PLAY_WITH_KEEPALIVE
    errno=0;    
    opt=1;
    res=setsockopt(fds.rfd, SOL_SOCKET, SO_KEEPALIVE, &amp;opt, 4);
    LOG3(&quot;setsockopt %s %d\n&quot;, strerror(errno),res);
#endif
    fds.wfd=fds.rfd;

    if (fds.rfd&gt;0) { 
	di =daveNewInterface(fds,&quot;IF1&quot;,0, useProtocol, daveSpeed187k);
	daveSetTimeout(di,5000000);
	dc =daveNewConnection(di,2,0,useSlot);  // insert your rack and slot here

	if (0==daveConnectPLC(dc)) {
	    printf(&quot;Connected.\n&quot;);
//	    di-&gt;timeout=1000;
/*		
	printf(&quot;Trying to read 1 byte from system data,address 0x1e3 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0x1e3,1,NULL);

	printf(&quot;Trying to read 20 bytes from system data,address 0 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0,20,NULL);
*
	printf(&quot;Trying to read 64 bytes (16 dwords) from data block 1.\n&quot;);
	wait();
	res=daveReadBytes(dc,daveDB,1,0,64,NULL);
        if(0==res) {
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW0: %d\n&quot;,a);
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW1: %d\n...\n&quot;,a);
	    a=daveGetU16At(dc,62);
	    printf(&quot;DB1:DW32: %d\n&quot;,a);
	} else 
	    printf(&quot;failed! (%d)\n&quot;,res);  
	printf(&quot;Trying to read 16 bytes from FW0.\n&quot;);
	wait();
/*
 * Some comments about daveReadBytes():
 *
 * Here we read flags and not data blocks, because we cannot know which data blocks will
 * exist in a user's PLC, but flags are always present. To read from data block 5 use:
 * 	daveReadBytes(dc, daveDB, 5, 0, 16, NULL);
 * to read DBD68 and DBW72 use:
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, NULL);
 * to read DBD68 and DBW72 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, appBuffer);
 * to read DBD68 and DBD78 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 14, appBuffer);
 * this reads DBD68 and DBD78 and everything in between and fills the range
 * appBuffer+4 to appBuffer+9 with unwanted bytes, but is much faster than:
 *	daveReadBytes(dc, daveDB, 5, 68, 4, appBuffer);
 *	daveReadBytes(dc, daveDB, 5, 78, 4, appBuffer+4);
 *
 * Users of the 200 family please note:
 * The 200 family PLCs have the V area. This is accessed like a datablock with number 1.
 * This is not a quirk or convention introduced by libnodave, but the command transmitted 
 * to the PLC is exactly the same that would read from DB1 off a 300 or 400.
 *
 *	
	res=daveReadBytes(dc,daveFlags,0,0,16,NULL);
	if (0==res) { 
/
 *	daveGetU32(dc); reads a word (2 bytes) from the current buffer position and increments
 *	an internal pointer by 2, so next daveGetXXX() wil read from the new position behind that
 *	word. If you want to read from a position you specify, use daveGetU16at(dc, position).	
 *	
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	}  else 
	    printf(&quot;failed! (%d)\n&quot;,res);  */

	if(doSZLread) {
	    readSZL(dc,0xA0,0x0);
	    readSZL(dc,0x92,0x0);
	    readSZL(dc,0xB4,0x1024);
	    readSZL(dc,0x111,0x1);
	    readSZL(dc,0x111,0x2);
	    readSZL(dc,0xD91,0x0);
	    readSZL(dc,0x232,0x4);
	    readSZL(dc,0x1A0,0x0);
	}    
	if(doSZLreadAll) {
	    readSZLAll(dc);
	}    
	if(doMultiple) {
    	    printf(&quot;Now testing read multiple variables.\n&quot;
		&quot;This will read 1 Byte from inputs,\n&quot;
		&quot;4 bytes from flags, 2 bytes from DB6\n&quot;
		&quot; and other 2 bytes from flags\n&quot;);
    	    wait();
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,12,2);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    printf(&quot;Input Byte 0 &quot;);
	    res=daveUseResult(dc, &amp;rs, 0); // first result
	    if (res==0) {
		a=daveGetU8(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag DWord 0 &quot;);	
	    res=daveUseResult(dc, &amp;rs, 1); // 2nd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;DB 6 Word 20: &quot;);	
	    res=daveUseResult(dc, &amp;rs, 2); // 3rd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag Word 12: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 3); // 4th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));	

	    printf(&quot;non existing result: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 4); // 5th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));		
	    daveFreeResults(&amp;rs);	

/*	    
	    for (i=0; i&lt;rs.numResults;i++) {
		r2=&amp;(rs.results[i]);
		printf(&quot;result: %s length:%d\n&quot;,daveStrerror(r2-&gt;error), r2-&gt;length);
		res=daveUseResult(dc, &amp;rs, i);
		if (r2-&gt;length&gt;0) _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
		if (r2-&gt;bytes!=NULL) {
	    	    _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
	            d=daveGetFloat(dc);
	            printf(&quot;FD12: %f\n&quot;,d);
		}	 
	    }
*/	    
	}	    

	if(doWrite) {
    	    printf(&quot;\n           @@@ Hier werden die gewuenschte 'area' ueberschrieben. @@@\n&quot;);
	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen vor dem Schreiben\n&quot;);

	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);

	   // Hauptmenu
          printf(&quot;\nSie sind in der Hauptmenu:\n&quot;);
	    printf(&quot;\nBitte geben Sie die gewuenschte 'Schreibweise':\n \n Bit  = 1\n Byte = 2\n Wort = 3\n\n&quot;);
          scanf(&quot;\n%d&quot;, &amp;menu);   

          switch (menu) {

           case 1:       {
            printf(&quot;\nBitte geben die Position der Bit ein Bsp: E0.0=0 und E1.0=8 sowie E2.0=16 ...\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bitp);    
            printf(&quot;\nBitte geben Sie der binaer-wert '0' oder '1'\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bit);
            printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBits(dc, daveOutputs, 0, bitp,1, &amp;bit);
                         break;
                      case 2:
                        res=daveWriteBits(dc, daveInputs, 0, bitp,1, &amp;bit);
                         break;
                      case 3:
                        res=daveWriteBits(dc, daveFlags, 0, bitp,1, &amp;bit);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBits(dc, daveDB, dbnr, bitp,1, &amp;bit);
                         break;
                      case 5:
                        res=daveWriteBits(dc, daveTimer, 0, bitp,1, &amp;bit);
                          break;
                       case 6:
                        res=daveWriteBits(dc, daveCounter, 0, bitp,1, &amp;bit);
                          break;

                                        }
		    break;  }

                case 2:  {
                  printf(&quot;\nBitte geben die Byte-Position ein Bsp: Byte0 = 0, Byte1 = 1 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der byte\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,1, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,1, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,1, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,1, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,1, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,1, &amp;byte);
                          break;

                                        }
		    break;  }

                  case 3:  {
                  printf(&quot;\nBitte geben die Byte-Position (an welche der Wort startet)  ein Bsp: Byte0 = 0, Byte4 = 4 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der Wort\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,4, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,4, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,4, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,4, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,4, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,4, &amp;byte);
                          break;

                                        }
		    break;    }

                                 }

	   printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen nach dem Schreiben\n&quot;);
	   res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
    	   printf(&quot;\nErgebnis:%d=%s\n&quot;, res, daveStrerror(res));	  

	} // doWrite
	if(doClear) {
    	    printf(&quot;Now writing 0 to the bytes FB0...FB15.\n&quot;);
    	    wait();
	    a=0;
    	    daveWriteBytes(dc,daveFlags,0,0,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,4,4,&amp;a);
	    daveWriteBytes(dc,daveFlags,0,8,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,12,4,&amp;a);
	    daveReadBytes(dc,daveFlags,0,0,16,NULL);
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	} // doClear

	if(doNewfunctions) {
	    saveDebug=daveGetDebug();

	    printf(&quot;\nTrying to read two consecutive bits from DB11.DBX0.1 (supposed to fail)\n&quot;);;
	    res=daveReadBits(dc, daveDB, 11, 1, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read no bit (length 0) from DB17.DBX0.1 (supposed to fail)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 1, 0,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    daveSetDebug(daveGetDebug()|daveDebugPDU); 
	    printf(&quot;\nTrying to read a single bit from DB17.DBX0.3 (supposed to work if you have a DB17)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 3, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read a single bit from E0.2 (supposed to work)\n&quot;);
	    res=daveReadBits(dc, daveInputs, 0, 2, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=0;
	    printf(&quot;\nWriting 0 to EB0 (supposed to work)\n&quot;);
	    res=daveWriteBytes(dc, daveOutputs, 0, 0, 1, &amp;a);

	    a=1;
	    printf(&quot;\nTrying to set single bit E0.5 (supposed to work)\n&quot;);
	    res=daveWriteBits(dc, daveOutputs, 0, 5, 1, &amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 1 byte from AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveReadBytes(dc, daveAnaIn, 0, 0, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=2341;
	    printf(&quot;\nTrying to write 1 word (2 bytes) to AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveWriteBytes(dc, daveAnaOut, 0, 0, 2,&amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 4 items from Timers (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveTimer, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetSeconds(dc)\n&quot;);
		d=daveGetSeconds(dc);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot; %0.3f\n&quot;,d);
		printf(&quot;\nShowing the same results using daveGetSecondsAt(dc,position)\n&quot;);
		d=daveGetSecondsAt(dc,0);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,2);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,4);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,6);
		printf(&quot; %0.3f\n&quot;,d);
	    }
	    printf(&quot;\nTrying to read 4 items from Counters (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveCounter, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));
	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetCounterValue(dc)\n&quot;);
		c=daveGetCounterValue(dc);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot; %d\n&quot;,c);

		printf(&quot;\nShowing the same results using daveGetCounterValueAt(dc, position)\n&quot;);
		c=daveGetCounterValueAt(dc,0);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValueAt(dc,2);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,4);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,6);
		printf(&quot; %d\n&quot;,c);
	    }

	    printf(&quot;\nTrying to read multiple items with multiple variable read. (1st 2 supposed to work ok, rests may debend on CPU type and contents)\n&quot;);
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,2,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,2,4);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    daveSetDebug(saveDebug);
	}

	if(doStop) {
	    daveStop(dc);
	}
	if(doRun) {
	    daveStart(dc);
	}
	if(doReadout) {
	    printf(&quot;\nDie 8 Byte Eingaenge werden byteweise gelesen\n&quot;);
	//wait();
	res=daveReadBytes(dc,daveInputs,0,0,8,NULL);

	    a=daveGetU8(dc);
	    printf(&quot;\nE0.0:E0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E1.0:E1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E2.0:E2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E3.0:E3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nE4.0:E4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E5.0:E5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E6.0:E6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E7.0:E7.7: %d\n&quot;,a);

	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen\n&quot;);

	//wait();
	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

             a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
	    /*a=daveGetU16At(dc,4);        Diese Variante mit Byte-Offset
	    printf(&quot;DB1:DW32: %d\n&quot;,a);*/

}

	if(doBenchmark) {
	    if(useProtocol==daveProtoISOTCP243) { // we have a 200 CPU, use V memory
		rBenchmark(dc, daveDB);
	        if(doWrite) {
		    wBenchmark(dc, daveDB);
	        } // doWrite
	    } else {				// we have a 300/400 CPU, use Flags(Merkers)
		rBenchmark(dc, daveFlags);
		if(doWrite) {
		    wBenchmark(dc, daveFlags);
		} // doWrite
	    }	
	} // doBenchmark

	printf(&quot;Finished.\n&quot;);
	return 0;
	} else {
	    printf(&quot;Couldn't connect to PLC.\n Please make sure you use the -2 option with a CP243 but not with CPs 343 or 443.\n&quot;);	
	    return -2;
	}
    } else {
	printf(&quot;Couldn't open TCP port. \nPlease make sure a CP is connected and the IP address is ok. \n&quot;);	
    	return -1;
    }    
}

/*
    Changes: 
    07/19/04  removed unused vars.
    09/09/04  applied patch for variable Profibus speed from Andrew Rostovtsew.
    09/09/04  removed unused includes byteswap.h. Made some code to test TCP keepalive conditional.
    03/03/05  added slot select option.
    03/28/05  changed code to use flag (M) area for write. Was DB17.
    04/09/05  removed CYGWIN defines. As there were no more differences against LINUX, it should 
	      work with LINUX defines.
*/
//#define PLAY_WITH_KEEPALIVE
#include &quot;C:\Programme\National Instruments\LabVIEW 7.0\cintools\extcode.h&quot;
#pragma comment(lib, &quot;libnodave.lib&quot;)
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#define BCCWIN
#include &quot;nodavesimple.h&quot;
#include &quot;openSocket.h&quot;

#ifdef LINUX
#include &lt;unistd.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;fcntl.h&gt;
#define UNIX_STYLE
#endif

#ifdef BCCWIN
#include &lt;time.h&gt;
void usage(void);
void wait(void);

#define WIN_STYLE    
#endif

#ifdef PLAY_WITH_KEEPALIVE
#include &lt;sys/socket.h&gt;
#endif
#include &lt;errno.h&gt;
//************************************************************************
void readSZL(daveConnection *dc,int id, int index)
{
    int res, SZLid, indx, SZcount, SZlen,i,j,len;
    uc * d,*dd;
    uc ddd[3000];
    printf(&quot;Trying to read SZL-ID %04X index %02X.\n&quot;,id,index);
    res=daveReadSZL(dc,id,index, ddd, 3000);
    printf(&quot;Function result: %d %s len:%d\n&quot;,res,daveStrerror(res),dc-&gt;AnswLen);
//    _daveDump(&quot;Data&quot;,dc-&gt;resultPointer,dc-&gt;AnswLen);
    _daveDump(&quot;Data&quot;,ddd,dc-&gt;AnswLen);

    if ((dc-&gt;AnswLen)&gt;=4) {
	d=ddd;
        dd=ddd;
	dd+=8;
	len=dc-&gt;AnswLen-8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    if(len&gt;0){
	    for (i=0;i&lt;SZcount;i++){
		if(len&gt;0){
		for (j=0; j&lt;SZlen; j++){
		    if(len&gt;0){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		    }
		    len--;
		}
		printf(&quot;\n&quot;);
		}
	    }
	    }
	}
    }
    printf(&quot;\n&quot;);
}    

void readSZLAll(daveConnection *dc) {
    uc SzlList[1000];
    int res, SZLid, indx, SZcount, SZlen,i,j, rid, rind;
    uc * d,*dd;

    res=daveReadSZL(dc,0,0,SzlList, 1000);
    printf(&quot;%d %d\n&quot;,res,dc-&gt;AnswLen);
    if ((dc-&gt;AnswLen)&gt;=4) {
	d=dc-&gt;resultPointer;
        dd=SzlList;
	dd+=8;
	SZLid=0x100*d[0]+d[1]; 
        indx=0x100*d[2]+d[3]; 
	printf(&quot;result SZL ID %04X %02X \n&quot;,SZLid,indx);

	if ((dc-&gt;AnswLen)&gt;=8) {
    	    SZlen=0x100*d[4]+d[5]; 
    	    SZcount=0x100*d[6]+d[7]; 
	    printf(&quot;%d elements of %d bytes\n&quot;,SZcount,SZlen);
	    for (i=0;i&lt;SZcount;i++){
//		rind=*dd;
//		rid=*(dd+1); 
		rid=*(dd+1)+256*(*dd); 
		rind=0;
		printf(&quot;ID:%04X Index:%02X\n&quot;,rid,rind);
		readSZL(dc, rid, rind);
		for (j=0; j&lt;SZlen; j++){
		    printf(&quot;%02X,&quot;,*dd);
		    dd++;
		}
		printf(&quot;\nID:%04X Index:%02X\n&quot;,rid,rind);

	    }
	}
    }
    printf(&quot;\n&quot;);
}

void wait() {
    uc c;
    printf(&quot;Press return to continue.\n&quot;);
#ifdef UNIX_STYLE
    read(0,&amp;c,1);
#endif
}    
 void usage()
{
    printf(&quot;Usage: testISO_TCP [-d] [-w] IP-Address of CP\n&quot;);
    printf(&quot;-2 uses a protocol variant for the CP243. You need to set it, if you use such a CP.\n&quot;);
    printf(&quot;-w will try to write to Flag words. It will overwrite FB0 to FB15 (MB0 to MB15) !\n&quot;);
    printf(&quot;-d will produce a lot of debug messages.\n&quot;);
    printf(&quot;-b will run benchmarks. Specify -b and -w to run write benchmarks.\n&quot;);
    printf(&quot;-m will run a test for multiple variable reads.\n&quot;);
    printf(&quot;-c will write 0 to the PLC memory used in write tests.\n&quot;);
    printf(&quot;-z will read some SZL list items (diagnostic information).\n&quot;
	    &quot;  Works 300 and 400 family only.\n&quot;);
    printf(&quot;-s stops the PLC.\n&quot;);
    printf(&quot;-r tries to put the PLC in run mode.\n&quot;);
    printf(&quot;--readout read program and data blocks from PLC.\n&quot;);
    printf(&quot;--readoutall read all program and data blocks from PLC. Includes SFBs and SFCs.\n&quot;);
    printf(&quot;--slot=&lt;number&gt; sets slot for PLC (default is 2).\n&quot;);
    printf(&quot;--debug=&lt;number&gt; will set daveDebug to number.\n&quot;);
    printf(&quot;Example: testISO_TCP -w 192.168.19.1\n&quot;);
}

void loadBlocksOfType(daveConnection * dc, int blockType) {
    int j, i, uploadID, len, more;
#ifdef UNIX_STYLE
    int fd;
#endif	        
#ifdef WIN_STYLE	    
    HANDLE fd;
    unsigned long res;
#endif	        
    char blockName [20];
    uc blockBuffer[20000],*bb;
    daveBlockEntry dbe[256];   
    j=daveListBlocksOfType(dc, blockType, dbe);
    if (j&lt;0) {
	printf(&quot;error %d = %s\n&quot;,-j,daveStrerror(-j));
	return;
    }
    printf(&quot;%d blocks of type %s\n&quot;,j,daveBlockName(blockType));
    for (i=0; i&lt;j; i++) {
	printf(&quot;%s%d  %d %d\n&quot;,
	    daveBlockName(blockType),
	    dbe[i].number, dbe[i].type[0],dbe[i].type[1]);	
	bb=blockBuffer;
	len=0;
	if (0==initUpload(dc, blockType, dbe[i].number, &amp;uploadID)) {
    	    do {
		doUpload(dc,&amp;more,&amp;bb,&amp;len,uploadID);
	    } while (more);
	    sprintf(blockName,&quot;%s%d.mc7&quot;,daveBlockName(blockType), dbe[i].number);	
#ifdef UNIX_STYLE
    	    fd=open(blockName,O_RDWR|O_CREAT|O_TRUNC,0644);
    	    write(fd, blockBuffer, len);
    	    close(fd);
#endif	    
#ifdef WIN_STYLE
	    fd = CreateFile(blockName,
    	      GENERIC_WRITE, 0, 0, 2,
    		FILE_FLAG_WRITE_THROUGH, 0);
    	    WriteFile(fd, blockBuffer, len, &amp;res, NULL);
    	    CloseHandle(fd);
#endif	    

    	    endUpload(dc,uploadID);
	}    
    }
}

#include &quot;benchmark.c&quot;

int main(int argc, char **argv) {
  int const start = 12;
  int a,b,c,menu,dbnr,area,bit,byte,bitp,bytep,adrPos,doWrite,doBenchmark, doSZLread, doMultiple, doClear,
	res, useProtocol,doSZLreadAll, doRun, doStop, doReadout, doSFBandSFC,
	doNewfunctions, saveDebug,
	useSlot;
#ifdef PLAY_WITH_KEEPALIVE    	
    int opt;
#endif    
    float d;
    daveInterface * di;
    daveConnection * dc;
    _daveOSserialType fds;
    PDU p;
    daveResultSet rs;

    daveSetDebug(daveDebugPrintErrors);
    adrPos=1;
    doWrite=0;
    doBenchmark=0;
    doMultiple=0;
    doClear=0;
    doSZLread=0;
    doSZLreadAll=0;
    doRun=0;
    doStop=0;
    doReadout=0;
    doSFBandSFC=0;
    doNewfunctions=0;

    useProtocol=daveProtoISOTCP;
    useSlot=2;

    if (argc&lt;2) {
	usage();
	exit(-1);
    }    

    while (argv[adrPos][0]=='-') {
	if (strcmp(argv[adrPos],&quot;-2&quot;)==0) {
	    useProtocol=daveProtoISOTCP243;
	} else	if (strncmp(argv[adrPos],&quot;--debug=&quot;,8)==0) {
	    daveSetDebug(atol(argv[adrPos]+8));
	    printf(&quot;setting debug to: 0x%lx\n&quot;,atol(argv[adrPos]+8));
	} else if (strcmp(argv[adrPos],&quot;-s&quot;)==0) {
	    doStop=1;
	} else if (strcmp(argv[adrPos],&quot;-r&quot;)==0) {
	    doRun=1;
	} else if (strncmp(argv[adrPos],&quot;--readoutall&quot;,12)==0) {
	    doReadout=1;
	    doSFBandSFC=1;
	} else if (strncmp(argv[adrPos],&quot;--readout&quot;,9)==0) {
	    doReadout=1;
	} else if (strncmp(argv[adrPos],&quot;--slot=&quot;,7)==0) {
	    useSlot=atol(argv[adrPos]+7);
	} else if (strcmp(argv[adrPos],&quot;-d&quot;)==0) {
	    daveSetDebug(daveDebugAll);
	} else if (strcmp(argv[adrPos],&quot;-n&quot;)==0) {
	    doNewfunctions=1;
	} else
	if (strcmp(argv[adrPos],&quot;-w&quot;)==0) {
	    doWrite=1;
	} else
	if (strcmp(argv[adrPos],&quot;-b&quot;)==0) {
	    doBenchmark=1;
	} else
	if (strcmp(argv[adrPos],&quot;-z&quot;)==0) {
	    doSZLread=1;
	} else
	if (strcmp(argv[adrPos],&quot;-a&quot;)==0) {
	    doSZLreadAll=1;
	} else
	if (strcmp(argv[adrPos],&quot;-m&quot;)==0) {
	    doMultiple=1;
	}
	adrPos++;
	if (argc&lt;=adrPos) {
	    usage();
	    exit(-1);
	}	
    }    

    fds.rfd=openSocket(102, argv[adrPos]);
#ifdef PLAY_WITH_KEEPALIVE
    errno=0;    
    opt=1;
    res=setsockopt(fds.rfd, SOL_SOCKET, SO_KEEPALIVE, &amp;opt, 4);
    LOG3(&quot;setsockopt %s %d\n&quot;, strerror(errno),res);
#endif
    fds.wfd=fds.rfd;

    if (fds.rfd&gt;0) { 
	di =daveNewInterface(fds,&quot;IF1&quot;,0, useProtocol, daveSpeed187k);
	daveSetTimeout(di,5000000);
	dc =daveNewConnection(di,2,0,useSlot);  // insert your rack and slot here

	if (0==daveConnectPLC(dc)) {
	    printf(&quot;Connected.\n&quot;);
//	    di-&gt;timeout=1000;
/*		
	printf(&quot;Trying to read 1 byte from system data,address 0x1e3 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0x1e3,1,NULL);

	printf(&quot;Trying to read 20 bytes from system data,address 0 like MicroWin does.\n&quot;);
	daveReadBytes(dc,3,0,0,20,NULL);
*
	printf(&quot;Trying to read 64 bytes (16 dwords) from data block 1.\n&quot;);
	wait();
	res=daveReadBytes(dc,daveDB,1,0,64,NULL);
        if(0==res) {
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW0: %d\n&quot;,a);
	    a=daveGetU16(dc);
	    printf(&quot;DB1:DW1: %d\n...\n&quot;,a);
	    a=daveGetU16At(dc,62);
	    printf(&quot;DB1:DW32: %d\n&quot;,a);
	} else 
	    printf(&quot;failed! (%d)\n&quot;,res);  
	printf(&quot;Trying to read 16 bytes from FW0.\n&quot;);
	wait();
/*
 * Some comments about daveReadBytes():
 *
 * Here we read flags and not data blocks, because we cannot know which data blocks will
 * exist in a user's PLC, but flags are always present. To read from data block 5 use:
 * 	daveReadBytes(dc, daveDB, 5, 0, 16, NULL);
 * to read DBD68 and DBW72 use:
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, NULL);
 * to read DBD68 and DBW72 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 6, appBuffer);
 * to read DBD68 and DBD78 into your applications buffer appBuffer use:	
 * 	daveReadBytes(dc, daveDB, 5, 68, 14, appBuffer);
 * this reads DBD68 and DBD78 and everything in between and fills the range
 * appBuffer+4 to appBuffer+9 with unwanted bytes, but is much faster than:
 *	daveReadBytes(dc, daveDB, 5, 68, 4, appBuffer);
 *	daveReadBytes(dc, daveDB, 5, 78, 4, appBuffer+4);
 *
 * Users of the 200 family please note:
 * The 200 family PLCs have the V area. This is accessed like a datablock with number 1.
 * This is not a quirk or convention introduced by libnodave, but the command transmitted 
 * to the PLC is exactly the same that would read from DB1 off a 300 or 400.
 *
 *	
	res=daveReadBytes(dc,daveFlags,0,0,16,NULL);
	if (0==res) { 
/
 *	daveGetU32(dc); reads a word (2 bytes) from the current buffer position and increments
 *	an internal pointer by 2, so next daveGetXXX() wil read from the new position behind that
 *	word. If you want to read from a position you specify, use daveGetU16at(dc, position).	
 *	
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	}  else 
	    printf(&quot;failed! (%d)\n&quot;,res);  */

	if(doSZLread) {
	    readSZL(dc,0xA0,0x0);
	    readSZL(dc,0x92,0x0);
	    readSZL(dc,0xB4,0x1024);
	    readSZL(dc,0x111,0x1);
	    readSZL(dc,0x111,0x2);
	    readSZL(dc,0xD91,0x0);
	    readSZL(dc,0x232,0x4);
	    readSZL(dc,0x1A0,0x0);
	}    
	if(doSZLreadAll) {
	    readSZLAll(dc);
	}    
	if(doMultiple) {
    	    printf(&quot;Now testing read multiple variables.\n&quot;
		&quot;This will read 1 Byte from inputs,\n&quot;
		&quot;4 bytes from flags, 2 bytes from DB6\n&quot;
		&quot; and other 2 bytes from flags\n&quot;);
    	    wait();
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,12,2);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    printf(&quot;Input Byte 0 &quot;);
	    res=daveUseResult(dc, &amp;rs, 0); // first result
	    if (res==0) {
		a=daveGetU8(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag DWord 0 &quot;);	
	    res=daveUseResult(dc, &amp;rs, 1); // 2nd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;DB 6 Word 20: &quot;);	
	    res=daveUseResult(dc, &amp;rs, 2); // 3rd result
	    if (res==0) {
		a=daveGetS16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));

	    printf(&quot;Flag Word 12: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 3); // 4th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));	

	    printf(&quot;non existing result: &quot;);		
	    res=daveUseResult(dc, &amp;rs, 4); // 5th result
	    if (res==0) {
		a=daveGetU16(dc);
        	printf(&quot;%d\n&quot;,a);
	    } else 
		printf(&quot;*** Error: %s\n&quot;,daveStrerror(res));		
	    daveFreeResults(&amp;rs);	

/*	    
	    for (i=0; i&lt;rs.numResults;i++) {
		r2=&amp;(rs.results[i]);
		printf(&quot;result: %s length:%d\n&quot;,daveStrerror(r2-&gt;error), r2-&gt;length);
		res=daveUseResult(dc, &amp;rs, i);
		if (r2-&gt;length&gt;0) _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
		if (r2-&gt;bytes!=NULL) {
	    	    _daveDump(&quot;bytes&quot;,r2-&gt;bytes,r2-&gt;length);
	            d=daveGetFloat(dc);
	            printf(&quot;FD12: %f\n&quot;,d);
		}	 
	    }
*/	    
	}	    

	if(doWrite) {
    	    printf(&quot;\n           @@@ Hier werden die gewuenschte 'area' ueberschrieben. @@@\n&quot;);
	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen vor dem Schreiben\n&quot;);

	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);

	   // Hauptmenu
          printf(&quot;\nSie sind in der Hauptmenu:\n&quot;);
	    printf(&quot;\nBitte geben Sie die gewuenschte 'Schreibweise':\n \n Bit  = 1\n Byte = 2\n Wort = 3\n\n&quot;);
          scanf(&quot;\n%d&quot;, &amp;menu);   

          switch (menu) {

           case 1:       {
            printf(&quot;\nBitte geben die Position der Bit ein Bsp: E0.0=0 und E1.0=8 sowie E2.0=16 ...\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bitp);    
            printf(&quot;\nBitte geben Sie der binaer-wert '0' oder '1'\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;bit);
            printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
            scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBits(dc, daveOutputs, 0, bitp,1, &amp;bit);
                         break;
                      case 2:
                        res=daveWriteBits(dc, daveInputs, 0, bitp,1, &amp;bit);
                         break;
                      case 3:
                        res=daveWriteBits(dc, daveFlags, 0, bitp,1, &amp;bit);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBits(dc, daveDB, dbnr, bitp,1, &amp;bit);
                         break;
                      case 5:
                        res=daveWriteBits(dc, daveTimer, 0, bitp,1, &amp;bit);
                          break;
                       case 6:
                        res=daveWriteBits(dc, daveCounter, 0, bitp,1, &amp;bit);
                          break;

                                        }
		    break;  }

                case 2:  {
                  printf(&quot;\nBitte geben die Byte-Position ein Bsp: Byte0 = 0, Byte1 = 1 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der byte\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,1, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,1, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,1, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,1, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,1, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,1, &amp;byte);
                          break;

                                        }
		    break;  }

                  case 3:  {
                  printf(&quot;\nBitte geben die Byte-Position (an welche der Wort startet)  ein Bsp: Byte0 = 0, Byte4 = 4 ...\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;bytep);    
                  printf(&quot;\nBitte geben Sie der decimale-wert der Wort\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;byte);
                  printf(&quot;\nBitte geben Sie die gewuenschte 'area': \ndaveOutputs = 1, daveInputs = 2, daveFlags = 3, daveDB = 4, daveTimer = 5, daveCounter = 6\n&quot;);
                  scanf(&quot;\n%d&quot;, &amp;area);            

                     switch (area) {

                      case 1:
                        res=daveWriteBytes(dc, daveOutputs, 0, bytep,4, &amp;byte);
                         break;
                      case 2:
                        res=daveWriteBytes(dc, daveInputs, 0, bytep,4, &amp;byte);
                         break;
                      case 3:
                        res=daveWriteBytes(dc, daveFlags, 0, bytep,4, &amp;byte);
                          break;
			  case 4:
			     printf(&quot;\nBitte geben Sie der DB-Nummer\n&quot;);
                         scanf(&quot;\n%d&quot;, &amp;dbnr);
                        res=daveWriteBytes(dc, daveDB, dbnr, bytep,4, &amp;byte);
                         break;
                      case 5:
                        res=daveWriteBytes(dc, daveTimer, 0, bytep,4, &amp;byte);
                          break;
                       case 6:
                        res=daveWriteBytes(dc, daveCounter, 0, bytep,4, &amp;byte);
                          break;

                                        }
		    break;    }

                                 }

	   printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen nach dem Schreiben\n&quot;);
	   res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

           a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
    	   printf(&quot;\nErgebnis:%d=%s\n&quot;, res, daveStrerror(res));	  

	} // doWrite
	if(doClear) {
    	    printf(&quot;Now writing 0 to the bytes FB0...FB15.\n&quot;);
    	    wait();
	    a=0;
    	    daveWriteBytes(dc,daveFlags,0,0,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,4,4,&amp;a);
	    daveWriteBytes(dc,daveFlags,0,8,4,&amp;a);
    	    daveWriteBytes(dc,daveFlags,0,12,4,&amp;a);
	    daveReadBytes(dc,daveFlags,0,0,16,NULL);
    	    a=daveGetU32(dc);
    	    b=daveGetU32(dc);
    	    c=daveGetU32(dc);
    	    d=daveGetFloat(dc);
	    printf(&quot;FD0: %d\n&quot;,a);
	    printf(&quot;FD4: %d\n&quot;,b);
	    printf(&quot;FD8: %d\n&quot;,c);
	    printf(&quot;FD12: %f\n&quot;,d);
	} // doClear

	if(doNewfunctions) {
	    saveDebug=daveGetDebug();

	    printf(&quot;\nTrying to read two consecutive bits from DB11.DBX0.1 (supposed to fail)\n&quot;);;
	    res=daveReadBits(dc, daveDB, 11, 1, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read no bit (length 0) from DB17.DBX0.1 (supposed to fail)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 1, 0,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    daveSetDebug(daveGetDebug()|daveDebugPDU); 
	    printf(&quot;\nTrying to read a single bit from DB17.DBX0.3 (supposed to work if you have a DB17)\n&quot;);
	    res=daveReadBits(dc, daveDB, 17, 3, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read a single bit from E0.2 (supposed to work)\n&quot;);
	    res=daveReadBits(dc, daveInputs, 0, 2, 1,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=0;
	    printf(&quot;\nWriting 0 to EB0 (supposed to work)\n&quot;);
	    res=daveWriteBytes(dc, daveOutputs, 0, 0, 1, &amp;a);

	    a=1;
	    printf(&quot;\nTrying to set single bit E0.5 (supposed to work)\n&quot;);
	    res=daveWriteBits(dc, daveOutputs, 0, 5, 1, &amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 1 byte from AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveReadBytes(dc, daveAnaIn, 0, 0, 2,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    a=2341;
	    printf(&quot;\nTrying to write 1 word (2 bytes) to AAW0 (supposed to work on S7-2xx)\n&quot;);
	    res=daveWriteBytes(dc, daveAnaOut, 0, 0, 2,&amp;a);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    printf(&quot;\nTrying to read 4 items from Timers (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveTimer, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));

	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetSeconds(dc)\n&quot;);
		d=daveGetSeconds(dc);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSeconds(dc);
		printf(&quot; %0.3f\n&quot;,d);
		printf(&quot;\nShowing the same results using daveGetSecondsAt(dc,position)\n&quot;);
		d=daveGetSecondsAt(dc,0);
		printf(&quot;Time: %0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,2);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,4);
		printf(&quot;%0.3f, &quot;,d);
		d=daveGetSecondsAt(dc,6);
		printf(&quot; %0.3f\n&quot;,d);
	    }
	    printf(&quot;\nTrying to read 4 items from Counters (supposed to work S7-3xx/4xx)\n&quot;);
	    res=daveReadBytes(dc, daveCounter, 0, 0, 4,NULL);
	    printf(&quot;function result:%d=%s\n&quot;, res, daveStrerror(res));
	    if (res==0) {
		printf(&quot;\nShowing the results using daveGetCounterValue(dc)\n&quot;);
		c=daveGetCounterValue(dc);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValue(dc);
		printf(&quot; %d\n&quot;,c);

		printf(&quot;\nShowing the same results using daveGetCounterValueAt(dc, position)\n&quot;);
		c=daveGetCounterValueAt(dc,0);
		printf(&quot;Count: %d, &quot;,c);
		c=daveGetCounterValueAt(dc,2);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,4);
		printf(&quot;%d, &quot;,c);
		c=daveGetCounterValueAt(dc,6);
		printf(&quot; %d\n&quot;,c);
	    }

	    printf(&quot;\nTrying to read multiple items with multiple variable read. (1st 2 supposed to work ok, rests may debend on CPU type and contents)\n&quot;);
	    davePrepareReadRequest(dc, &amp;p);
	    daveAddVarToReadRequest(&amp;p,daveInputs,0,0,1);
	    daveAddVarToReadRequest(&amp;p,daveFlags,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveDB,6,20,2);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveTimer,0,2,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,0,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,1,4);
	    daveAddVarToReadRequest(&amp;p,daveCounter,0,2,4);
	    res=daveExecReadRequest(dc, &amp;p, &amp;rs);

	    daveSetDebug(saveDebug);
	}

	if(doStop) {
	    daveStop(dc);
	}
	if(doRun) {
	    daveStart(dc);
	}
	if(doReadout) {
	    printf(&quot;\nDie 8 Byte Eingaenge werden byteweise gelesen\n&quot;);
	//wait();
	res=daveReadBytes(dc,daveInputs,0,0,8,NULL);

	    a=daveGetU8(dc);
	    printf(&quot;\nE0.0:E0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E1.0:E1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E2.0:E2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E3.0:E3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nE4.0:E4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E5.0:E5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;E6.0:E6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;E7.0:E7.7: %d\n&quot;,a);

	    printf(&quot;\nDie 8 Byte Ausgaenge werden byteweise gelesen\n&quot;);

	//wait();
	res=daveReadBytes(dc,daveOutputs,0,0,8,NULL);

             a=daveGetU8(dc);
	    printf(&quot;\nA0.0:A0.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A1.0:A1.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A2.0:A2.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A3.0:A3.7: %d\n&quot;,a);
	     a=daveGetU8(dc);
	    printf(&quot;\nA4.0:A4.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A5.0:A5.7: %d\n&quot;,a);
           a=daveGetU8(dc);
	    printf(&quot;A6.0:A6.7: %d\n&quot;,a);
	    a=daveGetU8(dc);
	    printf(&quot;A7.0:A7.7: %d\n&quot;,a);
	    /*a=daveGetU16At(dc,4);        Diese Variante mit Byte-Offset
	    printf(&quot;DB1:DW32: %d\n&quot;,a);*/

}

	if(doBenchmark) {
	    if(useProtocol==daveProtoISOTCP243) { // we have a 200 CPU, use V memory
		rBenchmark(dc, daveDB);
	        if(doWrite) {
		    wBenchmark(dc, daveDB);
	        } // doWrite
	    } else {				// we have a 300/400 CPU, use Flags(Merkers)
		rBenchmark(dc, daveFlags);
		if(doWrite) {
		    wBenchmark(dc, daveFlags);
		} // doWrite
	    }	
	} // doBenchmark

	printf(&quot;Finished.\n&quot;);
	return 0;
	} else {
	    printf(&quot;Couldn't connect to PLC.\n Please make sure you use the -2 option with a CP243 but not with CPs 343 or 443.\n&quot;);	
	    return -2;
	}
    } else {
	printf(&quot;Couldn't open TCP port. \nPlease make sure a CP is connected and the IP address is ok. \n&quot;);	
    	return -1;
    }    
}

/*
    Changes: 
    07/19/04  removed unused vars.
    09/09/04  applied patch for variable Profibus speed from Andrew Rostovtsew.
    09/09/04  removed unused includes byteswap.h. Made some code to test TCP keepalive conditional.
    03/03/05  added slot select option.
    03/28/05  changed code to use flag (M) area for write. Was DB17.
    04/09/05  removed CYGWIN defines. As there were no more differences against LINUX, it should 
	      work with LINUX defines.
*/
</code></pre>
<p>//************************Fehler Fehlermeldungen***************************</p>
<p>1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) void __stdcall _daveDump(char *,unsigned char *,int)&quot; (__imp_?_daveDump@@YGXPADPAEH@Z)&quot; in Funktion &quot;&quot;void __cdecl readSZL(struct _daveConnection *,int,int)&quot; (?readSZL@@YAXPAU_daveConnection@@HH@Z)&quot;.<br />
1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) char * __stdcall daveStrerror(int)&quot; (__imp_?daveStrerror@@YGPADH@Z)&quot; in Funktion &quot;&quot;void __cdecl readSZL(struct _daveConnection *,int,int)&quot; (?readSZL@@YAXPAU_daveConnection@@HH@Z)&quot;.<br />
1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) int __stdcall daveReadSZL(struct _daveConnection *,int,int,void *,int)&quot; (__imp_?daveReadSZL@@YGHPAU_daveConnection@@HHPAXH@Z)&quot; in Funktion &quot;&quot;void __cdecl readSZL(struct _daveConnection *,int,int)&quot; (?readSZL@@YAXPAU_daveConnection@@HH@Z)&quot;.<br />
1&gt;test.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol &quot;&quot;__declspec(dllimport) int __stdcall endUpload(struct _daveConnection *,int)&quot; (__imp_?endUpload@@YGHPAU_daveConnection@@H@Z)&quot; in Funktion &quot;&quot;void __cdecl loadBlocksOfType(struct _daveConnection *,int)&quot; (?loadBlocksOfType@@YAXPAU_daveConnection@@H@Z)&quot;.</p>
<p>*****************************************************************************<br />
<a href="http://sourceforge.net/project/showfiles.php?group_id=61026" rel="nofollow">http://sourceforge.net/project/showfiles.php?group_id=61026</a> Davon können die nötigen headerdatein in &quot;libnodave 0.8.2&quot; unterladen werden.</p>
<p>Das Problem kann ich immer nicht lösen , ich hoffe , dass jemand mir hilft. Danke im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277323</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277323</guid><dc:creator><![CDATA[MarioLiu]]></dc:creator><pubDate>Wed, 02 May 2007 08:02:14 GMT</pubDate></item><item><title><![CDATA[Reply to Das Problem beim Kompilieren on Wed, 02 May 2007 08:08:14 GMT]]></title><description><![CDATA[<p>Und Du bist sicher, dass die LIB-Datei libnodave auch vorhanden ist und vom Linker gefunden wird.</p>
<p>Andernfalls müsste ich davon ausgehen, dass die entsprechenden Funktionen nicht implementiert wurden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277326</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277326</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 02 May 2007 08:08:14 GMT</pubDate></item><item><title><![CDATA[Reply to Das Problem beim Kompilieren on Wed, 02 May 2007 08:53:52 GMT]]></title><description><![CDATA[<p><a href="http://sourceforge.net/project/downloading.php?group_id=61026&amp;use_mirror=kent&amp;filename=libnodave-0.8.2.tar.gz&amp;75169197" rel="nofollow">http://sourceforge.net/project/downloading.php?group_id=61026&amp;use_mirror=kent&amp;filename=libnodave-0.8.2.tar.gz&amp;75169197</a> davon is sicher unterladbar. Alle nötigen headerdatein sind in &quot;libnodave 0.8.2&quot;. Wenn man das Programm lauf lässt , kommen die Fehlermeldungen immer, die ich nicht lösen kann.:(</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1277348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1277348</guid><dc:creator><![CDATA[MarioLiu]]></dc:creator><pubDate>Wed, 02 May 2007 08:53:52 GMT</pubDate></item></channel></rss>