private void FillFields(ChannelConfig cc) { _textName.Text = cc.Name; _txtDefaultChannel.Text = cc.DefaultChannel.ToString(); _txtOffset.Text = cc.Offset.ToString(); _cmbOutput.SelectedIndex = 0; _txtPSI.Text = cc.PSI.ToString(); }
public ChannelConfig[] GetChannelConfigs() { List<ChannelConfig> configs = new List<ChannelConfig>(); IDataReader reader = ExecuteQuery("SELECT CC_ID,cc_name,cc_psi,cc_outputvolts,cc_offset,cc_defaultchannel from CHANNEL_CONFIG"); while (reader.Read()) { ChannelConfig cc = new ChannelConfig(); cc.ID = reader.GetInt32(0); cc.Name = reader.GetString(1); cc.PSI = reader.GetInt32(2); int voltRange = reader.GetInt32(3); switch (voltRange) { case 5: cc.VoltRange = OutputVoltRange.ZeroToFiveVolts; break; case 4: cc.VoltRange = OutputVoltRange.PointFiveToFourPointFive; break; default: throw new Exception("Invalid volt range"); } cc.Offset = reader.GetFloat(4); cc.DefaultChannel = reader.GetInt32(5); configs.Add(cc); } return configs.ToArray(); }
public DAQChannel CreateChannelForReading(Reading r,ChannelConfig cc, string details,int number) { SQLiteCommand cmd = _connection.CreateCommand(); cmd.CommandText = Properties.Settings.Default.INSERT_CHANNEL; cmd.Parameters.Add(new SQLiteParameter("@rid",r.ID)); cmd.Parameters.Add(new SQLiteParameter("@details",details)); cmd.Parameters.Add(new SQLiteParameter("@number",number)); cmd.Parameters.Add(new SQLiteParameter("@channelconfig", cc.ID)); int cid = Convert.ToInt32(cmd.ExecuteScalar()); DAQChannel ch = new DAQChannel(); ch.ID = cid; ch.Details = details; ch.ParentReading = r; ch.Channel = number; ch.Config = cc; r.ChannelList.Add(ch); return ch; }
public ChannelConfig CreateChannelConfig(string name, int psi, OutputVoltRange range, float offset, int defaultChannel) { int outputRange = 0; switch (range) { case OutputVoltRange.ZeroToFiveVolts: outputRange = 5; break; case OutputVoltRange.PointFiveToFourPointFive: outputRange = 4; break; default: throw new Exception("Invalid output range"); } SQLiteCommand cmd = _connection.CreateCommand(); cmd.CommandText = Properties.Settings.Default.INSERT_CHANNEL_CONFIG; cmd.Parameters.Add(new SQLiteParameter("@name", name)); cmd.Parameters.Add(new SQLiteParameter("@psi", psi)); cmd.Parameters.Add(new SQLiteParameter("@outputvolts", outputRange)); cmd.Parameters.Add(new SQLiteParameter("@offset", offset)); cmd.Parameters.Add(new SQLiteParameter("@defaultchannel",defaultChannel)); int ccid = Convert.ToInt32(cmd.ExecuteScalar()); ChannelConfig cc = new ChannelConfig(); cc.ID = ccid; cc.Name = name; cc.Offset = offset; cc.PSI = psi; cc.VoltRange = range; cc.DefaultChannel = defaultChannel; return cc; }
/// <summary> /// Quick peek at the volts /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void peekPress_Tick(object sender, EventArgs e) { try { if (_peekBoard == null) { _peekBoard = new MccDaq.MccBoard(); } short dValue; ErrorInfo ei = _peekBoard.AIn(0, MccDaq.Range.Bip5Volts, out dValue); float engVal; MccDaq.ErrorInfo info = _peekBoard.ToEngUnits(MccDaq.Range.Bip5Volts, dValue, out engVal); if (engVal < 0) { engVal = -1; } else { if (_defaultChannel == null) { foreach (ChannelConfig dq in _db.GetChannelConfigs()) { if (dq.DefaultChannel == 0) { _defaultChannel = dq; break; } } } if (_defaultChannel != null) { labelPSI.Text = Convert.ToInt32(_defaultChannel.GetPsi(engVal)).ToString() + " psi"; } else { labelPSI.Text = engVal.ToString() + " psi"; } } } catch (Exception ex) { labelPSI.Text = "Error occurred " + ex.ToString(); } }
public void TestMath() { ChannelConfig cc = new ChannelConfig(); cc.PSI = 1000; cc.VoltRange = OutputVoltRange.ZeroToFiveVolts; cc.Offset = 0.05F; Assert.IsTrue(190.0 == cc.GetPsi(1)); }