Exemplo n.º 1
0
        public bool ConnectToDevice()
        {
            Console.WriteLine("Connecting to Devices");

            SearchDevice();
            if (DevicesReady)
            {
                Port_1.Connect(RawPort);
                Port_2.Connect(DspPort);
                Connected = true;
            }
            return(Connected);
        }
Exemplo n.º 2
0
        private void DigOutSignal_Click(object sender, EventArgs e)
        {
            CMeaUSBDeviceNet mea = new CMeaUSBDeviceNet(); // Create object of class CMcsUsbFactoryNet (provides firmware upgrade and register access capabilities)

            if (mea.Connect(DspPort, LockMask) == 0)
            {
                CDigOutStimulatorFunctionNet dig = new CDigOutStimulatorFunctionNet(mea);
                int[]   ampl = new int[] { 1, 0 };
                ulong[] dur  = new ulong[] { 200000, 1000000 };
                CStimulusFunctionNet.StimulusDeviceDataAndUnrolledData data = dig.PrepareChannelData(ampl, dur);
                dig.SendChannelData(0, data);
                dig.SetGlobalRepeat(0, true);
                mea.SetDigitalSource <SCUDigitalSourceEnumNet>(DigitalTargetEnumNet.DigOutStimulatorStartTrigger, 0, new DigitalSource <SCUDigitalSourceEnumNet>(SCUDigitalSourceEnumNet.DigitalData), 0);
                mea.SetDigitalSource <SCUDigitalSourceEnumNet>(DigitalTargetEnumNet.Digout, 3, new DigitalSource <SCUDigitalSourceEnumNet>(SCUDigitalSourceEnumNet.DigitalOutStimulator), 0);
                mea.MeaDigitalDataFunctionNet.SetDigitalData(0, false);
                mea.MeaDigitalDataFunctionNet.SetDigitalData(0, true);
                mea.Disconnect();
            }
        }
Exemplo n.º 3
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;
            }
        }