Ejemplo n.º 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!");
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        private void UploadDSPBinary_Click(object sender, EventArgs e)
        {
            CMcsUsbFactoryNet factorydev = new CMcsUsbFactoryNet();

            if (DspPort != null || RawPort != null)
            {
                CMcsUsbListEntryNet port = DspPort;
                if (port == null)
                {
                    port = RawPort;
                }

                if (factorydev.Connect(port, LockMask) == 0)
                {
                    string FirmwareFile;
                    FirmwareFile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    if (factorydev.GetDeviceId().IdProduct == ProductIdEnumNet.MEA2100)
                    {
                        FirmwareFile += @"\..\..\..\..\DSP\FB_Example\Release\";
                        FirmwareFile += "FB_Example.bin";
                    }
                    else
                    {
                        FirmwareFile += @"\..\..\..\..\DSP\FB_W2100_SCU_MEA256\Release\";
                        FirmwareFile += "FB_W2100_SCU_MEA256.bin";
                    }

                    factorydev.Disconnect();

                    bool success = factorydev.LoadUserFirmware(FirmwareFile, port, LockMask); // Code for uploading compiled binary
                    if (!success)
                    {
                        MessageBox.Show("Firmware upload failed!");
                    }
                }
            }
            else
            {
                MessageBox.Show("No port available");
            }
        }
Ejemplo n.º 4
0
        private void btConnect_Click(object sender, EventArgs e)
        {
            if (device != null)
            {
                device.SendStop(1);
                device.Disconnect();
                device.Dispose();
                device = null;
            }

            device = new CStg200xDownloadNet(PollHandler);
            CMcsUsbListEntryNet listEntry = usblist.GetUsbListEntry((uint)cbDevices.SelectedIndex);

            device.Connect(listEntry);

            cbDevices.Enabled    = false;
            btConnect.Enabled    = false;
            btStart.Enabled      = true;
            btStop.Enabled       = false;
            btDisconnect.Enabled = true;
        }
Ejemplo n.º 5
0
        private void StopDSP_Click(object sender, EventArgs e)
        {
            CMcsUsbFactoryNet factorydev = new CMcsUsbFactoryNet(); // Create object of class CMcsUsbFactoryNet (provides firmware upgrade and register access capabilities)

            if (DspPort != null || RawPort != null)
            {
                CMcsUsbListEntryNet port = DspPort;
                if (port == null)
                {
                    port = RawPort;
                }

                if (factorydev.Connect(port, LockMask) == 0) // if connect call returns zero, connect has been successful
                {
                    factorydev.Coldstart(CFirmwareDestinationNet.MCU1);
                    factorydev.Disconnect();
                }
            }
            else
            {
                MessageBox.Show("No port available");
            }
        }
Ejemplo n.º 6
0
        private void ConnectMEA_Click(object sender, EventArgs e)
        {
            CMcsUsbFactoryNet factorydev = new CMcsUsbFactoryNet(); // Create object of class CMcsUsbFactoryNet (provides firmware upgrade and register access capabilities)

            if (DspPort != null || RawPort != null)
            {
                CMcsUsbListEntryNet port = DspPort;
                if (port == null)
                {
                    port = RawPort;
                }
                if (factorydev.Connect(port, LockMask) == 0) // if connect call returns zero, connect has been successful
                {
                    //int Thresh = (int)(Convert.ToDouble(SpikeThresh.Text) / (5000000 / Math.Pow(2, 24) / 10)); // 5 V input range ADC, 24bit ADC, 10 volt hardware gain
                    int Thresh   = (int)(Convert.ToInt64(SpikeThresh.Text) * 8388608 / 2500);
                    int DeadTime = Convert.ToInt32(Deadtime.Text) * Fs / 1000;

                    int StimAmplitude = 2 * Convert.ToInt32(BoxStimAmplitude.Text); // resolution is 500 uV / bit, thus factor allows user to specify stim amplitude in mV
                    int StimDuration  = Convert.ToInt32(BoxStimDuration.Text) / (1000000 / Fs);
                    int StimRepeats   = Convert.ToInt32(BoxStimRepeats.Text);
                    int StimStepsize  = 2 * Convert.ToInt32(BoxStimStepsize.Text); // resolution is 500 uV / bit, thus factor allows user to specify stim amplitude in mV

                    factorydev.WriteRegister(0x1000, (uint)Thresh);
                    factorydev.WriteRegister(0x1004, (uint)DeadTime);
                    factorydev.WriteRegister(0x1008, (uint)StimAmplitude);
                    factorydev.WriteRegister(0x100c, (uint)StimDuration);
                    factorydev.WriteRegister(0x1010, (uint)StimRepeats);
                    factorydev.WriteRegister(0x1014, (uint)StimStepsize);

                    factorydev.Disconnect();
                }
            }
            else
            {
                MessageBox.Show("No port available");
            }
        }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
