private void UpdateDeviceTable(uint selectedHub) { using (var c = ONIContextManager.ReserveContext(Configuration.Slot)) { var context = c.Context; dataGridViewDeviceTable.Rows.Clear(); for (int i = 0; i < context.DeviceTable.Count; i++) { var dev = context.DeviceTable.Values.ElementAt(i); var idx = context.DeviceTable.Keys.ElementAt(i); var hub = (idx & 0x0000FF00) >> 8; if (dev.ID != (int)ONIX.DeviceID.Null && hub == selectedHub) { var ri = dataGridViewDeviceTable.Rows.Add( idx + $@" ({(byte)(idx >> 8):X2}.{(byte)(idx >> 0):X2})", (DeviceID)dev.ID, dev.Version, dev.ReadSize, dev.WriteSize, dev.Description); dataGridViewDeviceTable.Rows[ri].HeaderCell.Value = ri.ToString(); } } } }
private void buttonBlockMin_Click(object sender, EventArgs e) { using (var c = ONIContextManager.ReserveContext(Configuration.Slot)) { var context = c.Context; Configuration.ReadSize = (int)context.MaxReadFrameSize; numericUpDownReadSize.Value = Configuration.ReadSize; } }
private void dataGridViewDeviceTable_SelectionChanged(object sender, EventArgs e) { if (dataGridViewDeviceTable.SelectedRows.Count == 0) { propertyGridSelecteDevice.SelectedObject = null; return; } var row = dataGridViewDeviceTable.SelectedRows[0]; var deviceIndexStr = (row.Cells[0].Value as string).Split(' ')[0]; var deviceIndex = uint.Parse(deviceIndexStr); using (var c = ONIContextManager.ReserveContext(Configuration.Slot)) { var context = c.Context; if (context.DeviceTable.TryGetValue(deviceIndex, out oni.Device dev)) { var device = ONIDeviceFactory.Make((DeviceID)dev.ID); if (device != null) { // Hacky "back door" into ONIDeviceIndexTypeConverter's functionality device.DeviceAddress = new ONIDeviceAddress { HardwareSlot = Configuration.Slot, Address = deviceIndex }; propertyGridSelecteDevice.SelectedObject = device; } else { propertyGridSelecteDevice.SelectedObject = null; } } else { propertyGridSelecteDevice.SelectedObject = null; } } }
public StimulatorEditorDialog(ONIDeviceAddress address) { InitializeComponent(); // Make device using (var c = ONIContextManager.ReserveContext(address.HardwareSlot)) { var context = c.Context; if (context.DeviceTable.TryGetValue((uint)address.Address, out oni.Device dev)) { device = ONIDeviceFactory.Make((DeviceID)dev.ID); if (device != null) { device.DeviceAddress = address; // Bind to properties pane propertyGridStimulator.SelectedObject = device; } else { propertyGridStimulator.SelectedObject = null; } } else { propertyGridStimulator.SelectedObject = null; } } SetupDisplay(); DrawWaveform(); FitWaveform(); zedGraphWaveform.KeyDown += ZedGraphWaveform_KeyDown; zedGraphWaveform.KeyUp += ZedGraphWaveform_KeyUp; }
private void AttemptToConnect() { dataGridViewDeviceTable.Rows.Clear(); tabControlHubs.SelectedTab = tabControlHubs.TabPages[0]; tabControlHubs.SelectedTab.Text = ""; while (tabControlHubs.TabPages.Count > 1) { tabControlHubs.TabPages.RemoveAt(tabControlHubs.TabPages.Count - 1); } try { using (var c = ONIContextManager.ReserveContext(Configuration.Slot)) { var context = c.Context; var hubs = new List <oni.Hub>(); foreach (var d in context.DeviceTable.Values) { if (d.ID != (int)ONIX.DeviceID.Null) { try { hubs.Add(context.GetHub(d.Address)); } catch (oni.ONIException) { Console.WriteLine($@"Failure to obtain hub information for device at address {d.Address}."); } } } hubs = hubs.GroupBy(h => h.Address).Select(g => g.First()).ToList(); if (hubs.Count > 0) { tabControlHubs.TabPages[0].Text = $@"Hub 0x{hubs.ElementAt(0).Address:X2}: " + hubs[0].Description; tabControlHubs.TabPages[0].Tag = hubs[0]; foreach (var h in hubs.GetRange(1, hubs.Count - 1)) { var text = $@"Hub 0x{h.Address:X2}: " + h.Description; tabControlHubs.TabPages.Add(h.Address.ToString(), text); tabControlHubs.TabPages[h.Address.ToString()].Tag = h; } } UpdateDeviceTable(hubs[0].Address); toolStripSplitButton.Text = Properties.Resources.ONIConnectionSuccess; toolStripSplitButton.ForeColor = Color.Black; if (Configuration.ReadSize < context.MaxReadFrameSize) { Configuration.ReadSize = (int)context.MaxReadFrameSize; } numericUpDownReadSize.Minimum = context.MaxReadFrameSize; } } catch (Exception err) { if (err is oni.ONIException || err is InvalidProgramException || err is TimeoutException) { toolStripSplitButton.Text = err.Message; toolStripSplitButton.ForeColor = Color.Red; } } }