Beispiel #1
0
        public DSPComms()
        {
            dspDevice = new CMcsUsbFactoryNet();
            dspDevice.EnableExceptions(true);
            usblist.Initialize(DeviceEnumNet.MCS_MEAUSB_DEVICE); // Get list of MEA devices connect by USB

            bool dspPortFound = false;
            uint lockMask     = 64;

            for (uint ii = 0; ii < usblist.Count; ii++)
            {
                if (usblist.GetUsbListEntry(ii).SerialNumber.EndsWith("B"))
                {
                    dspPort      = usblist.GetUsbListEntry(ii);
                    dspPortFound = true;
                    break;
                }
            }

            if (dspPortFound && (dspDevice.Connect(dspPort, lockMask) == 0))
            {
                connected = true;
                dspDevice.Disconnect();
            }
            else
            {
                Console.WriteLine("Fug!");
            }
        }
Beispiel #2
0
        public void SearchDevice()
        {
            devices.Initialize(DeviceEnumNet.MCS_MEAUSB_DEVICE); // Get list of MEA devices connect by USB

            RawPort = null;
            DspPort = null;

            DevicesReady = false;
            if (devices.Count == 2)
            {
                for (uint i = 0; i < devices.Count; i++)                       // loop through number of devices found
                {
                    if (devices.GetUsbListEntry(i).SerialNumber.EndsWith("A")) // check for each device if serial number ends with "A" (USB 1) This USB interface will be used by MC_Rack
                    {
                        RawPort = devices.GetUsbListEntry(i);
                    }
                    if (devices.GetUsbListEntry(i).SerialNumber.EndsWith("B"))// check for each device if serial number ends with "B" (USB 2) This USB interface will be used to control DSP
                    {
                        DspPort = devices.GetUsbListEntry(i);
                    }
                }
                Console.WriteLine("Both ports available");
                DevicesReady = true;
            }

            if (DeviceStateChange != null)
            {
                DeviceStateChange(this, EventArgs.Empty);
            }
        }
Beispiel #3
0
 private void updateDeviceList()
 {
     usblist.Initialize(DeviceEnumNet.MCS_MEA_DEVICE);
     devices = new String[usblist.Count];
     for (uint ii = 0; ii < usblist.Count; ii++)
     {
         devices[ii] =
             usblist.GetUsbListEntry(ii).DeviceName + " / "
             + usblist.GetUsbListEntry(ii).SerialNumber;
     }
     this.devices = devices;
 }
 private void BtMeaDevicePresentClick(object sender, EventArgs e)
 {
     cbDevices.Items.Clear();
     for (uint i = 0; i < usblist.Count; i++)
     {
         cbDevices.Items.Add(usblist.GetUsbListEntry(i).DeviceName + " / " + usblist.GetUsbListEntry(i).SerialNumber);
     }
     if (cbDevices.Items.Count > 0)
     {
         cbDevices.SelectedIndex = 0;
     }
 }
Beispiel #5
0
 private void btMeaDevice_present_Click(object sender, EventArgs e)
 {
     cbDevices.Items.Clear();
     usblist.Initialize(DeviceEnumNet.MCS_MEA_DEVICE);
     for (uint i = 0; i < usblist.Count; i++)
     {
         cbDevices.Items.Add(usblist.GetUsbListEntry(i).DeviceName + " / " + usblist.GetUsbListEntry(i).SerialNumber);
     }
     if (cbDevices.Items.Count > 0)
     {
         cbDevices.SelectedIndex = 0;
     }
 }
Beispiel #6
0
        private void UpdateDeviceList()
        {
            cbDevices.Items.Clear();

            for (uint i = 0; i < usblist.Count; i++)
            {
                var listEntry = usblist.GetUsbListEntry(i);
                cbDevices.Items.Add(listEntry.DeviceName + " / " + listEntry.SerialNumber);
            }
            if (cbDevices.Items.Count > 0)
            {
                cbDevices.SelectedIndex = 0;
                btConnect.Enabled       = true;
            }
        }