0
 void devices_DeviceArrival(CMcsUsbListEntryNet entry)
 {
     SearchDevice();
 }
Ejemplo n.º 9
0
 private void Usblist_DeviceArrival(CMcsUsbListEntryNet entry)
 {
     UpdateDeviceList();
 }
Ejemplo n.º 10
0
        // Occurs when the value of the selected index of the combo box (i.e. the seleted MEA device) changes.
        private void ComboBoxMeaDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            var index = (uint)this.comboBoxMeaDevices.SelectedIndex;

            // TODO understand MCS black magic.
            usb = this.usbList.GetUsbListEntry(index);
            // TODO understand MCS black magic.
            this.device = new CMeaDeviceNet(usb.DeviceId.BusType, ChannelDataCallback, ErrorCallback);
            // Establish a connection to the required DAQ device.
            this.device.Connect(usb);
            // TODO understand MCS black magic.
            this.device.SendStop();
            // TODO understand MCS black magic.
            var hardwareInfo = this.device.HWInfo();

            // Get the number of available analog hardware channels.
            hardwareInfo.GetNumberOfHWADCChannels(out nb_channels);
            // Set the number of analog hardware channels to the maximum.
            this.device.SetNumberOfChannels(nb_channels);
            // Update the text box which displays the number of analog hardware channels.
            this.textBoxNumberOfChannels.Text = nb_channels.ToString();
            // TODO understand MCS black magic.
            //hardwareInfo.GetAvailableSampleRates(out List<int> sample_rates);
            this.sample_rate = 20000;
            // TODO understand MCS black magic.
            var oversample    = (uint)1;
            var virtualDevice = 0;

            this.device.SetSampleRate(sample_rate, oversample, virtualDevice);
            this.textBoxSampleRate.Text = sample_rate.ToString();
            // TODO understand MCS black magic.
            gain = this.device.GetGain();
            this.textBoxGain.Text = gain.ToString();
            // TODO understand MCS black magic.
            //hardwareInfo.GetAvailableVoltageRangesInMicroVoltAndStringsInMilliVolt(out List<CMcsUsbDacqNet.CHWInfo.CVoltageRangeInfoNet> voltage_ranges);
            //var voltage_range = 10;
            // TODO understand MCS black magic.
            //this.device.SetVoltageRangeInMicroVolt(voltage_range);
            // TODO understand MCS black magic.
            this.device.EnableDigitalIn(true, virtualDevice);
            // TODO understand MCS black magic.
            this.device.EnableChecksum(true, virtualDevice);
            // TODO understand MCS black magic.
            //this.device.EnableTimestamp(false);
            // TODO understand MCS black magic.
            int analog_channels;
            int digital_channels;
            int checksum_channels;
            int timestamp_channels;

            this.device.GetChannelLayout(out analog_channels, out digital_channels, out checksum_channels, out timestamp_channels, out this.channels_in_block, (uint)virtualDevice);
            this.channels_in_block           = this.device.GetChannelsInBlock();
            this.textBoxChannelsInBlock.Text = this.channels_in_block.ToString();
            // ...
            this.selected_channels = new bool[this.channels_in_block];
            for (var i = 0; i < this.channels_in_block; i++)
            {
                this.selected_channels[i] = true;
            }
            // TODO check the value of the buffer size.
            this.buf_size = sample_rate / 10;
            //this.buf_size = sample_rate / 100;
            this.queue_size            = 20 * this.buf_size;
            this.textBoxQueueSize.Text = this.queue_size.ToString();
            // ...
            this.threshold             = this.buf_size;
            this.textBoxThreshold.Text = this.threshold.ToString();
            // ...
            this.sample_size            = SampleSizeNet.SampleSize16Unsigned;
            this.textBoxSampleSize.Text = sample_size.ToString();
            // TODO understand MCS black magic.
            this.device.ChannelBlock_SetCheckChecksum((uint)checksum_channels, (uint)timestamp_channels);
            // Enable control.
            this.textBoxQueueSize.Enabled           = true;
            this.textBoxThreshold.Enabled           = true;
            this.buttonDataAcquisitionStart.Enabled = true;
        }