Esempio n. 1
0
        static void Main(string[] args)
        {
            // Get version
            var ver = oe.lib.NativeMethods.LibraryVersion;

            Console.WriteLine("Using liboepcie version: " + ver);
            bool running = true;

            try
            {
                string conf, read, sig;
                Console.WriteLine("length {0}", args.Length);
                if (args.Length != 0 && args.Length != 3)
                {
                    throw new ArgumentException("Invalid program args.");
                }
                else if (args.Length == 3)
                {
                    conf = args[0];
                    sig  = args[1];
                    read = args[2];
                }
                else
                {
                    conf = oe.lib.NativeMethods.DefaultConfigPath;
                    read = oe.lib.NativeMethods.DefaultReadPath;
                    sig  = oe.lib.NativeMethods.DefaultSignalPath;
                }

                using (var ctx = new oe.Context(conf, read, sig))
                {
                    Console.WriteLine("Found the following devices:");
                    foreach (var elem in ctx.DeviceMap)
                    {
                        var index  = elem.Key;
                        var device = elem.Value;

                        Console.WriteLine("\t{0}) ID: {1}, Read size: {2}",
                                          index,
                                          device.id,
                                          device.read_size);
                    }

                    // See how big max frames are
                    Console.WriteLine("Max read frame size: "
                                      + ctx.MaxReadFrameSize);
                    Console.WriteLine("Max write frame size: "
                                      + ctx.MaxWriteFrameSize);

                    // See the hardware clock
                    Console.WriteLine("System clock frequency: "
                                      + ctx.SystemClockHz);

                    // Start acqusisition
                    ctx.Start();

                    // Start processor in background
                    var processor = new DataProcessor(ctx);
                    var proc_thread
                        = new Thread(new ThreadStart(processor.CaptureData));
                    proc_thread.Start();

                    int c = 's';
                    while (c != 'q')
                    {
                        Console.WriteLine("Enter a command and press enter:");
                        Console.WriteLine("\tc - toggle 1/100 clock display");
                        Console.WriteLine("\td - toggle 1/100 sample display");
                        Console.WriteLine("\tp - toggle stream pause");
                        Console.WriteLine("\tr - enter register command");
                        Console.WriteLine("\tq - quit");
                        Console.Write(">>> ");

                        var cmd = Console.ReadLine();
                        c = cmd[0];

                        if (c == 'p')
                        {
                            running = !running;
                            if (running)
                            {
                                ctx.Start();
                            }
                            else
                            {
                                ctx.Stop();
                                Console.WriteLine("\tPuased.");
                            }
                        }
                        else if (c == 'c')
                        {
                            processor.display_clock = !processor.display_clock;
                        }
                        else if (c == 'd')
                        {
                            processor.display = !processor.display;
                        }
                        // else if (c == 'r') {

                        //    printf("Enter dev_idx reg_addr reg_val\n");
                        //    printf(">>> ");

                        //    // Read the command
                        //    char *buf = NULL;
                        //    size_t len = 0;
                        //    rc = getline(&buf, &len, stdin);
                        //    if (rc == -1) { printf("Error: bad command\n");
                        //    continue;}

                        //    // Parse the command string
                        //    long values[3];
                        //    rc = parse_reg_cmd(buf, values);
                        //    if (rc == -1) { printf("Error: bad command\n");
                        //    continue;}
                        //    free(buf);

                        //    size_t dev_idx = (size_t)values[0];
                        //    oe_reg_addr_t addr = (oe_reg_addr_t)values[1];
                        //    oe_reg_val_t val = (oe_reg_val_t)values[2];

                        //    oe_write_reg(ctx, dev_idx, addr, val);
                        //}
                    }

                    // Join data and signal threads
                    processor.quit = true;

                    // Stop hardware, join data collection thread, and reset
                    ctx.Stop();
                    proc_thread.Join();
                    ctx.Reset();
                } // ctx.Dispose() is called.
            } catch (OEException ex) {
                Console.Error.WriteLine("Host.exe failed with the following error: "
                                        + ex.ToString());
                Console.Error.WriteLine("Current errno: "
                                        + Marshal.GetLastWin32Error());
            }
        }
Esempio n. 2
0
 public DataProcessor(oe.Context ctx)
 {
     this.ctx = ctx;
 }