static void Main() { int N_BITS = 4; M2k ctx = libm2k.m2kOpen(); M2kDigital dig = ctx.getDigital(); dig.setSampleRateIn(100000); dig.setSampleRateOut(100000); for (uint i = 0; i < N_BITS; i++) { dig.setDirection(i, DIO_DIRECTION.DIO_OUTPUT); dig.enableChannel(i, true); } VectorUS bufferOut = new VectorUS(); VectorUS bufferIn = new VectorUS(); for (ushort i = 0; i < (1 << N_BITS); i++) { bufferOut.Add(i); } dig.setCyclic(true); dig.push(bufferOut); bufferIn = dig.getSamples(1000); foreach (var val in bufferIn) { Console.Write(val + " \n"); } dig.stop(); libm2k.contextClose(ctx); }
static int Main() { int elementSize = Marshal.SizeOf(typeof(IntPtr)); M2k ctx = libm2k.m2kOpen(); if (ctx == null) { Console.WriteLine("Connection Error: No ADALM2000 device available/connected to your PC."); return(1); } dig = ctx.getDigital(); M2kHardwareTrigger trig = dig.getTrigger(); long sr_divider = SR_DIVIDER_START; long sample_rate_in, sample_rate_out = MAX_SAMPLE_RATE; int k = 1; while (sr_divider > 1) { sample_rate_in = MAX_SAMPLE_RATE / sr_divider; sample_rate_out = MAX_SAMPLE_RATE / (sr_divider * 4); // set sample rates for in/out interface dig.setSampleRateIn(sample_rate_in + 1); dig.setSampleRateOut(sample_rate_out + 1); // set number of kernel buffers for the digital input interface dig.setKernelBuffersCountIn(KERNEL_BUFFERS_COUNT); trig.setDigitalStreamingFlag(true); for (uint j = 0; j < N_BITS; j++) { dig.setDirection(j, DIO_DIRECTION.DIO_OUTPUT); dig.enableChannel(j, true); } var bufferOut = new VectorUS(); for (uint j = 0; j < (1 << N_BITS); j++) { bufferOut.Add((ushort)j); } dig.setCyclic(true); dig.push(bufferOut); // Startup refill threads Thread refill_thread = new Thread(new ThreadStart(RefillThread)); Thread process_thread = new Thread(new ThreadStart(ProcessThread)); refill_thread.Start(); process_thread.Start(); refill_reset_event.Set(); process_done_reset_event.WaitOne(); refill_thread.Join(); process_thread.Join(); if (SHOW_BUFFERS) { Console.WriteLine("===================== BUFFER =================== " + k); foreach (var val in values) { Console.WriteLine((val)); } } bool stable = true; uint same_val = 0; uint same_val_cnt = 0; long dropped = 0; int i; for (i = 1; i < values.Length; i++) { // find first transition if (values[i] != values[i - 1]) { same_val = values[i]; break; } } for (; i < values.Length; i++) { if (values[i] == same_val) { same_val_cnt++; } else { int divider = (int)(sample_rate_in / sample_rate_out); if (same_val_cnt == divider) { { same_val = values[i]; same_val_cnt = 1; } } else { dropped = Math.Abs(values[i] - same_val) * divider + (same_val_cnt - divider); stable = false; break; } } } Console.Write("SR_DIVIDER: " + sr_divider + " SR_IN: " + sample_rate_in + " SR_OUT: " + sample_rate_out + " , " + ((stable) ? "STABLE " : "UNSTABLE ") + " dropped: " + dropped + " samples"); if (!stable) { Console.WriteLine(" @ buffer " + i / IN_NO_SAMPLES + " prev val: " + (same_val) + " next val: " + (values[i])); } Console.Write("\n"); sr_divider -= SR_DIVIDER_STEP; dig.stopBufferOut(); dig.stopAcquisition(); k++; } libm2k.contextClose(ctx); var exit = Console.ReadLine(); return(0); }