/// <summary> /// Write an array of bytes to the test device. This is mainly used to send commands to /// the device - some of which require a response. /// </summary> /// <param name="Bytes"></param> public void Write(byte[] Bytes) { string cmd = enc.GetString(Bytes); // // Commands (requests from the controller): // // START: Start sampling and send sample data back to the controller. // PING: Check if the device is active. Response is "pOng". // COPY: Respond with a firmware revision and copyright message. // CHAN=: Set the number of channels to sample. // RATE=: Set the sampling rate (in samples per second). // COMP=: Set compression Y/N. // TIME=: Set the total sampling time (in milliseconds). // MODE=: Set the sampling mode (continuous or transitions-only). // if (cmd.Equals("START\r\n")) { BackgroundWorker worker; // Run the test samples in a thread -- mainly so the DataGrabber // can get its modes and timers set before data starts arriving. worker = new BackgroundWorker(); worker.DoWork += GenerateSamples; worker.RunWorkerAsync(); } else if (cmd.Equals("PING\r\n")) { BackgroundWorker worker; // Respond to the PING in a thread -- mainly so the DataGrabber // can get its modes and timers set before data starts arriving. worker = new BackgroundWorker(); worker.DoWork += PingResponse; worker.RunWorkerAsync(); } else if (cmd.Equals("COPY\r\n")) Copyright(); else if (cmd.StartsWith("CHAN=")) samplingChannels = Convert.ToInt32(cmd.Substring(5, cmd.Length - 7)); else if (cmd.StartsWith("RATE=")) samplingRate = Convert.ToInt32(cmd.Substring(5, cmd.Length - 7)); else if (cmd.StartsWith("COMP=")) samplingCompression = (cmd[5] == 'Y'); else if (cmd.StartsWith("TIME=")) samplingTime = Convert.ToInt32(cmd.Substring(5, cmd.Length - 7)); else if (cmd.StartsWith("MODE=")) samplingMode = (cmd[5] == 'T' ? DataGrabber.SamplingModes.TransitionsOnly : DataGrabber.SamplingModes.Continuous); }
/// <summary> /// Write an array of bytes to the test device. This is mainly used to send commands to /// the device - some of which require a response. /// </summary> /// <param name="Bytes"></param> public void Write(byte[] Bytes) { string cmd = enc.GetString(Bytes); // // Commands (requests from the controller): // // START: Start sampling and send sample data back to the controller. // PING: Check if the device is active. Response is "pOng". // COPY: Respond with a firmware revision and copyright message. // CHAN=: Set the number of channels to sample. // RATE=: Set the sampling rate (in samples per second). // COMP=: Set compression Y/N. // TIME=: Set the total sampling time (in milliseconds). // MODE=: Set the sampling mode (continuous or transitions-only). // if (cmd.Equals("START\r\n")) { BackgroundWorker worker; // Run the test samples in a thread -- mainly so the DataGrabber // can get its modes and timers set before data starts arriving. worker = new BackgroundWorker(); worker.DoWork += GenerateSamples; worker.RunWorkerAsync(); } else if (cmd.Equals("PING\r\n")) { BackgroundWorker worker; // Respond to the PING in a thread -- mainly so the DataGrabber // can get its modes and timers set before data starts arriving. worker = new BackgroundWorker(); worker.DoWork += PingResponse; worker.RunWorkerAsync(); } else if (cmd.Equals("COPY\r\n")) { Copyright(); } else if (cmd.StartsWith("CHAN=")) { samplingChannels = Convert.ToInt32(cmd.Substring(5, cmd.Length - 7)); } else if (cmd.StartsWith("RATE=")) { samplingRate = Convert.ToInt32(cmd.Substring(5, cmd.Length - 7)); } else if (cmd.StartsWith("COMP=")) { samplingCompression = (cmd[5] == 'Y'); } else if (cmd.StartsWith("TIME=")) { samplingTime = Convert.ToInt32(cmd.Substring(5, cmd.Length - 7)); } else if (cmd.StartsWith("MODE=")) { samplingMode = (cmd[5] == 'T' ? DataGrabber.SamplingModes.TransitionsOnly : DataGrabber.SamplingModes.Continuous); } }