//send to instrument by visacom private string send_to_instrument(string fullcmd,string address,string cmd, IMessage ioDmm,int delay = 0) { WriteTraceText(fullcmd); //IVisaSession basesession = null; //IMessage talksession = null; string strRd = ""; string instrumentAddress = address; //lock //this.WriteTraceText("\n"); lock (_lock_Instrument) { ioDmm.Clear(); ioDmm.WriteString(cmd); if (delay != 0 && delay > 500) Thread.Sleep(delay); else Thread.Sleep(500); if (cmd.Contains("?")) { for (int i = 0; i < 5; i++) { try { strRd = ioDmm.ReadString(4069); break; } catch (Exception exp) { ioDmm.Clear(); if (i != 9) { Thread.Sleep(200); continue; } else { WriteErrorText("write/read to instrumen by visacom error: " + exp.Message); throw new Exception(exp.Message); } } } } } strRd = strRd.TrimEnd('\n'); return strRd; }
//in visacom mode private void SaCapturebyVisacom(IMessage sesnCapture,string name = "",int delay = 5000) { StringBuilder filename = new StringBuilder(); if (name != "") { filename.Append(name).Append(@".png"); } else { filename.Append(DateTime.Now.ToString("yyyy-MM-dd_HH_mm_ss")).Append(@".png"); } string cmd = "MMEM:STOR:SCR \"D:\\rttscr.png\"";//;*OPC? sesnCapture.WriteString(cmd); sesnCapture.WriteString("MMEM:DATA? \"D:\\rttscr.png\""); //this.sa_sesn.WriteString("CALCulate:DATA?"); byte[] readbuf; readbuf = sesnCapture.Read(1000000); //WriteDebugText(Encoding.ASCII.GetString(readbuf)); //if(delay>5000) // Thread.Sleep(delay); //else // Thread.Sleep(5000); sesnCapture.WriteString("MMEM:DEL \"D:\\rttscr.png\""); sesnCapture.WriteString("*CLS"); byte[] size = { readbuf[1] }; byte[] newbuf = readbuf.Skip(2+ int.Parse(Encoding.ASCII.GetString(size))).Take(readbuf.Length-9).ToArray(); File.WriteAllBytes(_snapPath + filename.ToString(), newbuf); }