コード例 #1
0
        private void cbDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (device != null)
            {
                device.StopDacq();

                device.Disconnect();
                device.Dispose();

                device = null;
            }

            uint sel = (uint)cbDevices.SelectedIndex;

            /* choose one of the following contructors:
             * The first one uses the OnNewData callback and gives you a reference to the raw multiplexed data,
             * this could be used without further initialisation
             * The second uses the more advanced callback which gives you the data for each channel in a callback, but need initialistation
             * for buffers and the selected channels
             */

            if (sel >= 0) // a device is selected, enable the sampling buttons
            {
                btStart.Enabled = true;
            }
            else
            {
                btStart.Enabled = false;
            }
            btStop.Enabled = false;

            device = new CMeaDeviceNet(usblist.GetUsbListEntry(sel).DeviceId.BusType, OnChannelData, OnError);
            device.Connect(usblist.GetUsbListEntry(sel));

            device.SendStop(); // only to be sure

            tbDeviceInfo.Text  = "";
            tbDeviceInfo.Text += /*"Serialnumber: " +*/ device.SerialNumber + "\r\n";
            int hwchannels;

            device.HWInfo().GetNumberOfHWADCChannels(out hwchannels);
            tbDeviceInfo.Text += "Number of Hardwarechannels: " + hwchannels.ToString() + "\r\n";


            // configure MeaDevice: MC_Card or Usb
            device.SetNumberOfChannels(hwchannels);

            int samplingrate = 5000; // MC_Card does not support all settings, please see MC_Rack for valid settings

            device.SetSampleRate(samplingrate, 1, 0);

            int gain;

            device.GetGain(out gain);

            List <CMcsUsbDacqNet.CHWInfo.CVoltageRangeInfoNet> voltageranges;

            device.HWInfo().GetAvailableVoltageRangesInMicroVoltAndStringsInMilliVolt(out voltageranges);
            for (int i = 0; i < voltageranges.Count; i++)
            {
                tbDeviceInfo.Text += "(" + i.ToString() + ") " + voltageranges[i].VoltageRangeDisplayStringMilliVolt + "\r\n";
            }

            // Set the range acording to the index (only valid for MC_Card)
            // device.SetVoltageRangeInMicroVoltByIndex(0, 0);

            device.EnableDigitalIn(true, 0);

            // Checksum not supported by MC_Card
            device.EnableChecksum(true, 0);


            // Get the layout to know how the data look like that you receive
            int ana, digi, che, tim, block;

            device.GetChannelLayout(out ana, out digi, out che, out tim, out block, 0);

            // or
            device.GetChannelsInBlock(out block);

            m_block = block;
            // set the channel combo box with the channels
            SetChannelCombo(block);

            channelblocksize = samplingrate / 10; // good choice for MC_Card

            bool[] selChannels = new bool[block];

            for (int i = 0; i < block; i++)
            {
                selChannels[i] = true; // With true channel i is selected
                //Console.WriteLine("Selected: " + block);
                // selChannels[i] = false; // With false the channel i is deselected
            }
            // queue size and threshold should be selected carefully

            device.SetSelectedData(selChannels, 10 * channelblocksize, channelblocksize, SampleSizeNet.SampleSize16, block);
            // Alternative call if you want to select all channels
            //device.SetSelectedData(block, 10 * channelblocksize, channelblocksize, CMcsUsbDacqNet.SampleSize.Size16, block);
            m_channel_handles = block; // for this case, if all channels are selected
        }
