private void cbDevices_SelectedIndexChanged(object sender, EventArgs e) { if (device != null) { device.StopDacq(); device.Disconnect(); device.Dispose(); device = null; } uint sel = (uint)cbDevices.SelectedIndex; /* choose one of the following contructors: * The first one uses the OnNewData callback and gives you a reference to the raw multiplexed data, * this could be used without further initialisation * The second uses the more advanced callback which gives you the data for each channel in a callback, but need initialistation * for buffers and the selected channels */ if (sel >= 0) // a device is selected, enable the sampling buttons { btStart.Enabled = true; } else { btStart.Enabled = false; } btStop.Enabled = false; device = new CMeaDeviceNet(usblist.GetUsbListEntry(sel).DeviceId.BusType, OnChannelData, OnError); device.Connect(usblist.GetUsbListEntry(sel)); device.SendStop(); // only to be sure tbDeviceInfo.Text = ""; tbDeviceInfo.Text += /*"Serialnumber: " +*/ device.SerialNumber + "\r\n"; int hwchannels; device.HWInfo().GetNumberOfHWADCChannels(out hwchannels); tbDeviceInfo.Text += "Number of Hardwarechannels: " + hwchannels.ToString() + "\r\n"; // configure MeaDevice: MC_Card or Usb device.SetNumberOfChannels(hwchannels); int samplingrate = 5000; // MC_Card does not support all settings, please see MC_Rack for valid settings device.SetSampleRate(samplingrate, 1, 0); int gain; device.GetGain(out gain); List <CMcsUsbDacqNet.CHWInfo.CVoltageRangeInfoNet> voltageranges; device.HWInfo().GetAvailableVoltageRangesInMicroVoltAndStringsInMilliVolt(out voltageranges); for (int i = 0; i < voltageranges.Count; i++) { tbDeviceInfo.Text += "(" + i.ToString() + ") " + voltageranges[i].VoltageRangeDisplayStringMilliVolt + "\r\n"; } // Set the range acording to the index (only valid for MC_Card) // device.SetVoltageRangeInMicroVoltByIndex(0, 0); device.EnableDigitalIn(true, 0); // Checksum not supported by MC_Card device.EnableChecksum(true, 0); // Get the layout to know how the data look like that you receive int ana, digi, che, tim, block; device.GetChannelLayout(out ana, out digi, out che, out tim, out block, 0); // or device.GetChannelsInBlock(out block); m_block = block; // 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 //Console.WriteLine("Selected: " + block); // selChannels[i] = false; // With false the channel i is deselected } // queue size and threshold should be selected carefully device.SetSelectedData(selChannels, 10 * channelblocksize, channelblocksize, SampleSizeNet.SampleSize16, block); // Alternative call if you want to select all channels //device.SetSelectedData(block, 10 * channelblocksize, channelblocksize, CMcsUsbDacqNet.SampleSize.Size16, block); m_channel_handles = block; // for this case, if all channels are selected }
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); }