Beispiel #1
0
    /*=====================================================================
     | MAIN PROGRAM
     | ====================================================================*/
    public static void Main(String[] args)
    {
        int  port       = 0;     // open port 0 by default
        int  samplerate = 10000; // in kHz
        uint timeout    = 500;   // in milliseconds
        uint latency    = 200;   // in milliseconds
        int  len        = 0;
        int  num        = 0;

        if (args.Length < 2)
        {
            print_usage();
            Environment.Exit(1);
        }
        len = Convert.ToInt32(args[0]);
        num = Convert.ToInt32(args[1]);

        // Open the device
        beagle = BeagleApi.bg_open(port);
        if (beagle <= 0)
        {
            Console.Write("Unable to open Beagle device on port {0:d}\n",
                          port);
            Console.Write("Error code = {0:d}\n", beagle);
            Environment.Exit(1);
        }
        Console.Write("Opened Beagle device on port {0:d}\n", port);

        // Set the samplerate
        samplerate = BeagleApi.bg_samplerate(beagle, samplerate);
        if (samplerate < 0)
        {
            Console.Write("error: {0:s}\n",
                          BeagleApi.bg_status_string(samplerate));
            Environment.Exit(1);
        }
        Console.Write("Sampling rate set to {0:d} KHz.\n", samplerate);

        // Set the idle timeout.
        // The Beagle read functions will return in the specified time
        // if there is no data available on the bus.
        BeagleApi.bg_timeout(beagle, timeout);
        Console.Write("Idle timeout set to {0:d} ms.\n", timeout);

        // Set the latency.
        // The latency parameter allows the programmer to balance the
        // tradeoff between host side buffering and the latency to
        // receive a packet when calling one of the Beagle read
        // functions.
        BeagleApi.bg_latency(beagle, latency);
        Console.Write("Latency set to {0:d} ms.\n", latency);

        Console.Write("Host interface is {0:s}.\n",
                      ((BeagleApi.bg_host_ifce_speed(beagle)) != 0) ? "high speed" :
                      "full speed");
        // Configure the device for SPI
        BeagleApi.bg_spi_configure(
            beagle,
            BeagleSpiSSPolarity.BG_SPI_SS_ACTIVE_LOW,
            BeagleSpiSckSamplingEdge.BG_SPI_SCK_SAMPLING_EDGE_RISING,
            BeagleSpiBitorder.BG_SPI_BITORDER_MSB);

        // There is usually no need for target power when using the
        // Beagle as a passive monitor.
        BeagleApi.bg_target_power(beagle, BeagleApi.BG_TARGET_POWER_OFF);

        Console.Write("\n");
        Console.Out.Flush();

        spidump(len, num);

        // Close the device
        BeagleApi.bg_close(beagle);

        return;
    }