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<SZcount;i++){ rid=libnodave.getU16from(d,i*SZlen+8); rind=0; Console.WriteLine(String.Format("\nID:{0:X04} index {1:X02}",rid,rind)); readSZL(dc, rid, rind); } } } Console.WriteLine("\n"); }
static void rBenchmark(libnodave.daveConnection dc, int bmArea) { int i,res,maxReadLen,areaNumber; double usec; long t1, t2; libnodave.resultSet rs=new libnodave.resultSet(); maxReadLen=dc.getMaxPDULen()-46; areaNumber=0; if(bmArea==libnodave.daveDB) areaNumber=1; Console.WriteLine("Now going to do read benchmark with minimum block length of 1.\n"); t1=Environment.TickCount; for (i=1;i<101;i++) { dc.readBytes(bmArea, areaNumber,0, 1, null); if (i%10==0) { Console.Write("..."+i); } } t2=Environment.TickCount; usec = 0.001 * (t2 - t1); Console.WriteLine(" 100 reads took "+usec+" secs."); Console.WriteLine("Now going to do read benchmark with shurely supported block length "+maxReadLen); t1=Environment.TickCount; for (i=1;i<101;i++) { dc.readBytes(bmArea, areaNumber, 0, maxReadLen, null); if (i%10==0) { Console.Write("..."+i); } } t2=Environment.TickCount; usec = 0.001 * (t2 - t1); Console.WriteLine(" 100 reads took "+usec+" secs. "); Console.WriteLine("Now going to do read benchmark with 5 variables in a single request."); Console.WriteLine("running..."); t1=Environment.TickCount; for (i=1;i<101;i++) { libnodave.PDU p=dc.prepareReadRequest(); p.addVarToReadRequest(libnodave.daveInputs,0,0,6); p.addVarToReadRequest(libnodave.daveFlags,0,0,6); p.addVarToReadRequest(libnodave.daveFlags,0,6,6); p.addVarToReadRequest(bmArea,areaNumber,4,54); p.addVarToReadRequest(bmArea,areaNumber,4,4); res=dc.execReadRequest(p, rs); if (res!=0) Console.WriteLine("\nerror "+res+" = "+libnodave.daveStrerror(res)); if (i%10==0) { Console.Write("..."+i); } } t2=Environment.TickCount; usec = 0.001 * (t2 - t1); Console.WriteLine(" 100 reads took "+usec+" secs."); }
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;i<SZcount;i++){ if(len>0){ for (j=0; j<SZlen; j++){ if(len>0){ Console.Write(String.Format("{0:X02},",ddd[d])); d++; } len--; } Console.WriteLine(" "); } } } } } Console.WriteLine(" "); }
static void loadBlocksOfType(libnodave.daveConnection dc, int blockType, bool doReadout) { int j, i, len, k; int res; byte[] blockBuffer=new byte[20000]; byte[] dbe=new byte[2000]; j=dc.ListBlocksOfType(blockType, dbe); if (j<0) { Console.WriteLine("error "+(-j)+" = " + libnodave.daveStrerror(-j)); return; } string blockName=libnodave.blockName(blockType); Console.WriteLine(j+" blocks of type "+blockName); for(i=0; i<j; i++) { int number=BitConverter.ToInt16(dbe,4*i+0); Console.WriteLine(libnodave.blockName(blockType)+" "+number); if(doReadout) { len=1111; dc.getProgramBlock(blockType, number, blockBuffer, ref(len)); blockName=libnodave.blockName(blockType)+number+".mc7"; FileStream fs= new FileStream(blockName,FileMode.CreateNew); BinaryWriter w= new BinaryWriter(fs); for (k=0; k<len; k++) w.Write(blockBuffer[k]); } } }