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>
 
<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("?*", out instrlist);<br>
//TVA.Timeout(10000);<br>
Console.WriteLine("Visa Resources");<br>
for (j = 0; j < instrlist.Count; j++)<br>
{<br>
Console.WriteLine(j.ToString() + " : " + instrlist[j]);<br>
}<br>
Console.WriteLine("\n");<br>
<br>
// Connect to a known instrument and print its IDN<br>
TVA.Open(OSCILLOSCOPE);<br>
TVA.Write("*IDN?");<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("output.csv");<br>
//Console.WriteLine("reading from file");<br>
<br>
// Initialization<br>
hw.setKey(key, 16); // Hardware<br>
sw.setKey(key); // Software<br>
<br>
string path = @"E:\VS\plaintexts\PlainText_1000000.txt";<br>
// string path = @"D:\sanjana_laptop\downloads\PlainText_1000000.txt"; //@"E:\VS\plaintexts\pt_9000.txt"; //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("-", " "));<br>
<br>
<br>
using(StreamReader file = new StreamReader(path)) {<br>
//int loop = 0;<br>
string ln;<br>
while ((ln = file.ReadLine()) != null && (loop < num_trace)) {<br>
progress = (int)(100.0d * loop / num_trace);<br>
<br>
<br>
// Generate plain text<br>
for (int i = 0; i < 16; i++) text_in[i] = (byte) Convert.ToInt32(ln.Substring(i*2,2),16);<br>
loop++;<br>
// for (int i=0; i<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("DATA:SOU CH1");//, CH2*/<br>
TVA.Write("DATA:WIDTH 2");<br>
TVA.Write("DATA:ENC RPB");<br>
TVA.Query("WFMPRE:YMULT?", out response);<br>
ymult1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br>
TVA.Query("WFMPRE:YZERO?", out response);<br>
yzero1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br>
TVA.Query("WFMPRE:YOFF?", out response);<br>
yoff1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br>
TVA.Query("WFMPRE:XINCR?", out response);<br>
xincr1 = float.Parse(response, CultureInfo.InvariantCulture.NumberFormat);<br>
TVA.Write("CURVE?");<br>
TVA.ReadBinary(out rawwave1);<br>
TVA.Read(out response);<br>
wave1 = new float[rawwave1.Count()];<br>
for (j = 0; j < 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("cfb_64_" + loop + ".csv");<br>
file1.WriteLine("TIME,CH1");<br>
//file1.WriteLine("TIME,CH1,CH2");<br>
//Console.WriteLine(rawwave1.Count());<br>
for (j = 0; j < sampleLength /*wave2.Count()*/; j++)<br>
{<br>
timepoint = j * xincr1;<br>
// file1.WriteLine(timepoint.ToString() + "," + wave1[j].ToString() + "," + wave2[j].ToString());<br>
file1.WriteLine(timepoint.ToString() + "," + wave1[j].ToString());<br>
}<br>
file1.Close();<br>
<br>
//Console.WriteLine("\nPress Enter to exit");<br>
//Console.ReadLine();<br>
<br>
// COMPARE SW & HW GENERATED CIPHERTEXTS<br>
//for (int i=0; i < 16; i++)<br>
// if (text_out[i] != text_ans[i])<br>
// error = true;<br>
<br>
//WRITING TRACE NUMBER TO FILE<br>
//myWriter.Write(loop+",");<br>
<br>
// WRITING PLAINTEXT TO FILE<br>
//string tempString1 = BitConverter.ToString(text_in).Replace("-", " ");<br>
//myWriter.WriteLine(tempString + ",");<br>
<br>
// WRITING CIPHERTEXT TO FILE<br>
//string tempString2 = BitConverter.ToString(text_out).Replace("-", " ");<br>
//myWriter.WriteLine(loop + "," + tempString1 + "," + 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>