Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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);
        }
    }