using System; using System.Runtime.InteropServices; class test { static void wait() { } static void usage() { Console.WriteLine("Usage: testS7online [-d] [-w] access point"); Console.WriteLine("-w will try to write to Flag words. It will overwrite FB0 to FB15 (MB0 to MB15) !"); Console.WriteLine("-d will produce a lot of debug messages."); Console.WriteLine("-b will run benchmarks. Specify -b and -w to run write benchmarks."); Console.WriteLine("-z will read some SZL list items (diagnostic information)."); Console.WriteLine("-2 uses a slightly different version of the MPI protocol. Try it, if your Adapter doesn't work."); Console.WriteLine("-m will run a test for multiple variable reads."); Console.WriteLine("-c will write 0 to the PLC memory used in write tests."); Console.WriteLine("-n will test newly added functions."); Console.WriteLine("-a will read out everything from system state lists(SZLs)."); Console.WriteLine("-s stops the PLC."); Console.WriteLine("-r tries to put the PLC in run mode."); Console.WriteLine("--readout read program and data blocks from PLC."); Console.WriteLine("--readoutall read all program and data blocks from PLC. Includes SFBs and SFCs."); Console.WriteLine("- will set the speed of MPI/PROFIBUS network to this value (in kBaud). Default is 187. Supported values are 9, 19, 45, 93, 187, 500 and 1500."); Console.WriteLine("--mpi= will use number as the MPI adddres of the PLC. Default is 2."); Console.WriteLine("--mpi2= Use this option to test simultaneous connections to 2 PLCs."); Console.WriteLine(" It will use number as the MPI adddres of the 2nd PLC. Default is no 2nd PLC."); Console.WriteLine(" Most tests are executed with the first PLC. The first read test is also done with"); Console.WriteLine(" with the 2nd one to demonstrate that this works."); Console.WriteLine("--local= will set the local MPI adddres to number. Default is 0."); Console.WriteLine("--debug= will set daveDebug to number."); Console.WriteLine("Example: testS7online -w /S7ONLINE"); } static int initSuccess=0; static int localMPI=0; static int plcMPI=2; static int plc2MPI=-1; static int adrPos=0; static int useProto=libnodave.daveProtoS7online; static int speed=libnodave.daveSpeed187k; static libnodave.daveOSserialType fds; static libnodave.daveInterface di; static libnodave.daveConnection dc; static bool doWrite=false; static bool doClear=false; static bool doRun=false; static bool doStop=false; static bool doWbit=false; static int wbit; static bool doSZLread=false; static bool doSZLreadAll=false; static bool doBenchmark=false; static bool doReadout=false; static bool doSFBandSFC=false; static bool doExperimental=false; static bool doMultiple=false; static bool doNewfunctions=false; static void readSZL(libnodave.daveConnection dc, int id, int index) { int res, SZLid, indx, SZcount, SZlen,i,j,len; byte[] ddd=new byte[3000]; Console.WriteLine(String.Format("Trying to read SZL-ID {0:X04}, index {1:X02}",id,index)); res=dc.readSZL(id,index, ddd,3000); Console.WriteLine("Function result: "+res+" "+libnodave.daveStrerror(res)+" len:"+dc.getAnswLen()); if (dc.getAnswLen()>=4) { len=dc.getAnswLen()-8; SZLid=libnodave.getU16from(ddd,0); indx=libnodave.getU16from(ddd,2); Console.WriteLine(String.Format("result SZL ID {0:X04}, index {1:X02}",SZLid,indx)); int d=8; if (dc.getAnswLen()>=8) { SZlen=libnodave.getU16from(ddd,4); SZcount=libnodave.getU16from(ddd,6); Console.WriteLine(" "+SZcount+" elements of "+SZlen+" bytes"); if(len>0){ for (i=0;i0){ for (j=0; j0){ Console.Write(String.Format("{0:X02},",ddd[d])); d++; } len--; } Console.WriteLine(" "); } } } } } Console.WriteLine(" "); } static void readSZLAll(libnodave.daveConnection dc) { byte[] d=new byte[1000]; int res, SZLid, indx, SZcount, SZlen,i,j, rid, rind; res=dc.readSZL(0,0, d, 1000); Console.WriteLine(" "+res+" "+dc.getAnswLen()); if ((dc.getAnswLen())>=4) { SZLid=dc.getU16(); indx=dc.getU16(); Console.WriteLine(String.Format("result SZL ID {0:X04} index {1:X02}",SZLid,indx)); if ((dc.getAnswLen())>=8) { SZlen=0x100*d[4]+d[5]; SZcount=0x100*d[6]+d[7]; Console.WriteLine("%d elements of %d bytes\n",SZcount,SZlen); for (i=0;i=0) { di =new libnodave.daveInterface(fds, "IF1", localMPI, useProto, speed); di.setTimeout(5000000); for (i=0; i<3; i++) { if (0==di.initAdapter()) { initSuccess=1; a= di.listReachablePartners(buf1); Console.WriteLine("daveListReachablePartners List length: "+a); if (a>0) { for (j=0;j