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!"); } }
public bool WriteRegister(UInt32 Address, UInt32 Data) { if (DevicesReady) { CMcsUsbFactoryNet factorydev = new CMcsUsbFactoryNet(); if (factorydev.Connect(DspPort) == 0) { factorydev.Mea21WriteRegister(Address, Data); factorydev.Disconnect(); return(true); } } return(false); }
// TODO: Does this actually perform a sufficient factory reset? // clearly no... public void resetDevices() { if (dspDevice.Connect(dspPort, lockMask) == 0) { Console.WriteLine("resetting MCU1"); dspDevice.Coldstart(CFirmwareDestinationNet.MCU1); } else { Console.WriteLine("Connection Error when attempting to reset device"); return; } dspDevice.Disconnect(); }
public UInt32 ReadRegister(UInt32 Address) { UInt32 Value = 0; if (DevicesReady) { CMcsUsbFactoryNet factorydev = new CMcsUsbFactoryNet(); if (factorydev.Connect(DspPort) == 0) { Value = factorydev.Mea21ReadRegister(Address); factorydev.Disconnect(); } } return(Value); }
public bool Download_Code(string FirmwareFile) { if (DevicesReady) { CMcsUsbFactoryNet factorydev = new CMcsUsbFactoryNet(); factorydev.LoadUserFirmware(FirmwareFile, DspPort); // Code for uploading compiled binary factorydev.Disconnect(); Console.WriteLine("Firmware Loaded : " + FirmwareFile); return(true); } else { return(false); } }
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"); } }
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"); } }
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"); } }
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(); } }