private void LoggingScanThread(CancellationToken canTok, int seconds) { Thread.CurrentThread.Name = "LoggingScanThread"; saleae.SetActiveChannels(null, new int[] { 0, 1, 2, 3 }); // **** Turn off all triggers **** SaleaeAutomationApi.Trigger[] t = new SaleaeAutomationApi.Trigger[8]; for (int i = 0; i < t.Length; i++) { t[i] = SaleaeAutomationApi.Trigger.None; } //saleae.SetTrigger(t); // **** Use lowest analog sample rate possible **** var sampRates = saleae.GetAvailableSampleRates(); var minAnaRate = (from r in sampRates select r.AnalogSampleRate).Min(); var rateStruct = (from r in sampRates where r.AnalogSampleRate == minAnaRate select r).First(); saleae.SetSampleRate(rateStruct); var rate = (rateStruct.DigitalSampleRate > 0) ? (rateStruct.DigitalSampleRate) : (rateStruct.AnalogSampleRate); saleae.SetNumSamples(BurstSeconds * rate); // **** Do the data logging **** DateTime started = DateTime.Now; string saveFolder = @"C:\_LogicData\" + started.Year + "_" + started.Month.ToString("00") + "_" + started.Day.ToString("00") + "-" + started.Hour.ToString("00") + "_" + started.Minute.ToString("00") + "_" + started.Second.ToString("00") + @"\"; if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } indxWriter = new LoggingIndexWriter(Register); OnLoggingEvent(new LoggingStartedEventArgs(saveFolder)); while (DateTime.Now.Subtract(started).TotalSeconds < seconds) { if (canTok.IsCancellationRequested) { // Cancel me! break; } double remain = seconds - DateTime.Now.Subtract(started).TotalSeconds; if (remain < BurstSeconds) { // Remaining time is less than burst time saleae.SetNumSamples((int)(remain * rate)); } TimeSpan scanTime = DateTime.Now.Subtract(started); string filename = System.IO.Path.Combine(saveFolder, "data" + scanTime.TotalSeconds.ToString("00000") + ".logicdata"); saleae.CaptureToFile(filename); OnLoggingEvent(new LoggingFileEventArgs(filename, scanTime)); } OnLoggingEvent(new LoggingStoppedEventArgs()); }
private void LoggingScanThread(CancellationToken canTok, int seconds, int rate) { Thread.CurrentThread.Name = "LoggingScanThread"; // **** Turn off all triggers **** SaleaeAutomationApi.Trigger[] t = new SaleaeAutomationApi.Trigger[8]; for (int i = 0; i < t.Length; i++) { t[i] = SaleaeAutomationApi.Trigger.None; } saleae.SetNumSamples(BurstSeconds * rate); // **** Do the data logging **** DateTime started = DateTime.Now; string saveFolder = @"C:\_LogicData\" + started.Year + "_" + started.Month.ToString("00") + "_" + started.Day.ToString("00") + "-" + started.Hour.ToString("00") + "_" + started.Minute.ToString("00") + "_" + started.Second.ToString("00") + @"\"; if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } indxWriter = new LoggingIndexWriter(Register); OnLoggingEvent(new LoggingStartedEventArgs(saveFolder)); while (DateTime.Now.Subtract(started).TotalSeconds < seconds) { if (canTok.IsCancellationRequested) { // Cancel me! break; } double remain = seconds - DateTime.Now.Subtract(started).TotalSeconds; if (remain < BurstSeconds) { // Remaining time is less than burst time saleae.SetNumSamples((int)(remain * rate)); } TimeSpan scanTime = DateTime.Now.Subtract(started); string filename = System.IO.Path.Combine(saveFolder, "data" + scanTime.TotalSeconds.ToString("00000") + ".logicdata"); saleae.CaptureToFile(filename); OnLoggingEvent(new LoggingFileEventArgs(filename, scanTime)); } OnLoggingEvent(new LoggingStoppedEventArgs()); }
private void LoggingScanThread(CancellationToken canTok, int seconds) { Thread.CurrentThread.Name = "LoggingScanThread"; int[] chans = { 0, 1, 2, 3, 4, 5 }; int numchans = chans.Length; int numsamples = 4000000; saleae.SetActiveChannels(chans, null); //digital chans, analog chans // **** Turn off all triggers **** SaleaeAutomationApi.Trigger[] t = new SaleaeAutomationApi.Trigger[numchans]; for (int i = 0; i < numchans; i++) { t[i] = SaleaeAutomationApi.Trigger.None; } t[5] = SaleaeAutomationApi.Trigger.Posedge; // Set up trigger saleae.SetTrigger(t); // **** Use lowest analog sample rate possible **** var sampRates = saleae.GetAvailableSampleRates(); if (sampRates.Any(x => x.DigitalSampleRate == 4000000)) { saleae.SetSampleRate(sampRates.First(x => x.DigitalSampleRate == 4000000)); } saleae.SetNumSamples(BurstSeconds * 4000000); // **** Do the data logging **** DateTime started = DateTime.Now; string saveFolder = @"C:\_LogicData\" + started.Year + "_" + started.Month.ToString("00") + "_" + started.Day.ToString("00") + "-" + started.Hour.ToString("00") + "_" + started.Minute.ToString("00") + "_" + started.Second.ToString("00") + @"\"; if (!Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } indxWriter = new LoggingIndexWriter(Register); while (!canTok.IsCancellationRequested) { OnLoggingEvent(new LoggingStartedEventArgs(saveFolder)); TimeSpan scanTime = DateTime.Now.Subtract(started); string filename = System.IO.Path.Combine(saveFolder, "data" + scanTime.TotalSeconds.ToString("00000") + ".logicdata"); saleae.CaptureToFile(filename); OnLoggingEvent(new LoggingFileEventArgs(filename, scanTime)); while (!saleae.IsProcessingComplete()) { if (canTok.IsCancellationRequested) { // Cancel me! break; } } OnLoggingEvent(new LoggingStoppedEventArgs()); } }