コード例 #2
0
        private void CbDevicesSelectedIndexChanged(object sender, EventArgs e)
        {
            groupBoxSettings.Enabled = false;

            if (device != null)
            {
                device.StopDacq();

                device.Disconnect();
                device.Dispose();

                device = null;
            }

            btStart.Enabled = cbDevices.SelectedIndex >= 0;
            btStop.Enabled  = false;

            var entry = usblist.GetUsbListEntry((uint)cbDevices.SelectedIndex);

            /* choose one of the following constructors:
             * The first one uses the OnNewData callback and gives you a reference to the raw multiplexed data.
             * This could be used without further initialization
             * The second one uses the more advanced callback which gives you the data for each channel in a callback but needs initialization
             * for buffers and the selected channels
             */
            if (usePollForData)
            {
                device = new CMeaDeviceNet(entry.DeviceId.BusType);
            }
            else
            {
                device = new CMeaDeviceNet(entry.DeviceId.BusType, OnChannelData, OnError);
            }

            device.Connect(entry);
            useWireless = entry.DeviceId.IdProduct == ProductIdEnumNet.W2100;
            bool isMCCard = entry.DeviceId.IdProduct == ProductIdEnumNet.MC_Card;

            if (useWireless)
            {
                CW2100_FunctionNet   func           = new CW2100_FunctionNet(device);
                HeadStageIDTypeState headstagestate = func.GetSelectedHeadstageState(0); // information about currently selected headstage
                HeadStageIDType[]    headstages     = func.GetAvailableHeadstages(30);   // list of available headstage in range

                if (headstagestate.IdType.ID == 0xFFFF)                                  // if no headstage is currently selected
                {
                    if (headstages.Length > 0)                                           // if at least one headstage is available
                    {
                        func.SelectHeadstage(headstages[0].ID, 0);                       // then selected the first one
                    }
                }
                // func.DeselectHeadstage(0); // use this to deselect a selected headstage
            }

            device.SendStopDacq(); // only to be sure

            tbDeviceInfo.Text  = "";
            tbDeviceInfo.Text += "Serial number: " + device.SerialNumber + Environment.NewLine;
            device.HWInfo().GetNumberOfHWADCChannels(out int hwchannels);
            tbDeviceInfo.Text += @"Number of Hardware channels: " + hwchannels.ToString("D") + Environment.NewLine;

            if (hwchannels == 0)
            {
                hwchannels = 64;
            }

            // configure MeaDevice: MC_Card or Usb
            device.SetNumberOfChannels(hwchannels);

            const int Samplingrate = 20000; // MC_Card does not support all settings, please see MC_Rack for valid settings

            device.SetSamplerate(Samplingrate, 1, 0);

            int gain = device.GetGain();

            device.HWInfo().GetAvailableVoltageRangesInMicroVoltAndStringsInMilliVolt(out var voltageRanges);
            for (int i = 0; i < voltageRanges.Count; i++)
            {
                tbDeviceInfo.Text += @"(" + i.ToString("D") + @") " + voltageRanges[i].VoltageRangeDisplayStringMilliVolt + Environment.NewLine;
            }

            // Set the range according to the index (only valid for MC_Card)
            if (isMCCard)
            {
                device.SetVoltageRangeByIndex(0, 0);
            }

            device.EnableDigitalIn(true, 0);

            // Checksum not supported by MC_Card
            if (!isMCCard)
            {
                device.EnableChecksum(true, 0);
            }

            // Get the layout to know how the data look like that you receive
            device.GetChannelLayout(out int ana, out int digi, out int che, out int tim, out int block, 0);

            // or
            block = device.GetChannelsInBlock(0);

            // set the channel combo box with the channels
            SetChannelCombo(block);

            channelblocksize = Samplingrate / 10; // good choice for MC_Card

            bool[] selChannels = new bool[block];

            for (int i = 0; i < block; i++)
            {
                selChannels[i] = true; // With true channel i is selected
                // selChannels[i] = false; // With false the channel i is deselected
            }
            mChannelHandles = block; // for this case, if all channels are selected
            // queue size and threshold should be selected carefully
            if (useChannelMethod && useChannelData)
            {
                device.SetSelectedData(selChannels, 10 * channelblocksize, channelblocksize, SampleSizeNet.SampleSize16Unsigned, block);
                //device.AddSelectedChannelsQueue(10, 2, 10 * channelblocksize, channelblocksize, SampleSizeNet.SampleSize16Unsigned);
                //device.ChannelBlock_SetCommonThreshold(channelblocksize);
                // Alternative call if you want to select all channels
                //device.SetSelectedData(block, 10 * channelblocksize, channelblocksize, SampleSizeNet.SampleSize16Unsigned, block);
            }
            else if (useChannelMethod && !useChannelData)
            {
                device.SetSelectedChannels(selChannels, 10 * channelblocksize, channelblocksize, SampleSizeNet.SampleSize16Unsigned, block);
            }
            else
            {
                device.SetSelectedChannelsQueue(selChannels, 10 * channelblocksize, channelblocksize, SampleSizeNet.SampleSize16Unsigned, block);
            }

            device.ChannelBlock_SetCheckChecksum((uint)che, (uint)tim);
        }
