Esempio n. 1
0
        static void Main(string[] args)
        {
            int    hw_idx         = 0;
            string driver         = "";
            int    blk_read_size  = 1024;
            int    blk_write_size = 1024;

            switch (args.Length)
            {
            case 1:
                driver = args[0];
                break;

            case 2:
                driver = args[0];
                hw_idx = Int32.Parse(args[1]);
                break;

            case 3:
                driver        = args[0];
                hw_idx        = Int32.Parse(args[1]);
                blk_read_size = Int32.Parse(args[2]);
                break;

            case 4:
                driver         = args[0];
                hw_idx         = Int32.Parse(args[1]);
                blk_read_size  = Int32.Parse(args[2]);
                blk_write_size = Int32.Parse(args[3]);
                break;

            default:
                Console.Error.WriteLine("usage:");
                Console.Error.WriteLine("host driver [index block_read_size block_write_size]");
                return;
            }

            // Get version
            var ver = oni.lib.NativeMethods.LibraryVersion;

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

            try
            {
                using (var ctx = new oni.Context(driver, hw_idx))
                {
                    Console.WriteLine("Found the following devices:");
                    foreach (var elem in ctx.DeviceTable.Values)
                    {
                        Console.WriteLine("\t{0}) ID: {1}, Read size: {2}",
                                          elem.idx,
                                          elem.id,
                                          elem.read_size);
                    }

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

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

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

                    // See the hardware address
                    Console.WriteLine("Hardware address: "
                                      + ctx.HardwareAddress);

                    // Set read pre-allocation size
                    ctx.BlockReadSize  = blk_read_size;
                    ctx.BlockWriteSize = blk_write_size;

                    // State acquisition and reset acquisition clock counter
                    ctx.Start(true);

                    // 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("\tPaused.");
                            }
                        }
                        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];
                        //    oni_reg_addr_t addr = (oni_reg_addr_t)values[1];
                        //    oni_reg_val_t val = (oni_reg_val_t)values[2];

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

                    // Stop hardware
                    //ctx.Stop();

                    // Join data and signal threads
                    processor.quit = true;
                    proc_thread.Join(200);
                } // ctx.Dispose() is called.
            } catch (ONIException ex) {
                Console.Error.WriteLine("Host failed with the following error: "
                                        + ex.ToString());
                Console.Error.WriteLine("Current errno: "
                                        + Marshal.GetLastWin32Error());
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            const string DefaultConfigPath = "\\\\.\\xillybus_cmd_32";
            const string DefaultSignalPath = "\\\\.\\xillybus_signal_8";
            const string DefaultReadPath   = "\\\\.\\xillybus_data_read_32";
            const string DefaultWritePath  = "\\\\.\\xillybus_data_write_32";

            // Get version
            var ver = oni.lib.NativeMethods.LibraryVersion;

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

            try
            {
                string conf, read, write, sig;
                if (args.Length != 0 && args.Length != 4)
                {
                    throw new ArgumentException("Invalid program args.");
                }
                else if (args.Length == 4)
                {
                    conf  = args[0];
                    sig   = args[1];
                    read  = args[2];
                    write = args[3];
                }
                else
                {
                    conf  = DefaultConfigPath;
                    sig   = DefaultSignalPath;
                    read  = DefaultReadPath;
                    write = DefaultWritePath;
                }

                using (var ctx = new oni.Context(
                           "xillybus", 0, 0, conf, 1, sig, 2, read, 3, write))
                {
                    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);

                    // 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];
                        //    oni_reg_addr_t addr = (oni_reg_addr_t)values[1];
                        //    oni_reg_val_t val = (oni_reg_val_t)values[2];

                        //    oni_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 (ONIException ex) {
                Console.Error.WriteLine("HostXilly.exe failed with the following error: "
                                        + ex.ToString());
                Console.Error.WriteLine("Current errno: "
                                        + Marshal.GetLastWin32Error());
            }
        }