Beispiel #7
0
        private void BtnStartClick(object sender, EventArgs e)
        {
            // Get a list of all available MEA USB Devices such as the MEA2100, for example.
            CMcsUsbListNet cDeviceList = new CMcsUsbListNet(DeviceEnumNet.MCS_MEAUSB_DEVICE);

            if (cDeviceList.Count == 0)
            {
                MessageBox.Show("No MEA USB Device connected!", "Error Connecting To Device", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var deviceEntry = cDeviceList.GetUsbListEntry(0);

            CStg200xDownloadNet cStgDevice = new CStg200xDownloadNet();

            // Connect to the stimulator of the device. The lock mask allows multiple connections to the same device
            cStgDevice.Connect(deviceEntry, 1);

            uint electrode = 3;

            // ElectrodeMode: emManual: electrode is permanently selected for stimulation
            cStgDevice.SetElectrodeMode(electrode, ElectrodeModeEnumNet.emManual);

            // ElectrodeDacMux: DAC to use for stimulation
            cStgDevice.SetElectrodeDacMux(electrode, 0, ElectrodeDacMuxEnumNet.Stg1);

            // ElectrodeEnable: enable electrode for stimulation
            cStgDevice.SetElectrodeEnable(electrode, 0, true);

            // BlankingEnable: false: do not blank the ADC signal while stimulation is running
            cStgDevice.SetBlankingEnable(electrode, false);

            // AmplifierProtectionSwitch: false: Keep ADC connected to electrode even while stimulation is running
            cStgDevice.SetEnableAmplifierProtectionSwitch(electrode, false);

            // array of amplitudes and duration
            int[] amplitude = new int[2] {
                10000, -10000
            };                                            // µV
            ulong[] duration = new ulong[2] {
                100000, 100000
            };                                                // µs

            // use voltage stimulation
            cStgDevice.SetVoltageMode();

            // send stimulus data to device
            cStgDevice.PrepareAndSendData(0, amplitude, duration, STG_DestinationEnumNet.channeldata_voltage);

            // connect all stimulation channels to the first trigger
            cStgDevice.SetupTrigger(0, new uint[] { 255 }, new uint[] { 255 }, new uint[] { 1 });

            // start the first trigger
            cStgDevice.SendStart(1);

            cStgDevice.Disconnect();

            MessageBox.Show("Stimulation finished!");
        }
        private void RefreshDeviceList()
        {
            cbDeviceList.Items.Clear();
            for (uint i = 0; i < UsbDeviceList.Count; i++)
            {
                cbDeviceList.Items.Add(UsbDeviceList.GetUsbListEntry(i));
            }

            if (cbDeviceList.Items.Count > 0)
            {
                cbDeviceList.SelectedIndex = 0;
            }
        }
        private void SearchDevice()
        {
            RawPort = null;
            DspPort = null;

            rawSerial.Text = "not found";
            dspSerial.Text = "not found";


            for (uint i = 0; i < devices.Count; i++)                       // loop through number of devices found
            {
                if (devices.GetUsbListEntry(i).SerialNumber.EndsWith("A")) // check for each device if serial number ends with "A" (USB 1) This USB interface will be used by MC_Rack / Multi Channel Experimenter
                {
                    RawPort        = devices.GetUsbListEntry(i);           // assign to RawPort "handle"
                    rawSerial.Text = RawPort.SerialNumber;
                }
                if (devices.GetUsbListEntry(i).SerialNumber.EndsWith("B")) // check for each device if serial number ends with "B" (USB 2) This USB interface will be used to control DSP
                {
                    DspPort        = devices.GetUsbListEntry(i);           // assign to DSPPort "handle"
                    dspSerial.Text = DspPort.SerialNumber;
                }
            }

            if (RawPort != null && DspPort != null)
            {
                btnDeviceOK.BackColor = Color.LawnGreen;
            }
            else if (RawPort != null || DspPort != null)
            {
                btnDeviceOK.BackColor = Color.Yellow;
            }
            else
            {
                btnDeviceOK.BackColor = Color.Red;
            }

            // Set Filters
            CMcsUsbFactoryNet factorydev = new CMcsUsbFactoryNet();            // Create object of class CMcsUsbFactoryNet (provides firmware upgrade and register access capabilities)

            if (DspPort != null && factorydev.Connect(DspPort, LockMask) == 0) // if connect call returns zero, connect has been successful
            {
#if false
                double[] xcoeffs;
                double[] ycoeffs;
                mkfilterNet.mkfilter("Bu", 0, "Lp", 2, 1000.0 / 50000.0, 0, out xcoeffs, out ycoeffs);
                factorydev.WriteRegister(0x600, DoubleToFixedInt(1, 16, 30, xcoeffs[0])); // set b[0] fpr 100 Hz HP
                factorydev.WriteRegister(0x608, DoubleToFixedInt(1, 15, 30, xcoeffs[1])); // set b[1] fpr 100 Hz HP
                factorydev.WriteRegister(0x60C, DoubleToFixedInt(1, 30, 30, ycoeffs[1])); // set a[1] fpr 100 Hz HP
                factorydev.WriteRegister(0x610, DoubleToFixedInt(1, 16, 30, xcoeffs[2])); // set b[2] fpr 100 Hz HP
                factorydev.WriteRegister(0x614, DoubleToFixedInt(1, 30, 30, ycoeffs[2])); // set a[2] fpr 100 Hz HP
                factorydev.WriteRegister(0x61C, 0x00000001);                              // enable
                mkfilterNet.mkfilter("Bu", 0, "Hp", 2, 100.0 / 50000.0, 0, out xcoeffs, out ycoeffs);
                factorydev.WriteRegister(0x620, DoubleToFixedInt(1, 16, 30, xcoeffs[0])); // set b[0] fpr 100 Hz HP
                factorydev.WriteRegister(0x628, DoubleToFixedInt(1, 15, 30, xcoeffs[1])); // set b[1] fpr 100 Hz HP
                factorydev.WriteRegister(0x62C, DoubleToFixedInt(1, 30, 30, ycoeffs[1])); // set a[1] fpr 100 Hz HP
                factorydev.WriteRegister(0x630, DoubleToFixedInt(1, 16, 30, xcoeffs[2])); // set b[2] fpr 100 Hz HP
                factorydev.WriteRegister(0x634, DoubleToFixedInt(1, 30, 30, ycoeffs[2])); // set a[2] fpr 100 Hz HP
                factorydev.WriteRegister(0x63C, 0x00000001);                              // enable
#endif
                factorydev.Disconnect();
            }
        }
Beispiel #10
0
        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);
        }