Exemple #1
0
        // TODO: Modify this method signature to accept a single argument
        //       of type ReadDone. This is the delegate that will be passed
        //       in when this method is called.
        internal void ReadFromDataSource(ReadDone doneReadingCallbackMethod)
        {
            // Use a random number generator to determine a delay time
            // between each "read". This helps to simulate a long-running
            // process.
            Random r1 = new Random(DateTime.Now.Millisecond);
            int waitTime = r1.Next (0, 500);

            // Use a random number generator to determine how many data
            // records need to be read.
            Random r2 = new Random(DateTime.Now.Second);
            int numberOfRecordsToRead = r2.Next (10, 25);

            Console.WriteLine ("\n\t" +
                "Reading {0} records with a wait time of {1} milliseconds.",
                numberOfRecordsToRead, waitTime);

            // Create a simulated read process.
            for (int i=0; i < numberOfRecordsToRead; i++)
            {
                // Pause to simulate a long-running process.
                System.Threading.Thread.Sleep (waitTime);

                // Display an update to the console every so often.
                if (i%5 == 0)
                {
                    Console.WriteLine ("\tRead {0} records so far.", i);
                }
            }

            // TODO: Using the delegate that was passed into this method,
            //       call the Callback method here.
            Console.WriteLine("\tCalling the callback method.");
            doneReadingCallbackMethod();
        }
Exemple #2
0
        void ReadThreadRun(AutoResetEvent stop, long maxRead)
        {
            //maxRead < 0 indicates "unlimited" reads
            if (maxRead < 0)
            {
                maxRead = long.MaxValue;
            }
            Task readTask = new Task("EphysRead");

            readTask.AIChannels.CreateVoltageChannel(HardwareSettings.DAQ.DeviceName + "/" + HardwareSettings.DAQ.Ch1Read, "Electrode1", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            readTask.AIChannels.CreateVoltageChannel(HardwareSettings.DAQ.DeviceName + "/" + HardwareSettings.DAQ.Ch2Read, "Electrode2", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            readTask.AIChannels.CreateVoltageChannel(HardwareSettings.DAQ.DeviceName + "/" + HardwareSettings.DAQ.Ch1ModeRead, "Mode1", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            readTask.AIChannels.CreateVoltageChannel(HardwareSettings.DAQ.DeviceName + "/" + HardwareSettings.DAQ.Ch2ModeRead, "Mode2", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            readTask.AIChannels.CreateVoltageChannel(HardwareSettings.DAQ.DeviceName + "/" + HardwareSettings.DAQ.Ch1CommandRead, "Command1", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            readTask.AIChannels.CreateVoltageChannel(HardwareSettings.DAQ.DeviceName + "/" + HardwareSettings.DAQ.Ch2CommandRead, "Command2", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            readTask.AIChannels.CreateVoltageChannel(HardwareSettings.DAQ.DeviceName + "/" + HardwareSettings.DAQ.LaserRead, "LaserRead", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);
            readTask.Timing.ConfigureSampleClock("", HardwareSettings.DAQ.Rate, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples);
            long sampleIndex = 0;

            _writeThreadReady.WaitOne();


            try
            {
                readTask.Start();
                AnalogMultiChannelReader dataReader = new AnalogMultiChannelReader(readTask.Stream);


                while (!stop.WaitOne(0) && sampleIndex < maxRead)
                {
                    var nsamples = readTask.Stream.AvailableSamplesPerChannel;

                    if (nsamples >= 10)
                    {
                        double[,] read = dataReader.ReadMultiSample((int)nsamples);
                        var tail_voltages = new Tuple <double, double>(read[0, 0], read[1, 0]);
                        voltage_buffer.Post(tail_voltages);
                        if (ReadDone != null)
                        {
                            ReadDone.Invoke(new ReadDoneEventArgs(read, sampleIndex));
                        }
                        //Update our running index
                        sampleIndex += nsamples;
                    }
                }
            }
            finally
            {
                readTask.Stop();
                readTask.Dispose();
                Console.WriteLine("Got to Pipe Close");
                //Signal to subscribers that we exited
                //Note: Has to be asynchronous so that we leave here before stop gets called
                if (ReadThreadFinished != null)
                {
                    ReadThreadFinished.BeginInvoke(null, null);
                }
            }
        }
    void WriteIntoFile(float val)
    {
        FileInfo     t  = new FileInfo("Assets/PracticeProcess.txt");
        StreamWriter sw = t.CreateText();

        sw.WriteLine(RezeroDone.ToString());
        sw.WriteLine(val);
        sw.WriteLine(pushcnt.ToString());
        sw.WriteLine(ReadDone.ToString());
        sw.WriteLine(System.Math.Min(System.Math.Abs(ReadBar.value - stdv) / stdv, 1f));
        sw.Close();
        sw.Dispose();
    }
Exemple #4
0
    // Use this for initialization
    void Start()
    {
        TextAsset textFile = Resources.Load <TextAsset>(FileName);
        var       lines    = textFile.text.Split('\n');
        //var lines = File.ReadAllLines(Path.Combine(Application.dataPath, FileName));

        int index = 0;

        foreach (var line in lines)
        {
            var split = line.Split('\t');

            ANote note = new ANote()
            {
                Frequency = float.Parse(split[1]),
                Index     = index,
                Name      = split[0]
            };

            Values.Add(note);

            var noteSplit = split[0].Split('/');
            foreach (var noteName in noteSplit)
            {
                NoteFromName.Add(noteName, note);
            }
            if (noteSplit.Length >= 2)
            {
                NoteFromName.Add(split[0], note);
            }
            index++;
        }
        if (ReadDone != null)
        {
            ReadDone.Invoke(Values);
        }
    }
Exemple #5
0
        static void Main()
        {
            // TODO: Create an instance of the CallbackExampleDriver class.
            CallbackExampleDriver driver = new CallbackExampleDriver();

            DataSourceReader reader = new DataSourceReader();

            // TODO: Create an instance of the ReadDone delegate providing
            //       it the ReaderCallback method found in this class.
            ReadDone r = new ReadDone(driver.ReaderCallback);

            Console.WriteLine ("Starting to read in the data...");

            // TODO: Modify this call to include one argument which is the
            //       delegate object created above.
            reader.ReadFromDataSource(r);

            Console.Write ("\nPress <ENTER> to end: ");
            Console.ReadLine();
        }