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);
        }
Esempio n. 2
0
        private void CbDevicesSelectedIndexChanged(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 + Environment.NewLine;
            int hwchannels;

            device.HWInfo().GetNumberOfHWADCChannels(out hwchannels);
            tbDeviceInfo.Text += @"Number of Hardwarechannels: " + 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();

            List <CMcsUsbDacqNet.CHWInfo.CVoltageRangeInfoNet> voltageranges;

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

            // 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
            block = device.GetChannelsInBlock();

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

            channelblocksize = Samplingrate / 10; // good choise 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
            }
            // queue size and threshold should be selected carefully
#if channelmethod
#if channeldata
            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, CMcsUsbDacqNet.SampleSize.Size16, block);
            mChannelHandles = block; // for this case, if all channels are selected
#else // !channeldata
            device.SetSelectedChannels(selChannels, 10 * channelblocksize, channelblocksize, CMcsUsbDacqNet.SampleSize.Size16);
            m_channel_handles = block;     // for this case, if all channels are selected
#endif // !channeldata
#else // !channelmethod
            device.SetSelectedChannelsQueue(selChannels, 10 * channelblocksize, channelblocksize, CMcsUsbDacqNet.SampleSize.Size16);
#endif // !channelmethod
            device.ChannelBlock_SetCheckChecksum((uint)che, (uint)tim);
        }