AnsweredAssumed Answered

trouble of sending state file to instrument from PC using E4407B

Question asked by koala_kd on Oct 10, 2014
hi all:
I'm trying to send a state file to the instrument from PC using SCPI "mmem:data" in C++, but the instrument said "string data not allowed".

Below is my code, reading a state file from the instrument then sending it back to the instrument and loading the state file.

+// read a state file from E4407B+
+{+
       +ViSession defaultRM , vi;+
       +viOpenDefaultRM (&defaultRM );+
       +viOpen (defaultRM , "GPIB0::18::INSTR", VI_NULL ,VI_NULL , & vi);+
       +char buf [50000] = {0};+
       +viPrintf (vi , "MMEM:DEL 'R:State.sta'\n" );+
       +viPrintf (vi , "MMEM:STOR:STATe 1,'R:State.sta'\n" );+
      +Sleep(2500);+
      +viQueryf ( vi , "mmem:data? 'R:State.sta'\n" , "%t" , buf )+
      +// calculate the "#xyyyy"+
       +int nCount =0;+
       +int nDataSize =0;+
       +int nCalcTemp ;+
       +int i =0;+
       +nCount =buf [1]- '0';+
       +for (i =0; i< nCount ;i ++)+
      +{+
             +nCaclTemp =buf [2+ i]- '0' ;+
             +nDataSize =nDataSize *10+ nCalcTemp;+
      +}+
       +CFile fp ;+
       +fp .Open ( "d:\state1.sta", CFile :: modeCreate | CFile :: modeReadWrite |CFile :: typeBinary , NULL );+
       +fp .Write ( buf,2+nCount+nDataSize+1);+
       +fp .Close ();+
       +viClose (vi );+
       +viClose (defaultRM );+
+}+

+// send the saved state file back to E4407B+
+{+
       +ViSession defaultRM , vi;+
       +viOpenDefaultRM (&defaultRM );+
       +viOpen (defaultRM , "GPIB0::18::INSTR", VI_NULL ,VI_NULL , & vi);+
       +char buf [50000] = {0};+
          +CFile fp;+
       +fp . Open ( "d:\state1.sta" , CFile :: modeCreate| CFile ::modeNoTruncate | CFile :: modeReadWrite |CFile :: typeBinary , NULL );+
       +fp .Read ( buf, fp .GetLength ()); // read the whole file to the buffer+
       +fp .Close ();+
       +viPrintf ( vi, "mmem:delete 'R:State.sta'\n" );+
       +viPrintf ( vi, "mmem:data 'R:State.sta','%t'\n" , buf);+
       +viPrintf ( vi, "mmem:LOAD:STATe 1,'R:State.sta'\n" );+
       +viClose (vi );+
       +viClose (defaultRM );+
+}+
I think there is no problem in reading the file. The most problem is in *viPrintf ( vi, "mmem:data 'R:State.sta','%t'\n" , buf);*. The formation code isn't right, There is no such code I could refer. Could anybody help me? Many thanks.  

Attachments

Outcomes