コード例 #3
0
ファイル: DAQcontroller.cs プロジェクト: thentnucyborg/MEAME2
        public bool connectDataAcquisitionDevice(uint index)
        {
            this.dataFormat = SampleSizeNet.SampleSize32Signed;

            if (dataAcquisitionDevice != null)
            {
                dataAcquisitionDevice.StopDacq();
                dataAcquisitionDevice.Disconnect();
                dataAcquisitionDevice.Dispose();
                dataAcquisitionDevice = null;
                throw new System.ArgumentException("Reached bad code path", "DAQ is null, mcs cruft");
            }

            dataAcquisitionDevice = new CMeaDeviceNet(usblist.GetUsbListEntry(index).DeviceId.BusType,
                                                      _onChannelData,
                                                      onError);


            // The second arg refers to lock mask, allowing multiple device objects to be connected
            // to the same physical device. Yes, I know, what the f**k...
            dataAcquisitionDevice.Connect(usblist.GetUsbListEntry(index), 1);
            dataAcquisitionDevice.SendStop();

            int what = 0;

            dataAcquisitionDevice.HWInfo().GetNumberOfHWADCChannels(out what);
            hwchannels = what;

            dataAcquisitionDevice.SetNumberOfChannels(hwchannels);
            dataAcquisitionDevice.EnableDigitalIn(false, 0);
            dataAcquisitionDevice.EnableChecksum(false, 0);
            dataAcquisitionDevice.SetDataMode(DataModeEnumNet.dmSigned32bit, 0);

            // block:
            // get the number of 16 bit datawords which will be collected per sample frame,
            // use after the device is configured. (which means?, setting data mode, num channels etc?)
            int ana, digi, che, tim, block;

            dataAcquisitionDevice.GetChannelLayout(out ana, out digi, out che, out tim, out block, 0);


            dataAcquisitionDevice.SetSampleRate(samplerate, 1, 0);

            int gain = dataAcquisitionDevice.GetGain();

            List <CMcsUsbDacqNet.CHWInfo.CVoltageRangeInfoNet> voltageranges;

            dataAcquisitionDevice.HWInfo().
            GetAvailableVoltageRangesInMicroVoltAndStringsInMilliVolt(out voltageranges);


            bool[] selectedChannels = new bool[block];
            for (int i = 0; i < block; i++)
            {
                selectedChannels[i] = true;
            }                                                        // hurr


            // *org [[file:killme.cs::/%20a%20device%20are%20read%20in%2032%20bit%20data%20format%20nChannels%20=%20ChannelsInBlock/2][documentation]]
            bool[]        nChannels       = selectedChannels;
            int           queueSize       = 120000;
            int           threshold       = segmentLength;
            SampleSizeNet sampleSize      = dataFormat;
            int           ChannelsInBlock = block / 2;

            dataAcquisitionDevice.SetSelectedChannelsQueue
                (nChannels,
                queueSize, // huh?
                threshold,
                sampleSize,
                ChannelsInBlock);

            mChannelHandles = block;

            dataAcquisitionDevice.ChannelBlock_SetCheckChecksum((uint)che, (uint)tim); // ???

            // int voltrange = voltageranges.ToArray()[0];

            int validDataBits    = -1;
            int deviceDataFormat = -1;

            /**
             * Summary:
             *  Get the real number of data bits.
             *
             * Remarks:
             *  This value may be different from the value returned by GetDataFormat, e.g. in
             *  MC_Card the data are shifted 2 bits so the real number is 14 while the data format
             *  is 16 bits
             */
            dataAcquisitionDevice.GetNumberOfDataBits(0,
                                                      DacqGroupChannelEnumNet.HeadstageElectrodeGroup,
                                                      out validDataBits);

            dataAcquisitionDevice.GetDataFormat(0,
                                                DacqGroupChannelEnumNet.HeadstageElectrodeGroup,
                                                out deviceDataFormat);

            DataModeEnumNet dataMode = dataAcquisitionDevice.GetDataMode(0);


            /**
             * Summary:
             * Get the number of 16 bit datawords which will be collected per sample frame,
             * use after the device is configured.
             *
             * Returns:
             * Number of 16 bit datawords per sample frame.
             * Returns 132 (66 32 bit words???)
             */
            int meme = dataAcquisitionDevice.GetChannelsInBlock();

            deviceInfo =
                "Data acquisition device connected to physical device with parameters: \n" +
                $"[SetSelectedChannelsQueue arguments:]\n" +
                $"nChannels           \t{selectedChannels}\n" +
                $"queueSize:          \t{queueSize}\n" +
                $"threshold:          \t{threshold}\n" +
                $"samplesize:         \t{sampleSize}\n" +
                $"channelsInBlock:    \t{ChannelsInBlock}\n\n" +
                $"[Experiment params]\n" +
                $"sample rate:        \t{samplerate}\n" +
                $"Voltage range:      \t{voltageranges[0].VoltageRangeDisplayStringMilliVolt}\n" +
                $"Corresponding to    \t{voltageranges[0].VoltageRangeInMicroVolt} µV\n" +
                $"[Device channel layout]\n\n" +
                $"hardware channels:  \t{hwchannels}\n" + // 64
                $"analog channels:    \t{ana}\n" +        // 128
                $"digital channels:   \t{digi}\n" +       // 2
                $"che(??) channels:   \t{che}\n" +        // 4
                $"tim(??) channels:   \t{tim}\n\n" +
                $"[Other..]\n" +
                $"valid data bits:    \t{validDataBits}\n" +    // 24
                $"device data format: \t{deviceDataFormat}\n" + // 32
                $"device data mode:   \t{dataMode}\n" +         // dmSigned24bit
                $"nice meme:          \t{meme}\n" +
                "";

            return(true);
        }