Example #1
0
        private void stopDacq_Click(object sender, EventArgs e)
        {
            if (mea.GetDeviceId().IdProduct == ProductIdEnumNet.W2100)
            {
                CW2100_FunctionNet func = new CW2100_FunctionNet(mea);
                if (!w2100_hs_samling)
                {
                    func.SetHeadstageSamplingActive(false, other_receiver + 0);
                }
            }

            startDacq.Enabled = true;
            stopDacq.Enabled  = false;

            mea.StopDacq();
            mea.Disconnect();
        }
        private void BtStartClick(object sender, EventArgs e)
        {
            device.StartDacq();

            if (useWireless)
            {
                CW2100_FunctionNet func = new CW2100_FunctionNet(device);
                func.SetHeadstageSamplingActive(true, 0);
            }

            btMeaDevice_present.Enabled = false;
            cbDevices.Enabled           = false;
            btStart.Enabled             = false;
            btStop.Enabled = true;

            if (usePollForData)
            {
                LastData      = 0;
                timer.Enabled = true;
            }
        }
        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);
        }
Example #4
0
        private void startDacq_Click(object sender, EventArgs e)
        {
            startDacq.Enabled = false;
            stopDacq.Enabled  = true;

            other_receiver = 0;
            if (((CMcsUsbListEntryNet)cbDeviceList.SelectedItem).SerialNumber.EndsWith("-B"))
            {
                other_receiver = 4; // bit 0/1 select the timeslot of: bit 2/3 = 0 receiver according to USB port, 1 receiver A, 2 receiver B
            }

            uint status = mea.Connect((CMcsUsbListEntryNet)cbDeviceList.SelectedItem, 63);

            if (status == 0)
            {
                int ChannelsInBlock;

                mea.SetDataMode(DataModeEnumNet.Signed_32bit, 0);
                if (mea.GetDeviceId().IdProduct == ProductIdEnumNet.W2100)
                {
                    Samplerate = 20000;
                }

                mea.SetNumberOfAnalogChannels(Channels, 0, Channels, AnalogChannels, 0); // Read raw data

                try
                {
                    mea.SetSamplerate(Samplerate, 1, 0);
                }
                catch (CUsbExceptionNet)
                {
                    Samplerate = mea.GetSamplerate(0);
                }

                mea.EnableDigitalIn((use_digital_in ? (DigitalDatastreamEnableEnumNet)3 : 0), 0);

                // map feedback bit 0 to digital(in) stream bit 4
                mea.SetDigitalSource(DigitalTargetEnumNet.Digstream, 4, W2100DigitalSourceEnumNet.Feedback, 0);
                mea.SetDigitalSource(DigitalTargetEnumNet.Digout, 0, W2100DigitalSourceEnumNet.Feedback, 0);

                mea.EnableChecksum(true, 0);
                ChannelsInBlock = mea.GetChannelsInBlock(0);

                mea.GetChannelLayout(out int analogChannels, out int digitalChannels, out int checksumChannels, out int timestampChannels, out int channelsInBlock, 0);

                TotalChannels = channelsInBlock / 2;
                mea.SetSelectedData(TotalChannels, Samplerate * 10, Samplerate, SampleSizeNet.SampleSize32Signed, ChannelsInBlock);

                mea.ChannelBlock_SetCheckChecksum((uint)checksumChannels, (uint)timestampChannels);
                mea.StartDacq();
                if (mea.GetDeviceId().IdProduct == ProductIdEnumNet.W2100)
                {
                    CW2100_FunctionNet func = new CW2100_FunctionNet(mea);
                    w2100_hs_samling = func.GetHeadstageSamplingActive(other_receiver + 0);
                    func.SetHeadstageSamplingActive(false, other_receiver + 0);
#if true
                    // Send Stimulation pattern
                    bool first     = true;
                    int  preplegth = 0;
                    CW2100_StimulatorFunctionNet stim = new CW2100_StimulatorFunctionNet(mea);
                    stim.SelectTimeSlot(other_receiver + 0);
#if false
                    // Different repetition
                    int[]   ampl = new[] { 0, 100000, -100000, 0, 6, 0 };
                    ulong[] dur  = new ulong[] { 0, 10000, 10000, 10000, 0, 300000 };
                    for (int i = 0; i < 16; i++)
                    {
                        ampl[4] = i + 2;
#else
                    // Different strength
                    int[] ampl = new[] { 1000000, -1000000, 0 }
                    ;
                    ulong[] dur = new ulong[] { 2000, 2000, 10000 - 2 * 2000 };
                    for (int i = 0; i < 16; i++)
                    {
                        ampl[0] = 40000 * i + 50000;
                        ampl[1] = -40000 * i - 50000;
#endif
                        // choose, if global repeat is desired
                        CStimulusFunctionNet.StimulusDeviceDataAndUnrolledData prep = stim.PrepareData(0, ampl, dur, STG_DestinationEnumNet.channeldata_current, 1);
                        if (first)
                        {
                            first     = false;
                            preplegth = prep.DeviceDataLength;
                        }

                        Debug.Assert(preplegth == prep.DeviceDataLength);
                        Debug.Assert(prep.DeviceDataLength <= 15);
                        stim.SendPreparedData(0x10 * i + 0, prep, STG_DestinationEnumNet.channeldata_current);
                    }
#endif
                    func.SetHeadstageSamplingActive(true, other_receiver + 0);
                }
            }
            else
            {
                MessageBox.Show(CMcsUsbNet.GetErrorText(status));
                startDacq.Enabled = true;
                stopDacq.Enabled  = false;
            }
        }