Exemple #1
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!");
        }
Exemple #2
0
        private void btStart_Click(object sender, EventArgs e)
        {
            int DACResolution = device.GetDACResolution();

            device.SetCurrentMode();
            device.GetCurrentRangeInNanoAmp(0);
            device.GetCurrentResolutionInNanoAmp(0);

            device.SendSegmentSelect(0, Stg200xSegmentFlagsEnumNet.None);

            // Setup Trigger
            uint triggerInputs = device.GetNumberOfTriggerInputs();

            uint[] channelmap = new uint[triggerInputs];
            uint[] syncoutmap = new uint[triggerInputs];
            uint[] repeat     = new uint[triggerInputs];
            for (int i = 0; i < triggerInputs; i++)
            {
                channelmap[i] = 0;
                syncoutmap[i] = 0;
                repeat[i]     = 0;
            }
            // Trigger 0
            channelmap[0] = 1; // Channel 1
            syncoutmap[0] = 1; // Syncout 1
            repeat[0]     = 0; // forever

            // Trigger 1
            channelmap[1] = 4; // Channel 3

            device.SetupTrigger(0, channelmap, syncoutmap, repeat);

            // Data for Channel 0
            {
                device.ClearChannelData(0);

                double factor = 1;

                const int l = 1000;
                // without compression
                ushort[] pData = new ushort[l];
                ulong[]  tData = new ulong[l];
                for (int i = 0; i < l; i++)
                {
                    // calculate Sin-Wave
                    double sin = factor * (Math.Pow(2, DACResolution - 1) - 1.0) * Math.Sin(2.0 * i * Math.PI / l);

                    // calculate sign
                    pData[i] = sin >= 0 ? (ushort)sin : (ushort)((int)Math.Abs(sin) + (int)Math.Pow(2, DACResolution - 1));

                    tData[i] = 20; // duration in µs
                }
                device.SendChannelData(0, pData, tData);

                /*
                 * // with compression
                 * List<ushort> pData = new List<ushort>();
                 * List<UInt64> tData = new List<UInt64>();
                 * int j = 0;
                 * for (int i = 0; i < l; i++)
                 * {
                 *  // calculate Sin-Wave
                 *  double sin = factor * (Math.Pow(2, DACResolution - 1) - 1.0) *
                 *      Math.Sin(2.0 * (double)i * Math.PI / (double)l);
                 *
                 *  // calculate sign
                 *  ushort newval = sin >= 0 ? (ushort)sin : (ushort)((int)Math.Abs(sin) +
                 *      (int)Math.Pow(2, DACResolution - 1));
                 *
                 *  // do compression, duration in µs
                 *  if (j > 0 && pData[j - 1] == newval)
                 *  {
                 *      tData[j - 1] += 20;
                 *  }
                 *  else
                 *  {
                 *      pData.Add(newval);
                 *      tData.Add(20);
                 *      j++;
                 *  }
                 * }
                 * device.SendChannelData(0, pData.ToArray(), tData.ToArray());
                 */
            }

            // Data for Channel 3
            {
                device.ClearChannelData(2);

                double factor = 0.1;

                const int l = 700;
                // without compression
                ushort[] pData = new ushort[l];
                ulong[]  tData = new ulong[l];
                for (int i = 0; i < l; i++)
                {
                    // calculate Sin-Wave
                    double sin = factor * (Math.Pow(2, DACResolution - 1) - 1.0) * Math.Sin(2.0 * i * Math.PI / l);

                    // calculate sign
                    pData[i] = sin >= 0 ? (ushort)sin : (ushort)((int)Math.Abs(sin) + (int)Math.Pow(2, DACResolution - 1));

                    tData[i] = 20; // duration in µs
                }
                device.SendChannelData(2, pData, tData);
            }
            // Data for Sync 0
            {
                device.ClearSyncData(0);

                ushort[] pData = new ushort[1000];
                ulong[]  tData = new ulong[1000];
                for (int i = 0; i < 1000; i++)
                {
                    pData[i] = (ushort)(i & 1);
                    tData[i] = 20; // duration in µs
                }
                device.SendSyncData(0, pData, tData);
            }

            // Only meaningful for STG400x
            device.SetVoltageMode();

            // Start Trigger 1 and 2
            device.SendStart(1 + 2); // Trigger 1 and 2

            btStart.Enabled = false;
            btStop.Enabled  = true;
        }