Posted Thu, 30 Mar 2023 23:11:57 GMT by Teles, Afonso
Hi Birjit,<br> <br> I would ask how you're communicating with the instrument (USB, Ethernet, etc) and how you're handling VISA timeout errors?<br> It's normal to have timeouts, especially during the transfer of long waveforms or files, so it's important that your code handles these properly. It might be useful to post the relevant code.
Posted Fri, 31 Mar 2023 12:16:35 GMT by Singha, Birjit
We are communicating with the instrument via USB. In order to avoid TekVisa timeout issues, we are adding some sleep time (delay) after every iteration. With this extra delay, we are successfully able to capture data from channel 1 without any issue only until some iterations. After that, the process gets paused, and it takes indefinite time to resume. But, when we extract data from both channel 1 and channel 2, even with the extra delay, tekVisa is getting timed out very soon.<br> <br> Some portion of the code:<br> &#160; <p>Random rand = new Random();</p> <br> int loop = 0;<br> // int delayTime = Delay;<br> int sampleLength = samples;<br> bool error = false;<br> <br> byte[] text_in = new byte[16];<br> byte[] text_out = new byte[16];<br> byte[] text_ans = new byte[16];<br> <br> VISA TVA = new VISA();<br> // Print list of VISA resources<br> TVA.FindResources(&quot;?*&quot;, out instrlist);<br> //TVA.Timeout(10000);<br> Console.WriteLine(&quot;Visa Resources&quot;);<br> for (j = 0; j &lt; instrlist.Count; j++)<br> {<br> Console.WriteLine(j.ToString() + &quot; : &quot; + instrlist[j]);<br> }<br> Console.WriteLine(&quot;\n&quot;);<br> <br> // Connect to a known instrument and print its IDN<br> TVA.Open(OSCILLOSCOPE);<br> TVA.Write(&quot;*IDN?&quot;);<br> status = TVA.Read(out response);<br> if (status)<br> {<br> Console.WriteLine(response);<br> }<br> <br> <br> // FILE READER<br> //StreamWriter myWriter;<br> // myWriter = new StreamWriter(&quot;output.csv&quot;);<br> //Console.WriteLine(&quot;reading from file&quot;);<br> <br> // Initialization<br> hw.setKey(key, 16); // Hardware<br> sw.setKey(key); // Software<br> <br> string path = @&quot;E:\VS\plaintexts\PlainText_1000000.txt&quot;;<br> // string path = @&quot;D:\sanjana_laptop\downloads\PlainText_1000000.txt&quot;; //@&quot;E:\VS\plaintexts\pt_9000.txt&quot;; //pt_117000<br> // Main loop<br> progress = 0;<br> worker.ReportProgress(progress, (object)(new ControllerReport(loop, text_in, text_out, text_ans)));<br> <br> // myWriter.WriteLine(BitConverter.ToString(key).Replace(&quot;-&quot;, &quot; &quot;));<br> <br> <br> using(StreamReader file = new StreamReader(path)) {<br> //int loop = 0;<br> string ln;<br> while ((ln = file.ReadLine()) != null &amp;&amp; (loop &lt; num_trace)) {<br> progress = (int)(100.0d * loop / num_trace);<br> <br> <br> // Generate plain text<br> for (int i = 0; i &lt; 16; i++) text_in[i] = (byte) Convert.ToInt32(ln.Substring(i*2,2),16);<br> loop++;<br> // for (int i=0; i&lt;16; i++) text_in[i] = 0;<br> // Software encryption<br> text_ans = sw.encrypt(text_in);<br> <br> // Hardware encryption<br> hw.writeText(text_in, 16);<br> hw.execute();<br> hw.readText (text_out, 16);<br> <br> // Get curve data for channel 1, and scale to volts.<br> byte[] rawwave1;<br> float[] wave1;<br> TVA.Write(&quot;DATA:SOU CH1&quot;);//, CH2*/<br> TVA.Write(&quot;DATA:WIDTH 2&quot;);<br> TVA.Write(&quot;DATA:ENC RPB&quot;);<br> TVA.Query(&quot;WFMPRE:YMULT?&quot;, out response);<br> ymult1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br> TVA.Query(&quot;WFMPRE:YZERO?&quot;, out response);<br> yzero1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br> TVA.Query(&quot;WFMPRE:YOFF?&quot;, out response);<br> yoff1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br> TVA.Query(&quot;WFMPRE:XINCR?&quot;, out response);<br> xincr1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br> TVA.Write(&quot;CURVE?&quot;);<br> TVA.ReadBinary(out rawwave1);<br> TVA.Read(out response);<br> wave1 = new float[rawwave1.Count()];<br> for (j = 0; j &lt; sampleLength /*rawwave1.Count()*/; j++)<br> {<br> wave1[j] = (rawwave1[j] - yoff1) * ymult1 + yzero1;<br> <br> }<br> <br> //write waveform to a csv file<br> <a href="http://System.IO" rel="noreferrer noopener" target=_blank title="http://system.io/">System.IO</a>.StreamWriter file1 = new <a href="http://System.IO" rel="noreferrer noopener" target=_blank title="http://system.io/">System.IO</a>.StreamWriter(&quot;cfb_64_&quot; + loop + &quot;.csv&quot;);<br> file1.WriteLine(&quot;TIME,CH1&quot;);<br> //file1.WriteLine(&quot;TIME,CH1,CH2&quot;);<br> //Console.WriteLine(rawwave1.Count());<br> for (j = 0; j &lt; sampleLength /*wave2.Count()*/; j++)<br> {<br> timepoint = j * xincr1;<br> // file1.WriteLine(timepoint.ToString() + &quot;,&quot; + wave1[j].ToString() + &quot;,&quot; + wave2[j].ToString());<br> file1.WriteLine(timepoint.ToString() + &quot;,&quot; + wave1[j].ToString());<br> }<br> file1.Close();<br> <br> //Console.WriteLine(&quot;\nPress Enter to exit&quot;);<br> //Console.ReadLine();<br> <br> // COMPARE SW &amp; HW GENERATED CIPHERTEXTS<br> //for (int i=0; i &lt; 16; i++)<br> // if (text_out[i] != text_ans[i])<br> // error = true;<br> <br> //WRITING TRACE NUMBER TO FILE<br> //myWriter.Write(loop+&quot;,&quot;);<br> <br> // WRITING PLAINTEXT TO FILE<br> //string tempString1 = BitConverter.ToString(text_in).Replace(&quot;-&quot;, &quot; &quot;);<br> //myWriter.WriteLine(tempString + &quot;,&quot;);<br> <br> // WRITING CIPHERTEXT TO FILE<br> //string tempString2 = BitConverter.ToString(text_out).Replace(&quot;-&quot;, &quot; &quot;);<br> //myWriter.WriteLine(loop + &quot;,&quot; + tempString1 + &quot;,&quot; + tempString2 );<br> //myWriter.WriteLine();<br> <br> worker.ReportProgress(progress, (object)(new ControllerReport(loop, text_in, text_out, text_ans)));<br> <br> if (worker.CancellationPending || error)<br> break;<br> <br> // Sleep for given period of time<br> System.Threading.Thread.Sleep(500/*delayTime*/);<br> <br> } //endof loop<br> <br> if(TVA!=null) {<br> TVA.Clear();<br> TVA.Close();<br> }<br> file.Close();<br> } <p></p>
Posted Mon, 03 Apr 2023 21:15:23 GMT by Teles, Afonso
Hi,<br> <br> Adding sleeps is not the correct way to handle timeouts. VISA timeout errors should be caught and handled by the program; this usually means&#160; repeating the operation a few times and, if it still fails, exiting with an error.<br> Additionally, it's also important to use &quot;*ESR?&quot; to check for errors and &quot;*OPC?&quot; for synchronization.<br> <br> I have attached an example Python3 script for getting a curve query from an MSO4/5/6, but it will likely work (perhaps with some modifications) for your MDO4000B.

You must be signed in to post in this forum.