private void btnLoopReadClick(object sender, EventArgs e) { Log.WriteLog(mbSession.ResourceName + " Lectura continua", "", txtFile.Text + ".txt"); _worker = new BackgroundWorker(); _worker.WorkerSupportsCancellation = true; _worker.DoWork += new DoWorkEventHandler((state, args) => { do { if (_worker.CancellationPending) { break; } //mbSession.Timeout = Session.InfiniteTimeout; try { mbSession.SetAttributeBoolean(AttributeType.DmaAllowEn, true); MessageBasedSessionReader Reader = new MessageBasedSessionReader(mbSession); Reader.BinaryEncoding = BinaryEncoding.DefiniteLengthBlockData; Reader.BinaryEncoding = BinaryEncoding.RawLittleEndian; string responseString2 = Reader.ReadLine(); if (responseString2.Length != 1) { Log.SimpleWriteLog(responseString2, txtFile.Text + ".txt"); //readTextBox.Text += responseString2 + ","; } } catch (VisaException ex) { string textToWrite = ReplaceCommonEscapeSequences("STOP"); //readTextBox.Text = "Deteniendo\n"; mbSession.Write(textToWrite); textToWrite = ReplaceCommonEscapeSequences("DMA?"); //readTextBox.Text = "Llenando buffer..."; mbSession.Write(textToWrite); //MessageBox.Show("¡Tiempo excedido desde que se recibió la primer respesta! \\n Error: "+ ex.Message); //return; } } while (true); }); _worker.RunWorkerAsync(); readTextBox.Text = Log.dumpLine(txtFile.Text + ".txt"); btnLoopRead.Visible = false; btnCancel.Visible = true; btnCancel.Enabled = true; }
public void Dispose() { if (_handleSessionLifetime) { if (_instrumentSession != null) { ((IDisposable)(_instrumentSession)).Dispose(); _instrumentSession = null; } } _reader = null; GC.SuppressFinalize(this); }
/// <summary> /// This task will use the MessageBasedSession passed in. This task can either the MessageBasedSession or leave it open for the caller to close. /// </summary> /// <param name="session">MessageBasedSession used by this task.</param> /// <param name="taskHandlesSessionLifetime">If true, the task will close session when the task is disposed. If false, the caller is responsible for closing session.</param> public DUTMfgMode(MessageBasedSession session, bool taskHandlesSessionLifetime) { if (session == null) { throw new ArgumentNullException("session"); } _instrumentSession = session; _instrumentSession.Timeout = 2000; _instrumentSession.TerminationCharacterEnabled = true; _instrumentSession.TerminationCharacter = 10; // The caller can control the VISA session lifetime by passing in false for taskHandlesSessionLifetime. If taskHandlesSessionLifetime // is true, then the VISA session will be closed when the caller disposes this task. _handleSessionLifetime = taskHandlesSessionLifetime; // The MessageBasedSessionReader is used to read and parse data returned from the instrument _reader = new MessageBasedSessionReader(_instrumentSession); }
protected char[] ReadBinaryEncodedData(int numChars) { reader = new MessageBasedSessionReader(session); reader.BinaryEncoding = BinaryEncoding.DefiniteLengthBlockData; return(reader.ReadChars(numChars)); }