public override int GetHashCode() { int hash = 1; if (EggDropId != 0) { hash ^= EggDropId.GetHashCode(); } if (Rate != 0) { hash ^= Rate.GetHashCode(); } if (U3 != 0L) { hash ^= U3.GetHashCode(); } if (U4 != 0) { hash ^= U4.GetHashCode(); } if (IsRegular != false) { hash ^= IsRegular.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (U1 != 0) { hash ^= U1.GetHashCode(); } if (U2 != 0) { hash ^= U2.GetHashCode(); } if (U3.Length != 0) { hash ^= U3.GetHashCode(); } if (U4.Length != 0) { hash ^= U4.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (U1 != 0L) { hash ^= U1.GetHashCode(); } if (U2 != 0L) { hash ^= U2.GetHashCode(); } if (U3 != 0L) { hash ^= U3.GetHashCode(); } if (U4 != 0L) { hash ^= U4.GetHashCode(); } if (U5 != 0L) { hash ^= U5.GetHashCode(); } if (ItemSetId != 0L) { hash ^= ItemSetId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (ActorId.Length != 0) { hash ^= ActorId.GetHashCode(); } if (U2 != 0) { hash ^= U2.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (U4 != 0) { hash ^= U4.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (U6 != 0) { hash ^= U6.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (PassiveId != 0) { hash ^= PassiveId.GetHashCode(); } if (U2 != 0) { hash ^= U2.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (Type != 0) { hash ^= Type.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private void _read() { _epochTime = m_io.ReadU4le(); _machineId = new U3(m_io, this, m_root); _processId = m_io.ReadU2le(); _counter = new U3(m_io, this, m_root); }
public override int GetHashCode() { int hash = 1; if (FieldTalkVoiceId.Length != 0) { hash ^= FieldTalkVoiceId.GetHashCode(); } if (U2.Length != 0) { hash ^= U2.GetHashCode(); } if (U3.Length != 0) { hash ^= U3.GetHashCode(); } if (U4 != false) { hash ^= U4.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (LoginBonusId.Length != 0) { hash ^= LoginBonusId.GetHashCode(); } if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (ItemSetId != 0UL) { hash ^= ItemSetId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (QuestGroupId != 0L) { hash ^= QuestGroupId.GetHashCode(); } if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (U3.Length != 0) { hash ^= U3.GetHashCode(); } if (ItemSetId != 0L) { hash ^= ItemSetId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (TeamSkillTagId != 0UL) { hash ^= TeamSkillTagId.GetHashCode(); } if (TeamSkillTagType != 0) { hash ^= TeamSkillTagType.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (U4 != 0) { hash ^= U4.GetHashCode(); } if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
private void Initialize() { double value = 0; evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Initializing.")); try { //Open the first found LabJack U3 through USB. u3 = new U3(LJUD.CONNECTION.USB, "0", true); isValid = true; } catch (Exception ex) { evth.LogMessage(this, new LogEventArgs(LogLevel.ERROR, "Initialize exception: " + ex.Message)); return; } value = LJUD.GetDriverVersion(); evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "UD Driver Version: " + value.ToString())); LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref value, 0); evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Hardware Version: " + value)); LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref value, 0); evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Firmware Version: " + value)); evth.LogMessage(this, new LogEventArgs(LogLevel.INFO, "Initialized.")); Execute(LJU3Commands.PIN_CONFIGURATION_RESET, new object[] { }); //pin assignments in factory default condition. Execute(LJU3Commands.PUT_ANALOG_ENABLE_PORT, new object[] { 0, 0, 16 }); //all assignments digital input. }
public override int GetHashCode() { int hash = 1; if (EggDropId != 0) { hash ^= EggDropId.GetHashCode(); } if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (U4 != 0) { hash ^= U4.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (U6 != 0) { hash ^= U6.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (EventBannerId.Length != 0) { hash ^= EventBannerId.GetHashCode(); } if (U2 != 0) { hash ^= U2.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (U5.Length != 0) { hash ^= U5.GetHashCode(); } if (BannerId != 0) { hash ^= BannerId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
int z = 0; //flag private void recountBtn_Click(object sender, EventArgs e) { I1 -= 0.09; I2 -= 0.09; I3 -= 0.09; I4 -= 0.09; I5 -= 0.09; I6 -= 0.09; I1tb.Text = I1.ToString(); I2tb.Text = I2.ToString(); I3tb.Text = I3.ToString(); I4tb.Text = I4.ToString(); I5tb.Text = I5.ToString(); I6tb.Text = I6.ToString(); U2 = I2 * EU * IV / ((IV + I2 + I1) * (I2 + I3 + I4 + I5 - Math.Pow(I2, 2) / (IV + I2 + I1) - Math.Pow((I4 + I5), 2) / (I4 + I5 + I6))); U1 = U2 * I2 / (IV + I2 + I1) + EU * IV / (IV + I2 + I1); U3 = U2 * (I4 + I5) / (I4 + I5 + I6); U1 = Math.Round(U1, 3); U2 = Math.Round(U2, 3); U3 = Math.Round(U3, 3); U1label.Text = "U1 = " + U1.ToString(); U2label.Text = "U2 = " + U2.ToString(); U3label.Text = "U3 = " + U3.ToString(); if (z == 1) { F1 = Math.Round(Math.Pow(U11 - U1, 2), 3); } if (z == 2) { F1 = Math.Round(Math.Pow(U22 - U2, 2), 3); } if (z == 3) { F1 = Math.Round(Math.Pow(U33 - U3, 2), 3); } if (F1 < F) { FTB.Text = F1.ToString(); F = F1; logsRTB.AppendText("Целевая функция уменьшается F=" + F1.ToString() + "\n"); logsRTB.ScrollToCaret(); } else { logsRTB.AppendText("Целевая функция увеличилась F=" + F1.ToString() + "\n"); logsRTB.ScrollToCaret(); recountBtn.Enabled = false; } Fz = 0; calculateGrad(); calculateHessian(); }
public override int GetHashCode() { int hash = 1; if (MoveID != 0) { hash ^= MoveID.GetHashCode(); } if (U2 != 0) { hash ^= U2.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (U4 != 0) { hash ^= U4.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (Type != 0) { hash ^= Type.GetHashCode(); } if (U7 != 0) { hash ^= U7.GetHashCode(); } if (U8 != 0) { hash ^= U8.GetHashCode(); } if (Drain != 0) { hash ^= Drain.GetHashCode(); } if (Power != 0) { hash ^= Power.GetHashCode(); } if (Accuracy != 0) { hash ^= Accuracy.GetHashCode(); } if (U12 != 0) { hash ^= U12.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void performActions() { //long lngGetNextIteration; //LJUD.IO ioType=0, channel=0; //double dblValue=0; //double numI2CBytesToWrite; double numBytes = 0; byte[] array = new byte[256]; try { //Open the LabJack. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); // 1 MHz timer clock base. LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_BASE, (double) LJUD.TIMERCLOCKS.MHZ1_DIV, 0); // Set clock divisor to 1, so timer clock is 1 MHz. LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_DIVISOR, (double) LJUD.TIMERCLOCKS.MHZ1_DIV, 0); // Set timer/counter pin offset to 4. TX and RX appear after any timers and counters on U3 // hardware rev 1.30. We have no timers or counters enabled, so TX=FIO4 and RX=FIO5. LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_COUNTER_PIN_OFFSET, 4, 0); // Set data rate for 9600 bps communication. LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.ASYNCH_BAUDFACTOR, 204, 0); // Enable UART. LJUD.ePut(u3.ljhandle, LJUD.IO.ASYNCH_COMMUNICATION, LJUD.CHANNEL.ASYNCH_ENABLE, 1, 0); // Transmit 2 bytes. numBytes = 3; array[0] = 20; array[1] = 75; LJUD.eGet(u3.ljhandle, LJUD.IO.ASYNCH_COMMUNICATION, LJUD.CHANNEL.ASYNCH_TX, ref numBytes, array); // Read 2 bytes. numBytes = 9999; //Dummy values so we can see them change. array[0] = 111; array[1] = 111; LJUD.eGet(u3.ljhandle, LJUD.IO.ASYNCH_COMMUNICATION, LJUD.CHANNEL.ASYNCH_RX, ref numBytes, array); } catch (LabJackUDException e) { showErrorMessage(e); } //Display the read data. Console.Out.WriteLine("Pre-read buffer size = {0:0}\n\n",numBytes); Console.Out.WriteLine("Read data = {0:0.#}, {1:0.#}\n\n",array[0],array[1]); Console.ReadLine(); // Pause for user }
private void connectToLabjack() { int teller = 0; //Maak verbinding met de Labjack tsslbl_Status.Text = " Verbonden met de Labjack "; try { while (u3 == null && teller++ < 1000000) { u3 = new U3(LJUD.CONNECTION.USB, "0", true); //Probeer direct weer te verbinden } } catch (LabJackUDException e) //Reset en probeer opnieuw { ShowErrorMessage(e); try { resetLabjack(); while (u3 == null && teller++ < 1000000) { u3 = new U3(LJUD.CONNECTION.USB, "0", true); //Probeer direct weer te verbinden } } catch (Exception) { tsslbl_Status.Text = "Geen Labjack aangesloten "; } } if (u3 != null) //test voor labjack aanwezigheid { //Read and display the hardware version of this U3. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.SERIAL_NUMBER, ref dblValue, 0); serienummerToolStripMenuItem1.Text = "Serienummer: " + String.Format("{0:0}", dblValue); //Read and display the hardware version of this U3. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref dblValue, 0); hardwareVersieToolStripMenuItem.Text = "Hardware versie: " + String.Format("{0:0.000}", dblValue); //Read and display the firmware version of this U3. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref dblValue, 0); firmwareVersieToolStripMenuItem.Text = "Firmware versie:" + String.Format("{0:0.000}", dblValue); //Hv or Lv LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.U3HV, ref dblValue, 0); if (dblValue >= 1.0) { tsmi_LabjackHV.Text = "U3-HV (High Voltage, 0-10 V)"; } else { tsmi_LabjackHV.Text = "U3-LV (Low Voltage)"; blLabjackHV = false; } } }
public override int GetHashCode() { int hash = 1; if (MissionId != 0) { hash ^= MissionId.GetHashCode(); } if (MissionGroupId != 0) { hash ^= MissionGroupId.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } hash ^= parameters_.GetHashCode(); hash ^= objectives_.GetHashCode(); if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (U7 != 0) { hash ^= U7.GetHashCode(); } if (U8 != 0) { hash ^= U8.GetHashCode(); } if (U9 != 0) { hash ^= U9.GetHashCode(); } hash ^= itemSetIds_.GetHashCode(); if (Number != 0) { hash ^= Number.GetHashCode(); } if (RequirementId != 0) { hash ^= RequirementId.GetHashCode(); } if (U13.Length != 0) { hash ^= U13.GetHashCode(); } if (U14.Length != 0) { hash ^= U14.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void ToStringTests() { Helper.RunWithMultipleSimulators((qsim) => { var _ = AbstractCallable._; var dump = qsim.Get <ICallable>(typeof(Microsoft.Quantum.Extensions.Diagnostics.DumpMachine <>)); var trace = qsim.Get <IUnitary>(typeof(Circuits.Generics.Trace <>)); var x = qsim.Get <Intrinsic.X>(); var q2 = new FreeQubit(2) as Qubit; var Q = new Q(q2); var Qs = new QArray <Qubit>(q2); var qs = new Qs(Qs); var udtOp = new U3(x); var udtQ = new Q(q2); var t1 = new QTuple <(long, Range, (Qubit, IUnitary))>((1L, new Range(10, -2, 4), (q2, x))); var t4 = new T4((3L, (1.1, false, Result.One))); var t5 = new T5((Pauli.PauliX, Qs, qs, Q)); var d_1 = dump.Partial(_); var d_2 = d_1.Partial(_); var x_1 = x.Partial(new Func <Qubit, Qubit>(q => q)); var x_2 = x_1.Partial(new Func <Qubit, Qubit>(q => q)); var x_3 = x.Partial <OperationPartial <Qubit, Qubit, QVoid> >(_); var t_1 = trace.Adjoint.Partial(_); var t_2 = t_1.Controlled.Partial(_); Assert.Equal("()", QVoid.Instance.ToString()); Assert.Equal("_", _.ToString()); Assert.Equal("U3(X)", udtOp.ToString()); Assert.Equal("q:2", q2.ToString()); Assert.Equal("Q(q:2)", udtQ.ToString()); Assert.Equal("(1, 10..-2..4, (q:2, X))", t1.ToString()); Assert.Equal("T4((3, (1.1, False, One)))", t4.ToString()); Assert.Equal("T5((PauliX, [q:2], Qs([q:2]), Q(q:2)))", t5.ToString()); Assert.Equal("X", x.ToString()); Assert.Equal("(Adjoint X)", x.Adjoint.ToString()); Assert.Equal("(Controlled X)", x.Controlled.ToString()); Assert.Equal("(Adjoint (Controlled X))", x.Controlled.Adjoint.ToString()); Assert.Equal("(Controlled (Adjoint X))", x.Adjoint.Controlled.ToString()); Assert.Equal("X{_}", x_1.ToString()); Assert.Equal("(Adjoint X{_})", x_1.Adjoint.ToString()); Assert.Equal("X{_}{_}", x_2.ToString()); Assert.Equal("X{_}", x_3.ToString()); Assert.Equal("DumpMachine", dump.ToString()); Assert.Equal("DumpMachine{_}", d_1.ToString()); Assert.Equal("DumpMachine{_}{_}", d_2.ToString()); Assert.Equal("Trace", trace.ToString()); Assert.Equal("(Adjoint Trace)", trace.Adjoint.ToString()); Assert.Equal("(Controlled Trace)", trace.Controlled.ToString()); Assert.Equal("(Adjoint (Controlled Trace))", trace.Controlled.Adjoint.ToString()); Assert.Equal("(Adjoint Trace){_}", t_1.ToString()); Assert.Equal("(Adjoint (Controlled (Adjoint Trace){_}){_})", t_2.Adjoint.ToString()); }); }
private void resetLabjack() { tsslbl_Error.Text = ""; if (u3 != null) { LJUD.ResetLabJack(u3.ljhandle); MessageBox.Show("Wacht a.u.b. op het bericht:" + " Verbonden met de Labjack "); Thread.Sleep(5000); u3 = null; btnStartStop.Text = "Start"; } }
public override int GetHashCode() { int hash = 1; if (MissionGroupId != 0) { hash ^= MissionGroupId.GetHashCode(); } if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (U4 != 0) { hash ^= U4.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (U6 != 0) { hash ^= U6.GetHashCode(); } if (ItemSetId != 0L) { hash ^= ItemSetId.GetHashCode(); } if (BannerId != 0) { hash ^= BannerId.GetHashCode(); } if (U9 != 0) { hash ^= U9.GetHashCode(); } if (U10 != 0) { hash ^= U10.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Initialise a gate by the given line code. /// </summary> /// <param name="code"> The line code which represents a gate. </param> /// <returns> /// The gate which is represented by the given line. If the given /// line doesn't represent a valid gate or a gate which is not /// implemented, then is null returned. /// </returns> private static Gate InitialiseGate(string code) { if (!Regex.Match(code, @"^\S+ (q[\D+],)*(q[\D])").Success || Regex.Match(code, @"^qreg\s").Success) { return(null); } string prefix = code.Split()[0].ToUpper(); List <double> numbers = Regex.Split(code, @"[^0-9\.]+").Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToDouble(x)).ToList(); switch (prefix) { case "CX": // CNOT gate return(new CNOT((int)numbers[0], (int)numbers[1])); case "H": // Hadamard gate return(U3.GetHadamardGate((int)numbers[0])); case "U3": case "U": // U3 rotation gate return(new U3((int)numbers[3], numbers[0], numbers[1], numbers[2], GatePart.U3)); case "RX": // Rotation over x axis return(new U3((int)numbers[1], numbers[0], -Math.PI / 2, Math.PI / 2, GatePart.Rx)); case "RY": // Rotation over y axis return(new U3((int)numbers[1], numbers[0], 0, 0, GatePart.Ry)); case "RZ": // Rotation over z axis return(new U3((int)numbers[1], 0, numbers[0], 0, GatePart.Rz)); case "X": // Pauli X gate return(new U3((int)numbers[0], Math.PI, -Math.PI / 2, Math.PI / 2, GatePart.X)); case "Y": // Pauli Y gate return(new U3((int)numbers[0], Math.PI, 0, 0, GatePart.Y)); case "Z": // Pauli Z gate return(new U3((int)numbers[0], 0, Math.PI, 0, GatePart.Z)); case "T": // T gate return(new U3((int)numbers[0], 0, Math.PI / 4, 0, GatePart.T)); case "TDG": // Invers of t gate return(new U3((int)numbers[0], 0, -Math.PI / 4, 0, GatePart.TDG)); } return(null); }
public override int GetHashCode() { int hash = 1; if (ScoutEpId.Length != 0) { hash ^= ScoutEpId.GetHashCode(); } if (ScoutId.Length != 0) { hash ^= ScoutId.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (TextId.Length != 0) { hash ^= TextId.GetHashCode(); } if (GemType != 0) { hash ^= GemType.GetHashCode(); } if (Cost != 0) { hash ^= Cost.GetHashCode(); } if (ScoutQuantity != 0) { hash ^= ScoutQuantity.GetHashCode(); } if (U8 != 0) { hash ^= U8.GetHashCode(); } if (ItemSetId != 0L) { hash ^= ItemSetId.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (ItemId != 0L) { hash ^= ItemId.GetHashCode(); } if (SubCategory != 0L) { hash ^= SubCategory.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (Rarity != 0) { hash ^= Rarity.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (ImageId.Length != 0) { hash ^= ImageId.GetHashCode(); } if (ScheduleId.Length != 0) { hash ^= ScheduleId.GetHashCode(); } if (U8 != 0) { hash ^= U8.GetHashCode(); } if (U9 != 0L) { hash ^= U9.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (TeamSkillEffectId != 0UL) { hash ^= TeamSkillEffectId.GetHashCode(); } if (TeamSkillId != 0) { hash ^= TeamSkillId.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (TeamSkillGrowthId != 0) { hash ^= TeamSkillGrowthId.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (U6 != 0) { hash ^= U6.GetHashCode(); } if (U7 != 0) { hash ^= U7.GetHashCode(); } if (U8 != 0) { hash ^= U8.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void QSharpTypeTests() { Helper.RunWithMultipleSimulators((qsim) => { var _ = AbstractCallable._; var x = qsim.Get <Intrinsic.X>(); var q2 = new FreeQubit(2) as Qubit; var Q = new Q(q2); var Qs = new QArray <Qubit>(q2); var qs = new Qs(Qs); var udtOp = new U3(x); var udtQ = new Q(q2); var t4 = new T4((3L, (1.1, false, Result.One))); var t5 = new T5((Pauli.PauliX, Qs, qs, Q)); var plain = qsim.Get <BPlain1>(); var adj = qsim.Get <BAdj1>(); var ctrl = qsim.Get <BCtrl1>(); var mapper = qsim.Get <Circuits.ClosedType.Map>(); Assert.Equal("()", typeof(QVoid).QSharpType()); Assert.Equal("_", _.GetType().QSharpType()); Assert.Equal("U3", udtOp.GetType().QSharpType()); Assert.Equal("Qubit => () : Adjoint, Controlled", udtOp.Data.GetType().QSharpType()); Assert.Equal("Qubit", q2.GetType().QSharpType()); Assert.Equal("Q", udtQ.GetType().QSharpType()); Assert.Equal("Qubit", udtQ.Data.GetType().QSharpType()); Assert.Equal("T4", t4.GetType().QSharpType()); Assert.Equal("(Int,(Double,Boolean,Result))", t4.Data.GetType().QSharpType()); Assert.Equal("T5", t5.GetType().QSharpType()); Assert.Equal("(Pauli,Qubit[],Qs,Q)", t5.Data.GetType().QSharpType()); Assert.Equal("Qubit => () : Adjoint, Controlled", x.GetType().QSharpType()); Assert.Equal("Qubit => () : Adjoint, Controlled", x.Adjoint.GetType().QSharpType()); Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.GetType().QSharpType()); Assert.Equal("(Qubit[],Qubit) => () : Adjoint, Controlled", x.Controlled.Adjoint.GetType().QSharpType()); Assert.Equal("(Int,Qubit,Callable) => ()", plain.GetType().QSharpType()); Assert.Equal("(Int,(Qubit,Qubit,Qubit[]),Adjointable) => () : Adjoint", adj.GetType().QSharpType()); Assert.Equal("(Int,Qs,Controllable) => () : Controlled", ctrl.GetType().QSharpType()); Assert.Equal("(Callable,Result[]) => String[]", mapper.GetType().QSharpType()); }); }
public override ArrayList GetItemInfo() { ArrayList itemInfo = new ArrayList { new InputText(this, "P1:", P1.ToString(), true, "p1"), new InputText(this, "U1:", U1.ToString(), true, "u1"), new InputText(this, "V1:", V1.ToString(), true, "v1"), new InputText(this, "P2:", P2.ToString(), true, "p2"), new InputText(this, "U2:", U2.ToString(), true, "u2"), new InputText(this, "V2:", V2.ToString(), true, "v2"), new InputText(this, "P3:", P3.ToString(), true, "p3"), new InputText(this, "U3:", U3.ToString(), true, "u3"), new InputText(this, "V3:", V3.ToString(), true, "v3"), new InputText(this, "Material:", Enum.GetName(typeof(P3DMaterial), Material), false, ""), }; return(itemInfo); }
public void outputLow() { try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //First some configuration commands. These will be done with the ePut //function which combines the add/go/get into a single call. //Configure FIO0-FIO3 as analog, all else as digital. That means we //will start from channel 0 and update all 16 flexible bits. We will //pass a value of b0000000000001111 or d15. //LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16); //The following commands will use the add-go-get method to group //multiple requests into a single low-level function. //Set DAC0 to 0 volts. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_DAC, 0, 0, 0, 0); LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_DAC, 1, 5, 0, 0); //Set digital output FIO2 to output-high. //LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 1, 0, 0, 0); LJUD.GoOne(u3.ljhandle); //Set digital output FIO3 to output-low. //LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 1, 0, 0, 0); } catch (LabJackUDException e) { ShowErrorMessage(e); } }
/// <summary> /// Loads / configures the U3 and displays the UD driver version /// </summary> /// <param name="sender">The object that executed this method</param> /// <param name="e">Event parameters</param> private void TimedWindow_Load(object sender, System.EventArgs e) { double dblDriverVersion; // Disable the go button until the device has loaded goStopButton.Enabled = false; // Create the event timer but do not start it updateTimer = new System.Timers.Timer(); updateTimer.Elapsed += new ElapsedEventHandler(TimerEvent); updateTimer.Interval = TIMER_INTERVAL; //Read and display the UD version. dblDriverVersion = LJUD.GetDriverVersion(); versionDisplay.Text = String.Format("{0:0.000}", dblDriverVersion); try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Configure FIO0-FIO3 as analog, all else as digital. That means we //will start from channel 0 and update all 16 flexible bits. We will //pass a value of b0000000000001111 or d15. LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16); } catch (LabJackUDException exc) { ShowErrorMessage(exc); return; } // Re-enable the go button goStopButton.Enabled = true; }
public override int GetHashCode() { int hash = 1; if (QuestGroupId != 0L) { hash ^= QuestGroupId.GetHashCode(); } if (BannerId != 0) { hash ^= BannerId.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (U4.Length != 0) { hash ^= U4.GetHashCode(); } if (U5.Length != 0) { hash ^= U5.GetHashCode(); } if (BgmId.Length != 0) { hash ^= BgmId.GetHashCode(); } if (ItemId != 0L) { hash ^= ItemId.GetHashCode(); } hash ^= missionIds_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (Level != 0) { hash ^= Level.GetHashCode(); } if (U2 != 0) { hash ^= U2.GetHashCode(); } if (U3 != 0) { hash ^= U3.GetHashCode(); } if (U4 != 0) { hash ^= U4.GetHashCode(); } if (U5 != 0) { hash ^= U5.GetHashCode(); } if (U6 != 0) { hash ^= U6.GetHashCode(); } if (U7 != 0) { hash ^= U7.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void performActions() { LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblValue=0; // Variables to satisfy certain method signatures int dummyInt = 0; double dummyDouble = 0; double[] dummyDoubleArray = {0}; try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //First requests to configure the timer and counter. These will be //done with and add/go/get block. //Set the timer/counter pin offset to 4, which will put the first //timer/counter on FIO4. LJUD.AddRequest (u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_COUNTER_PIN_OFFSET, 4, 0, 0); //Use the 48 MHz timer clock base with divider. Since we are using clock with divisor //support, Counter0 is not available. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_BASE, (double) LJUD.TIMERCLOCKS.MHZ48_DIV, 0, 0); //LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_BASE, LJUD.TIMERCLOCKS.MHZ24_DIV, 0, 0); //Use this line instead for hardware rev 1.20. //Set the divisor to 48 so the actual timer clock is 1 MHz. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_DIVISOR, 48, 0, 0); //LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_DIVISOR, 24, 0, 0); //Use this line instead for hardware rev 1.20. //Enable 1 timer. It will use FIO4. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.NUMBER_TIMERS_ENABLED, 1, 0, 0); //Configure Timer0 as 8-bit PWM. Frequency will be 1M/256 = 3906 Hz. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_MODE, 0, (double) LJUD.TIMERMODE.PWM8, 0, 0); //Set the PWM duty cycle to 50%. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_VALUE, 0, 32768, 0, 0); //Enable Counter1. It will use FIO5 since 1 timer is enabled. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_COUNTER_ENABLE, 1, 1, 0, 0); //Execute the requests. LJUD.GoOne (u3.ljhandle); } catch (LabJackUDException e) { showErrorMessage(e); } //Get all the results just to check for errors. try { LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { showErrorMessage(e); } bool finished = false; while(!finished) { try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { // If we get an error, report it. If the error is NO_MORE_DATA_AVAILABLE we are done if(e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE) finished = true; else showErrorMessage(e); } } try { //Wait 1 second. Thread.Sleep(1000); //Request a read from the counter. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_COUNTER, (LJUD.CHANNEL) 1, ref dblValue, dummyDoubleArray); //This should read roughly 4k counts if FIO4 is shorted to FIO5. Console.Out.WriteLine("Counter = {0:0.0}\n",dblValue); //Wait 1 second. Thread.Sleep(1000); //Request a read from the counter. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_COUNTER, (LJUD.CHANNEL) 1, ref dblValue, dummyDoubleArray); //This should read about 3906 counts more than the previous read. Console.Out.WriteLine("Counter = {0:0.0}\n",dblValue); //Reset all pin assignments to factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //The PWM output sets FIO4 to output, so we do a read here to set //it to input. LJUD.eGet (u3.ljhandle, LJUD.IO.GET_DIGITAL_BIT, (LJUD.CHANNEL) 4, ref dblValue, dummyDoubleArray); } catch (LabJackUDException e) { showErrorMessage(e); } Console.ReadLine(); // Pause for user }
public void performActions() { LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblValue=0; double valueAIN = 0; //Analog Voltage Value // Variables to satisfy certain method signatures int dummyInt = 0; double dummyDouble = 0; long time=0, j=0; LJUD.CHANNEL tempChannel = (LJUD.CHANNEL)4; //Channel which the TC/LJTIA is on (FIO4). double tcVolts = 0, cjTempK = 0, pTCTempK = 0; LJUD.THERMOCOUPLETYPE tcType = LJUD.THERMOCOUPLETYPE.K; //Set the temperature sensor to a k type thermocouple //Possible Thermocouple types are: //B = 6001 //E = 6002 //J = 6003 //K = 6004 //N = 6005 //R = 6006 //S = 6007 //T = 6008 //Offset calibration: The nominal voltage offset of the LJTick is //0.4 volts. For improved accuracy, though, you should measure the //overall system offset. We know that if the end of the TC is at the //same temperature as the cold junction, the voltage should be zero. //Put the end of the TC near the LJTIA to make sure they are at the same //temperature, and note the voltage measured by FIO4. This is the actual //offset that can be entered below. double offsetVoltage = 0.4; try { //Open the first found LabJack U3 via USB. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Reset all U3 ports to their default configuration. //This is recommended prior to using the U3 to ensure the U3's ports are //in the proper state. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_BIT, (LJUD.CHANNEL)tempChannel, 1, 0); } catch (LabJackUDException e) { showErrorMessage(e); } Console.Out.WriteLine("Press any key to quit\n"); //Constantly acquire temperature readings until a key is pressed bool keyPressed = false; while(!keyPressed) { ioType = 0; channel = 0; time = 0; tcVolts = 0; cjTempK = 0; pTCTempK = 0; //Add analog input requests. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_AIN, tempChannel, 0, 0, 0); //Add request for internal temperature reading -- Internal temp sensor uses //analog input channel 30. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_AIN, 30, 0, 0, 0); //Execute all requests on the labjack u3.ljhandle. LJUD.GoOne (u3.ljhandle); //Get all the results. The first result should be the voltage reading of the //temperature channel. LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); //Get the rest of the results. There should only be one more on the request //queue. bool finished = false; while(!finished) { if(ioType == LJUD.IO.GET_AIN) { if(channel == tempChannel) valueAIN = dblValue; if(channel == (LJUD.CHANNEL)30) cjTempK = dblValue; } try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { if (e.LJUDError == LJUD.LJUDERROR.NO_DATA_AVAILABLE) finished = true; else if (e.LJUDError > LJUD.LJUDERROR.MIN_GROUP_ERROR) finished = true; else showErrorMessage(e); } } //Display Voltage Reading Console.Out.WriteLine("Analog {0:0}: {1:0.######}\n", (int)tempChannel, valueAIN); //Display the internal temperature sensor reading. This example uses //that value for cold junction compensation. Console.Out.WriteLine("U3 internal sensor: {0:0.0} deg K\n", (double)cjTempK); //To get the thermocouple voltage we subtract the offset from the AIN //voltage and divide by the LJTIA gain. tcVolts = (valueAIN - offsetVoltage)/51; //Convert TC voltage to temperature. LJUD.TCVoltsToTemp(tcType, tcVolts, cjTempK, ref pTCTempK); //Display Temperature Console.Out.WriteLine("Thermocouple sensor: {0:0.0} deg K\n\n", pTCTempK); Thread.Sleep(1500); // Short pause keyPressed = Win32Interop._kbhit() != 0; // If a key was hit break out of the loop } }
public void performActions() { LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblVal=0; double ValueDIPort=0; int intVal=0; double val=0; double[] ValueAIN = new double[16]; long time=0; long numIterations = 1; int numChannels = 16; //Number of AIN channels, 0-16. long quickSample = 0; //Set to TRUE for quick AIN sampling. See section 2.6 / 3.1 of the User's Guide long longSettling = 1; //Set to TRUE for extra AIN settling time. try { //Open the first found LabJack. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Configure quickSample. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.AIN_RESOLUTION, quickSample, 0); //Configure longSettling. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.AIN_SETTLING_TIME, longSettling, 0); //Configure the necessary lines as analog. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, Math.Pow(2,numChannels)-1, numChannels); //Now an Add/Go/Get block to configure the timers and counters. These //are configured on EIO0-EIO3, so if more than 8 analog inputs are //enabled then the analog inputs use these lines. if(numChannels <= 8) { //Set the timer/counter pin offset to 8, which will put the first //timer/counter on EIO0. LJUD.AddRequest (u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_COUNTER_PIN_OFFSET, 8, 0, 0); //Use the default clock source. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_BASE, (double) LJUD.TIMERCLOCKS.MHZ48, 0, 0); //Enable 2 timers. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.NUMBER_TIMERS_ENABLED, 2, 0, 0); //Configure Timer0 as 8-bit PWM. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_MODE, 0, (double) LJUD.TIMERMODE.PWM8, 0, 0); //Set the PWM duty cycle to 50%. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_VALUE, 0, 32768, 0, 0); //Configure Timer1 as 8-bit PWM. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_MODE, 1, (double) LJUD.TIMERMODE.PWM8, 0, 0); //Set the PWM duty cycle to 50%. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_VALUE, 1, 32768, 0, 0); //Enable Counter0. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_COUNTER_ENABLE, 0, 1, 0, 0); LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_COUNTER_ENABLE, 1, 1, 0, 0); //Execute the requests. LJUD.GoOne (u3.ljhandle); } //Now add requests that will be processed every iteration of the loop. //Add analog input requests. for(int j=0; j<numChannels; j++) { LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_AIN, j, 0, 0, 0); } //Set DAC0 to 2.5 volts. LJUD.AddRequest (u3.ljhandle, LJUD.IO.PUT_DAC, 0, 2.5, 0, 0); //Read CIO digital lines. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_DIGITAL_PORT, 16, 0, 4, 0); //Only do the timer/counter stuff if there are less than 8 analog inputs. if(numChannels <= 8) { LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_COUNTER, 0, 0, 0, 0); LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_COUNTER, 1, 0, 0, 0); LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_TIMER, 0, 0, 0, 0); LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_TIMER, 1, 0, 0, 0); //Set the PWM duty cycle to 50%. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_VALUE, 0, 32768, 0, 0); //Set the PWM duty cycle to 50%. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_VALUE, 1, 32768, 0, 0); } time = Environment.TickCount; } catch (LabJackUDException e) { showErrorMessage(e); } for(int i=0;i<numIterations;i++) { try { //Execute the requests. LJUD.GoOne(u3.ljhandle); //Get all the results. The input measurement results are stored. All other //results are for configuration or output requests so we are just checking //whether there was an error. LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref val, ref intVal, ref dblVal); } catch (LabJackUDException e) { showErrorMessage(e); } // Get results until there is no more data available bool isFinished = false; while(!isFinished) { switch(ioType) { case LJUD.IO.GET_AIN: ValueAIN[(int)channel]=val; break; case LJUD.IO.GET_DIGITAL_PORT: ValueDIPort=val; break; } try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref val, ref intVal, ref dblVal); } catch (LabJackUDException e) { // If we get an error, report it. If there is no more data available we are done if(e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE) isFinished = true; else showErrorMessage(e); } } } time = Environment.TickCount - time; Console.Out.WriteLine("Milleseconds per iteration = {0:0.000}\n", (double)time / (double)numIterations); Console.Out.WriteLine("\nDigital Input = {0:0.###}\n",ValueDIPort); Console.Out.WriteLine("\nAIN readings from last iteration:\n"); for(int j=0; j<numChannels; j++) { Console.Out.WriteLine("{0:0.000}\n", ValueAIN[j]); } Console.ReadLine(); // Pause for user }
public void performActions() { LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblValue=0; double dummyDouble=0; int dummyInt=0; double numI2CBytesToWrite; double numI2CBytesToRead; byte[] writeArray = new byte[128]; byte[] readArray = new byte[128]; long i=0; long serialNumber=0; double slopeDACA=0, offsetDACA=0, slopeDACB=0, offsetDACB=0; double writeACKS=0, expectedACKS=0; byte[] bytes; //Open the LabJack. try { device = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB } catch (LabJackUDException e) { showErrorMessage(e); } //Configure the I2C communication. //The address of the EEPROM on the LJTick-DAC is 0xA0. LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_ADDRESS_BYTE,160,0,0); //SCL is FIO4 LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_SCL_PIN_NUM,4,0,0); //SDA is FIO5 LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_SDA_PIN_NUM,5,0,0); //See description of low-level I2C function. LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_OPTIONS,0,0,0); //See description of low-level I2C function. 0 is max speed of about 130 kHz. LJUD.AddRequest(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_SPEED_ADJUST,0,0,0); //Execute the requests on a single LabJack. LJUD.GoOne(device.ljhandle); //Get all the results just to check for errors. LJUD.GetFirstResult(device.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); bool finished = false; while (!finished) { try{ LJUD.GetNextResult(device.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { if (e.LJUDError == LJUD.LJUDERROR.NO_MORE_DATA_AVAILABLE) finished = true; else showErrorMessage(e); } } //Initial read of EEPROM bytes 0-3 in the user memory area. //We need a single I2C transmission that writes the address and then reads //the data. That is, there needs to be an ack after writing the address, //not a stop condition. To accomplish this, we use Add/Go/Get to combine //the write and read into a single low-level call. numI2CBytesToWrite = 1; writeArray[0] = 0; //Memory address. User area is 0-63. LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, numI2CBytesToWrite, writeArray, 0); LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, 0, 0, 0); numI2CBytesToRead = 4; LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, numI2CBytesToRead, readArray, 0); //Execute the requests. LJUD.GoOne(device.ljhandle); //Get the result of the write just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, ref dummyDouble); //Get the write ACKs and compare to the expected value. We expect bit 0 to be //the ACK of the last data byte progressing up to the ACK of the address //byte (data bytes only for Control firmware 1.43 and less). So if n is the //number of data bytes, the ACKs value should be (2^(n+1))-1. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS); expectedACKS = Math.Pow(2,numI2CBytesToWrite+1) - 1; if(writeACKS != expectedACKS) Console.Out.WriteLine("Expected ACKs = {0:0}, Received ACKs = %0.f\n",expectedACKS,writeACKS); //When the GoOne processed the read request, the read data was put into the readArray buffer that //we passed, so this GetResult is also just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, ref dummyDouble); //Display the first 4 elements. Console.Out.WriteLine("Read User Mem [0-3] = {0:0.#}, {1:0.#}, {2:0.#}, {3:0.#}\n",readArray[0],readArray[1],readArray[2],readArray[3]); //Write EEPROM bytes 0-3 in the user memory area, using the page write technique. Note //that page writes are limited to 16 bytes max, and must be aligned with the 16-byte //page intervals. For instance, if you start writing at address 14, you can only write //two bytes because byte 16 is the start of a new page. numI2CBytesToWrite = 5; writeArray[0] = 0; //Memory address. User area is 0-63. //Create 4 new pseudo-random numbers to write. Random rand = new Random((int)DateTime.Now.Ticks); for(i=1;i<5;i++) { writeArray[i] = (byte)(rand.NextDouble()*255); } LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, numI2CBytesToWrite, writeArray, 0); LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, 0, 0, 0); //Execute the requests. LJUD.GoOne(device.ljhandle); //Get the result of the write just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, ref dummyDouble); //Get the write ACKs and compare to the expected value. We expect bit 0 to be //the ACK of the last data byte progressing up to the ACK of the address //byte (data bytes only for Control firmware 1.43 and less). So if n is the //number of data bytes, the ACKs value should be (2^(n+1))-1. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS); expectedACKS = Math.Pow(2,numI2CBytesToWrite+1) - 1; if(writeACKS != expectedACKS) Console.Out.WriteLine("Expected ACKs = {0:0}, Received ACKs = %0.f\n",expectedACKS,writeACKS); //Delay to allow the EEPROM to complete the write cycle. Datasheet says 1.5 ms max. System.Threading.Thread.Sleep(2); Console.Out.WriteLine("Write User Mem [0-3] = {0:0.#}, {1:0.#}, {2:0.#}, {3:0.#}\n",writeArray[1],writeArray[2],writeArray[3],writeArray[4]); //Final read of EEPROM bytes 0-3 in the user memory area. //We need a single I2C transmission that writes the address and then reads //the data. That is, there needs to be an ack after writing the address, //not a stop condition. To accomplish this, we use Add/Go/Get to combine //the write and read into a single low-level call. numI2CBytesToWrite = 1; writeArray[0] = 0; //Memory address. User area is 0-63. LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, numI2CBytesToWrite, writeArray, 0); LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, 0, 0, 0); numI2CBytesToRead = 4; LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, numI2CBytesToRead, readArray, 0); //Execute the requests. LJUD.GoOne(device.ljhandle); //Get the result of the write just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, ref dummyDouble); //Get the write ACKs and compare to the expected value. We expect bit 0 to be //the ACK of the last data byte progressing up to the ACK of the address //byte (data bytes only for Control firmware 1.43 and less). So if n is the //number of data bytes, the ACKs value should be (2^(n+1))-1. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS); expectedACKS = Math.Pow(2,numI2CBytesToWrite+1) - 1; if(writeACKS != expectedACKS) Console.Out.WriteLine("Expected ACKs = {0:0}, Received ACKs = %0.f\n",expectedACKS,writeACKS); //When the GoOne processed the read request, the read data was put into the readArray buffer that //we passed, so this GetResult is also just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, ref dummyDouble); //Display the first 4 elements. Console.Out.WriteLine("Read User Mem [0-3] = {0:0.#}, {1:0.#}, {2:0.#}, {3:0.#}\n\n",readArray[0],readArray[1],readArray[2],readArray[3]); //Read cal constants and serial number. //We need a single I2C transmission that writes the address and then reads //the data. That is, there needs to be an ack after writing the address, //not a stop condition. To accomplish this, we use Add/Go/Get to combine //the write and read into a single low-level call. // //64-71 DACA Slope //72-79 DACA Offset //80-87 DACB Slope //88-95 DACB Offset //96-99 Serial Number // numI2CBytesToWrite = 1; writeArray[0] = 64; //Memory address. Cal constants start at 64. LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, numI2CBytesToWrite, writeArray, 0); LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, 0, 0, 0); numI2CBytesToRead = 36; LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, numI2CBytesToRead, readArray, 0); //Execute the requests. LJUD.GoOne(device.ljhandle); //Get the result of the write just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, ref dummyDouble); //Get the write ACKs and compare to the expected value. We expect bit 0 to be //the ACK of the last data byte progressing up to the ACK of the address //byte (data bytes only for Control firmware 1.43 and less). So if n is the //number of data bytes, the ACKs value should be (2^(n+1))-1. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS); expectedACKS = Math.Pow(2,numI2CBytesToWrite+1) - 1; if(writeACKS != expectedACKS) Console.Out.WriteLine("Expected ACKs = {0:0}, Received ACKs = %0.f\n",expectedACKS,writeACKS); //When the GoOne processed the read request, the read data was put into the readArray buffer that //we passed, so this GetResult is also just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_READ, ref dummyDouble); //Convert fixed point values to floating point doubles. //double[] readArray; //readArray = (double[])(readArray); slopeDACA = BitConverter.ToInt64(readArray, 0)/(double)4294967296; offsetDACA = BitConverter.ToInt64(readArray, 8)/(double)4294967296; slopeDACB = BitConverter.ToInt64(readArray, 16)/(double)4294967296; offsetDACB = BitConverter.ToInt64(readArray, 24)/(double)4294967296; Console.Out.WriteLine("DACA Slope = {0:0.0} bits/volt\n",slopeDACA); Console.Out.WriteLine("DACA Offset = {0:0.0} bits\n",offsetDACA); Console.Out.WriteLine("DACB Slope = {0:0.0} bits/volt\n",slopeDACB); Console.Out.WriteLine("DACB Offset = {0:0.0} bits\n",offsetDACB); //Convert serial number bytes to long. serialNumber = (int)readArray[32] + ((int) readArray[33] << 8) + ((int) readArray[34] << 16) + ((int) readArray[35] << 24); Console.Out.WriteLine("Serial Number = {0:0.#}\n\n",serialNumber); //Update both DAC outputs. //Set the I2C address in the UD driver so that we not talk to the DAC chip. //The address of the DAC chip on the LJTick-DAC is 0x24. LJUD.ePut(device.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.I2C_ADDRESS_BYTE,36,0); ///Set DACA to 2.4 volts. numI2CBytesToWrite = 3; writeArray[0] = 48; //Write and update DACA. bytes = BitConverter.GetBytes((long)((2.4*slopeDACB)+offsetDACB)/256); writeArray[1] = bytes[0]; //Upper byte of binary DAC value. writeArray[2] = bytes[1]; //Lower byte of binary DAC value. LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, numI2CBytesToWrite, writeArray, 0); LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, 0, 0, 0); //Execute the requests. LJUD.GoOne(device.ljhandle); //Get the result of the write just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, ref dummyDouble); //Get the write ACKs and compare to the expected value. We expect bit 0 to be //the ACK of the last data byte progressing up to the ACK of the address //byte (data bytes only for Control firmware 1.43 and less). So if n is the //number of data bytes, the ACKs value should be (2^(n+1))-1. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS); expectedACKS = Math.Pow(2,numI2CBytesToWrite+1) - 1; if(writeACKS != expectedACKS) Console.Out.WriteLine("Expected ACKs = {0:0}, Received ACKs = %0.f\n",expectedACKS,writeACKS); Console.Out.WriteLine("DACA set to 2.4 volts\n\n"); //Set DACB to 1.5 volts. numI2CBytesToWrite = 3; writeArray[0] = 49; //Write and update DACB. bytes = BitConverter.GetBytes((long)((1.5*slopeDACB)+offsetDACB)/256); writeArray[1] = bytes[0]; //Upper byte of binary DAC value. writeArray[2] = bytes[1]; //Lower byte of binary DAC value. LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, numI2CBytesToWrite, writeArray, 0); LJUD.AddRequest(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, 0, 0, 0); //Execute the requests. LJUD.GoOne(device.ljhandle); //Get the result of the write just to check for an error. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_WRITE, ref dummyDouble); //Get the write ACKs and compare to the expected value. We expect bit 0 to be //the ACK of the last data byte progressing up to the ACK of the address //byte (data bytes only for Control firmware 1.43 and less). So if n is the //number of data bytes, the ACKs value should be (2^(n+1))-1. LJUD.GetResult(device.ljhandle, LJUD.IO.I2C_COMMUNICATION, LJUD.CHANNEL.I2C_GET_ACKS, ref writeACKS); expectedACKS = Math.Pow(2,numI2CBytesToWrite+1) - 1; if(writeACKS != expectedACKS) Console.Out.WriteLine("Expected ACKs = {0:0}, Received ACKs = %0.f\n",expectedACKS,writeACKS); Console.Out.WriteLine("DACB set to 1.5 volts\n"); Console.ReadLine(); // Pause for user return; }
/// <summary> /// Configure and start the stream on the LabJack /// </summary> /// <returns>True if successful and false otherwise</returns> private bool StartStreaming() { //Read and display the UD version. dblValue = LJUD.GetDriverVersion(); versionDisplay.Text = String.Format("{0:0.000}",dblValue); try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Read and display the hardware version of this U3. LJUD.eGet (u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref dblValue, 0); hardwareDisplay.Text = String.Format("{0:0.000}",dblValue); //Read and display the firmware version of this U3. LJUD.eGet (u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref dblValue, 0); firmwareDisplay.Text = String.Format("{0:0.000}",dblValue); //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Configure FIO0 and FIO1 as analog, all else as digital. That means we //will start from channel 0 and update all 16 flexible bits. We will //pass a value of b0000000000000011 or d3. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 3, 16); //Configure the stream: //Set the scan rate. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_SCAN_FREQUENCY, scanRate, 0, 0); //Give the driver a 5 second buffer (scanRate * 2 channels * 5 seconds). LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_BUFFER_SIZE, scanRate*2*5, 0, 0); //Configure reads to retrieve whatever data is available without waiting (wait mode LJUD.STREAMWAITMODES.NONE). //See comments below to change this program to use LJUD.STREAMWAITMODES.SLEEP mode. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_WAIT_MODE, (double) LJUD.STREAMWAITMODES.NONE, 0, 0); //Define the scan list as AIN0 then AIN1. LJUD.AddRequest(u3.ljhandle, LJUD.IO.CLEAR_STREAM_CHANNELS, 0, 0, 0, 0); LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 0, 0, 0, 0); LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL_DIFF, 1, 0, 32, 0); //Execute the list of requests. LJUD.GoOne(u3.ljhandle); } catch (LabJackUDException e) { ShowErrorMessage(e); return false; } //Get all the results just to check for errors. try {LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);} catch (LabJackUDException e) { ShowErrorMessage(e); } bool finished = false; while(!finished) { try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { // If we get an error, report it. If the error is NO_MORE_DATA_AVAILABLE we are done if(e.LJUDError == U3.LJUDERROR.NO_MORE_DATA_AVAILABLE) finished = true; else ShowErrorMessage(e); } } //Start the stream. try { LJUD.eGet(u3.ljhandle, LJUD.IO.START_STREAM, 0, ref dblValue, 0); } catch (LabJackUDException e) { ShowErrorMessage(e); return false; } //The actual scan rate is dependent on how the desired scan rate divides into //the LabJack clock. The actual scan rate is returned in the value parameter //from the start stream command. scanDisplay.Text = String.Format("{0:0.000}",dblValue); sampleDisplay.Text = String.Format("{0:0.000}",2*dblValue); // # channels * scan rate // The stream started successfully return true; }
public void performActions() { LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblValue=0; double numSPIBytesToTransfer; byte[] dataArray = new byte[50]; // Variables to satsify certain method signatures int dummyInt = 0; double dummyDouble = 0; try { //Open the LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //First, configure the SPI communication. //Enable automatic chip-select control. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_AUTO_CS,1,0,0); //Do not disable automatic digital i/o direction configuration. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_DISABLE_DIR_CONFIG,0,0,0); //Mode A: CPHA=1, CPOL=1. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_MODE,0,0,0); //125kHz clock. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_CLOCK_FACTOR,0,0,0); //MOSI is FIO6 LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_MOSI_PIN_NUM,6,0,0); //MISO is FIO7 LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_MISO_PIN_NUM,7,0,0); //CLK is FIO4 LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_CLK_PIN_NUM,4,0,0); //CS is FIO5 LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SPI_CS_PIN_NUM,5,0,0); //Execute the requests on a single LabJack. The driver will use a //single low-level TimerCounter command to handle all the requests above. LJUD.GoOne(u3.ljhandle); } catch (LabJackUDException e) { showErrorMessage(e); } //Get all the results just to check for errors. try { LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);} catch (LabJackUDException e) { showErrorMessage(e); } bool finished = false; while(!finished) { try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { // If we get an error, report it. If the error is NO_MORE_DATA_AVAILABLE we are done if(e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE) finished = true; else showErrorMessage(e); } } //This example transfers 4 test bytes. numSPIBytesToTransfer = 4; dataArray[0] = 170; dataArray[1] = 240; dataArray[2] = 170; dataArray[3] = 240; //Transfer the data. The write and read is done at the same time. try{ LJUD.eGet(u3.ljhandle, LJUD.IO.SPI_COMMUNICATION, 0, ref numSPIBytesToTransfer, dataArray); } catch (LabJackUDException e) { showErrorMessage(e); } //Display the read data. Console.Out.WriteLine("dataArray[0] = {0:0.#}\n",dataArray[0]); Console.Out.WriteLine("dataArray[1] = {0:0.#}\n",dataArray[1]); Console.Out.WriteLine("dataArray[2] = {0:0.#}\n",dataArray[2]); Console.Out.WriteLine("dataArray[3] = {0:0.#}\n",dataArray[3]); Console.ReadLine(); // Pause for user }
public void performActions() { double dblDriverVersion; LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblValue=0; double Value0=9999,Value1=9999,Value2=9999; double ValueDIBit=9999,ValueDIPort=9999,ValueCounter=9999; // Variables to satisfy certain method signatures int dummyInt = 0; double dummyDouble = 0; //Read and display the UD version. dblDriverVersion = LJUD.GetDriverVersion(); Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n",dblDriverVersion); try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //First some configuration commands. These will be done with the ePut //function which combines the add/go/get into a single call. //Configure FIO0-FIO3 as analog, all else as digital. That means we //will start from channel 0 and update all 16 flexible bits. We will //pass a value of b0000000000001111 or d15. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16); //Set the timer/counter pin offset to 7, which will put the first //timer/counter on FIO7. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_COUNTER_PIN_OFFSET, 7, 0); //Enable Counter1 (FIO7). LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_COUNTER_ENABLE, (LJUD.CHANNEL)1, 1, 0); //The following commands will use the add-go-get method to group //multiple requests into a single low-level function. //Request a single-ended reading from AIN0. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_AIN, 0, 0, 0, 0); //Request a single-ended reading from AIN1. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_AIN, 1, 0, 0, 0); //Request a reading from AIN2 using the Special range. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_AIN_DIFF, 2, 0, 32, 0); //Set DAC0 to 3.5 volts. LJUD.AddRequest (u3.ljhandle, LJUD.IO.PUT_DAC, 0, 3.5, 0, 0); //Set digital output FIO4 to output-high. LJUD.AddRequest (u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, 4, 1, 0, 0); //Read digital input FIO5. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_DIGITAL_BIT, 5, 0, 0, 0); //Read digital inputs FIO5 through FIO6. LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_DIGITAL_PORT, 5, 0, 2, 0); //Request the value of Counter1 (FIO7). LJUD.AddRequest (u3.ljhandle, LJUD.IO.GET_COUNTER, 1, 0, 0, 0); } catch (LabJackUDException e) { ShowErrorMessage(e); } bool requestedExit = false; while (!requestedExit) { try { //Execute the requests. LJUD.GoOne (u3.ljhandle); //Get all the results. The input measurement results are stored. All other //results are for configuration or output requests so we are just checking //whether there was an error. LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { ShowErrorMessage(e); } bool finished = false; while(!finished) { switch(ioType) { case LJUD.IO.GET_AIN : switch((int)channel) { case 0: Value0=dblValue; break; case 1: Value1=dblValue; break; } break; case LJUD.IO.GET_AIN_DIFF : Value2=dblValue; break; case LJUD.IO.GET_DIGITAL_BIT : ValueDIBit=dblValue; break; case LJUD.IO.GET_DIGITAL_PORT : ValueDIPort=dblValue; break; case LJUD.IO.GET_COUNTER : ValueCounter=dblValue; break; } try {LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);} catch (LabJackUDException e) { // If we get an error, report it. If the error is NO_MORE_DATA_AVAILABLE we are done if(e.LJUDError == U3.LJUDERROR.NO_MORE_DATA_AVAILABLE) finished = true; else ShowErrorMessage(e); } } Console.Out.WriteLine("AIN0 = {0:0.###}\n",Value0); Console.Out.WriteLine("AIN1 = {0:0.###}\n",Value1); Console.Out.WriteLine("AIN2 = {0:0.###}\n",Value2); Console.Out.WriteLine("FIO5 = {0:0.###}\n",ValueDIBit); Console.Out.WriteLine("FIO5-FIO6 = {0:0.###}\n",ValueDIPort); //Will read 3 (binary 11) if both lines are pulled-high as normal. Console.Out.WriteLine("Counter1 (FIO7) = {0:0.###}\n",ValueCounter); Console.Out.WriteLine("\nPress Enter to go again or (q) to quit\n"); requestedExit = Console.ReadLine().Equals("q"); } }
public void performActions() { double dblValue=0; //Open the first found LabJack U3. try { u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB } catch (LabJackUDException e) { showErrorMessage(e); } try { //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Set the Data line to FIO4, which is the default anyway. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SHT_DATA_CHANNEL, 4, 0); //Set the Clock line to FIO5, which is the default anyway. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.SHT_CLOCK_CHANNEL, 5, 0); //Set FIO6 to output-high to provide power to the EI-1050. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, (LJUD.CHANNEL)6, 1, 0); } catch (LabJackUDException e) { showErrorMessage(e); } /* //Use this code if only a single EI-1050 is connected. // Connections for one probe: // Red (Power) FIO6 // Black (Ground) GND // Green (Data) FIO4 // White (Clock) FIO5 // Brown (Enable) FIO6 try { //Now, an add/go/get block to get the temp & humidity at the same time. //Request a temperature reading from the EI-1050. LJUD.AddRequest (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_TEMP, 0, 0, 0); //Request a humidity reading from the EI-1050. LJUD.AddRequest (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_RH, 0, 0, 0); //Execute the requests. Will take about 0.5 seconds with a USB high-high //or Ethernet connection, and about 1.5 seconds with a normal USB connection. LJUD.GoOne (u3.ljhandle); //Get the temperature reading. LJUD.GetResult (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_TEMP, ref dblValue); Console.Out.WriteLine("Temp Probe A = {0:0.###} deg K\n",dblValue); Console.Out.WriteLine("Temp Probe A = {0:0.###} deg C\n",(dblValue-273.15)); Console.Out.WriteLine("Temp Probe A = {0:0.###} deg F\n",(((dblValue-273.15)*1.8)+32)); //Get the humidity reading. LJUD.GetResult (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_RH, ref dblValue); Console.Out.WriteLine("RH Probe A = {0:0.###} percent\n\n",dblValue); } catch (LabJackUDException e) { showErrorMessage(e); } //End of single probe code. */ ///* //Use this code if two EI-1050 probes are connected. // Connections for both probes: // Red (Power) FIO6 // Black (Ground) GND // Green (Data) FIO4 // White (Clock) FIO5 // // Probe A: // Brown (Enable) FIO7 // // Probe B: // Brown (Enable) DAC0 try { //Set FIO7 to output-low to disable probe A. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, (LJUD.CHANNEL) 7, 0, 0); //Set DAC0 to 0 volts to disable probe B. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_DAC, 0, 0.0, 0); //Set FIO7 to output-high to enable probe A. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, (LJUD.CHANNEL) 7, 1, 0); //Now, an add/go/get block to get the temp & humidity at the same time. //Request a temperature reading from the EI-1050. LJUD.AddRequest (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_TEMP, 0, 0, 0); //Request a humidity reading from the EI-1050. LJUD.AddRequest (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_RH, 0, 0, 0); //Execute the requests. Will take about 0.5 seconds with a USB high-high //or Ethernet connection, and about 1.5 seconds with a normal USB connection. LJUD.GoOne (u3.ljhandle); //Get the temperature reading. LJUD.GetResult (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_TEMP, ref dblValue); Console.Out.WriteLine("Temp Probe A = {0:0.###} deg K\n",dblValue); Console.Out.WriteLine("Temp Probe A = {0:0.###} deg C\n",(dblValue-273.15)); Console.Out.WriteLine("Temp Probe A = {0:0.###} deg F\n",(((dblValue-273.15)*1.8)+32)); //Get the humidity reading. LJUD.GetResult (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_RH, ref dblValue); Console.Out.WriteLine("RH Probe A = {0:0.###} percent\n\n",dblValue); //Set FIO7 to output-low to disable probe A. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_DIGITAL_BIT, (LJUD.CHANNEL) 7, 0, 0); //Set DAC0 to 3.3 volts to enable probe B. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_DAC, 0, 3.3, 0); //Since the DACs on the U3 are slower than the communication speed, //we put a delay here to make sure the DAC has time to rise to 3.3 volts //before communicating with the EI-1050. Thread.Sleep(30); //Wait 30 ms. //Now, an add/go/get block to get the temp & humidity at the same time. //Request a temperature reading from the EI-1050. LJUD.AddRequest (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_TEMP, 0, 0, 0); //Request a humidity reading from the EI-1050. LJUD.AddRequest (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_RH, 0, 0, 0); //Execute the requests. Will take about 0.5 seconds with a USB high-high //or Ethernet connection, and about 1.5 seconds with a normal USB connection. LJUD.GoOne (u3.ljhandle); //Get the temperature reading. LJUD.GetResult (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_TEMP, ref dblValue); Console.Out.WriteLine("Temp Probe B = {0:0.###} deg K\n",dblValue); Console.Out.WriteLine("Temp Probe B = {0:0.###} deg C\n",(dblValue-273.15)); Console.Out.WriteLine("Temp Probe B = {0:0.###} deg F\n",(((dblValue-273.15)*1.8)+32)); //Get the humidity reading. LJUD.GetResult (u3.ljhandle, LJUD.IO.SHT_GET_READING, LJUD.CHANNEL.SHT_RH, ref dblValue); Console.Out.WriteLine("RH Probe B = {0:0.###} percent\n\n",dblValue); //Set DAC0 to 0 volts to disable probe B. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_DAC, 0, 0.0, 0); //If we were going to loop and talk to probe A next, we would //want a delay here to make sure the DAC falls to 0 volts //before enabling probe A. Thread.Sleep(30); //Wait 30 ms. } catch (LabJackUDException e) { showErrorMessage(e); } //End of dual probe code. //*/ Console.ReadLine(); // Pause for user }
public void performActions() { long i=0,k=0; LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblValue=0, dblCommBacklog=0, dblUDBacklog=0; double scanRate = 2000; int delayms = 1000; double numScans = 4000; //2x the expected # of scans (2*scanRate*delayms/1000) double numScansRequested; double[] adblData = new double[8000]; //Max buffer size (#channels*numScansRequested) // Variables to satisfy certain method signatures int dummyInt = 0; double dummyDouble = 0; double[] dummyDoubleArray = {0}; //Read and display the UD version. dblValue = LJUD.GetDriverVersion(); Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n",dblValue); try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //LJUD.ResetLabJack(u3.ljhandle); //Read and display the hardware version of this U3. LJUD.eGet (u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref dblValue, 0); Console.Out.WriteLine("U3 Hardware Version = {0:0.000}\n\n",dblValue); //Read and display the firmware version of this U3. LJUD.eGet (u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref dblValue, 0); Console.Out.WriteLine("U3 Firmware Version = {0:0.000}\n\n",dblValue); //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Configure FIO0 and FIO1 as analog, all else as digital. That means we //will start from channel 0 and update all 16 flexible bits. We will //pass a value of b0000000000000011 or d3. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 3, 16); //Configure the stream: //Set the scan rate. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_SCAN_FREQUENCY, scanRate, 0, 0); //Give the driver a 5 second buffer (scanRate * 2 channels * 5 seconds). LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_BUFFER_SIZE, scanRate*2*5, 0, 0); //Configure reads to retrieve whatever data is available without waiting (wait mode LJUD.STREAMWAITMODES.NONE). //See comments below to change this program to use LJUD.STREAMWAITMODES.SLEEP mode. LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_WAIT_MODE, (double) LJUD.STREAMWAITMODES.NONE, 0, 0); //Define the scan list as AIN0 then AIN1. LJUD.AddRequest(u3.ljhandle, LJUD.IO.CLEAR_STREAM_CHANNELS, 0, 0, 0, 0); LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 0, 0, 0, 0); LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL_DIFF, 1, 0, 32, 0); //Execute the list of requests. LJUD.GoOne(u3.ljhandle); } catch (LabJackUDException e) { showErrorMessage(e); } //Get all the results just to check for errors. try {LJUD.GetFirstResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble);} catch (LabJackUDException e) { showErrorMessage(e); } bool finished = false; while(!finished) { try { LJUD.GetNextResult(u3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { // If we get an error, report it. If the error is NO_MORE_DATA_AVAILABLE we are done if(e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE) finished = true; else showErrorMessage(e); } } //Start the stream. try { LJUD.eGet(u3.ljhandle, LJUD.IO.START_STREAM, 0, ref dblValue, 0); } catch (LabJackUDException e) { showErrorMessage(e); } //The actual scan rate is dependent on how the desired scan rate divides into //the LabJack clock. The actual scan rate is returned in the value parameter //from the start stream command. Console.Out.WriteLine("Actual Scan Rate = {0:0.000}\n",dblValue); Console.Out.WriteLine("Actual Sample Rate = {0:0.000}\n",2*dblValue); // # channels * scan rate //Read data while(Win32Interop._kbhit() == 0) //Loop will run until any key is hit { //Since we are using wait mode LJUD.STREAMWAITMODES.NONE, we will wait a little, then //read however much data is available. Thus this delay will control how //fast the program loops and how much data is read each loop. An //alternative common method is to use wait mode LJUD.STREAMWAITMODES.SLEEP where the //stream read waits for a certain number of scans. In such a case //you would not have a delay here, since the stream read will actually //control how fast the program loops. // //To change this program to use sleep mode, // -change numScans to the actual number of scans desired per read, // -change wait mode addrequest value to LJUD.STREAMWAITMODES.SLEEP, // -comment out the following Thread.Sleep command. Thread.Sleep(delayms); //Remove if using LJUD.STREAMWAITMODES.SLEEP. //init array so we can easily tell if it has changed for(k=0;k<numScans*2;k++) { adblData[k] = 9999.0; } try { //Read the data. We will request twice the number we expect, to //make sure we get everything that is available. //Note that the array we pass must be sized to hold enough SAMPLES, and //the Value we pass specifies the number of SCANS to read. numScansRequested=numScans; LJUD.eGet(u3.ljhandle, LJUD.IO.GET_STREAM_DATA, LJUD.CHANNEL.ALL_CHANNELS, ref numScansRequested, adblData); //The displays the number of scans that were actually read. Console.Out.WriteLine("\nIteration # {0:0.#}\n",i); Console.Out.WriteLine("Number read = {0:0}\n",numScansRequested); //This displays just the first scan. Console.Out.WriteLine("First scan = {0:0.000}, {1:0.000}\n",adblData[0],adblData[1]); //Retrieve the current backlog. The UD driver retrieves stream data from //the U3 in the background, but if the computer is too slow for some reason //the driver might not be able to read the data as fast as the U3 is //acquiring it, and thus there will be data left over in the U3 buffer. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.STREAM_BACKLOG_COMM, ref dblCommBacklog, 0); Console.Out.WriteLine("Comm Backlog = {0:0}\n",dblCommBacklog); LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.STREAM_BACKLOG_UD, ref dblUDBacklog, 0); Console.Out.WriteLine("UD Backlog = {0:0}\n",dblUDBacklog); i++; } catch (LabJackUDException e) { showErrorMessage(e); } } //Stop the stream try{ LJUD.eGet(u3.ljhandle, LJUD.IO.STOP_STREAM, 0, ref dummyDouble, dummyDoubleArray); } catch (LabJackUDException e) { showErrorMessage(e); } Console.Out.WriteLine("\nDone"); Console.ReadLine(); // Pause for user }
/// <summary> /// Loads / configures the U3 and displays the UD driver version /// </summary> /// <param name="sender">The object that executed this method</param> /// <param name="e">Event parameters</param> private void TimedWindow_Load(object sender, System.EventArgs e) { double dblDriverVersion; // Disable the go button until the device has loaded goStopButton.Enabled = false; // Create the event timer but do not start it updateTimer = new System.Timers.Timer(); updateTimer.Elapsed += new ElapsedEventHandler( TimerEvent ); updateTimer.Interval = TIMER_INTERVAL; //Read and display the UD version. dblDriverVersion = LJUD.GetDriverVersion(); versionDisplay.Text = String.Format("{0:0.000}",dblDriverVersion); try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Configure FIO0-FIO3 as analog, all else as digital. That means we //will start from channel 0 and update all 16 flexible bits. We will //pass a value of b0000000000001111 or d15. LJUD.ePut (u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 15, 16); } catch (LabJackUDException exc) { ShowErrorMessage(exc); return; } // Re-enable the go button goStopButton.Enabled = true; }
public void performActions() { double dblValue=0; int intValue=0; int binary; int[] aEnableTimers = new int[2]; int[] aEnableCounters = new int[2]; int tcpInOffset; int timerClockDivisor; LJUD.TIMERCLOCKS timerClockBaseIndex; int[] aTimerModes = new int[2]; double[] adblTimerValues = new double[2]; int[] aReadTimers = new int[2]; int[] aUpdateResetTimers = new int[2]; int[] aReadCounters = new int[2]; int[] aResetCounters = new int[2]; double[] adblCounterValues = {0,0}; double highTime, lowTime, dutyCycle; try { //Open the first found LabJack U3. u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //Take a single-ended measurement from AIN3. binary = 0; LJUD.eAIN( u3.ljhandle, 3, 31, ref dblValue, -1, -1, -1, binary); Console.Out.WriteLine("AIN3 = {0:0.###}\n",dblValue); //Set DAC0 to 3.0 volts. dblValue = 3.0; binary = 0; LJUD.eDAC (u3.ljhandle, 0, dblValue, binary, 0, 0); Console.Out.WriteLine("DAC0 set to {0:0.###} volts\n",dblValue); //Read state of FIO4. LJUD.eDI (u3.ljhandle, 4, ref intValue); Console.Out.WriteLine("FIO4 = {0:0.#}\n",intValue); //Set the state of FIO7. intValue = 1; LJUD.eDO (u3.ljhandle, 7, intValue); Console.Out.WriteLine("FIO7 set to = {0:0.#}\n\n",intValue); //Timers and Counters example. //First, a call to eTCConfig. Fill the arrays with the desired values, then make the call. aEnableTimers[0] = 1; //Enable Timer0 (uses FIO4). aEnableTimers[1] = 1; //Enable Timer1 (uses FIO5). aEnableCounters[0] = 0; //Disable Counter0. aEnableCounters[1] = 1; //Enable Counter1 (uses FIO6). tcpInOffset = 4; //Offset is 4, so timers/counters start at FIO4. timerClockBaseIndex = LJUD.TIMERCLOCKS.MHZ48_DIV; //Base clock is 48 MHz with divisor support, so Counter0 is not available. //timerClockBaseIndex = LJUD.TIMERCLOCKS.MHZ24_DIV; //Use this line instead for hardware rev 1.20. timerClockDivisor = 48; //Thus timer clock is 1 MHz. //timerClockDivisor = 24; //Use this line instead for hardware rev 1.20. aTimerModes[0] = (int) LJUD.TIMERMODE.PWM8; //Timer0 is 8-bit PWM output. Frequency is 1M/256 = 3906 Hz. aTimerModes[1] = (int) LJUD.TIMERMODE.DUTYCYCLE; //Timer1 is duty cyle input. adblTimerValues[0] = 16384; //Set PWM8 duty-cycle to 75%. adblTimerValues[1] = 0; LJUD.eTCConfig(u3.ljhandle, aEnableTimers, aEnableCounters, tcpInOffset, (int) timerClockBaseIndex, timerClockDivisor, aTimerModes, adblTimerValues, 0, 0); Console.Out.WriteLine("Timers and Counters enabled.\n\n"); Thread.Sleep(1000); //Wait 1 second. //Now, a call to eTCValues. aReadTimers[0] = 0; //Don't read Timer0 (output timer). aReadTimers[1] = 1; //Read Timer1; aUpdateResetTimers[0] = 1; //Update Timer0; aUpdateResetTimers[1] = 1; //Reset Timer1; aReadCounters[0] = 0; aReadCounters[1] = 1; //Read Counter1; aResetCounters[0] = 0; aResetCounters[1] = 1; //Reset Counter1. adblTimerValues[0] = 32768; //Change Timer0 duty-cycle to 50%. adblTimerValues[1] = 0; LJUD.eTCValues(u3.ljhandle, aReadTimers, aUpdateResetTimers, aReadCounters, aResetCounters, adblTimerValues, adblCounterValues, 0, 0); Console.Out.WriteLine("Timer1 value = {0:0.000}\n",adblTimerValues[1]); Console.Out.WriteLine("Counter1 value = {0:0.000}\n",adblCounterValues[1]); //Convert Timer1 value to duty-cycle percentage. //High time is LSW highTime = (double)(((ulong)adblTimerValues[1]) % (65536)); //Low time is MSW lowTime = (double)(((ulong)adblTimerValues[1]) / (65536)); //Calculate the duty cycle percentage. dutyCycle = 100*highTime/(highTime+lowTime); Console.Out.WriteLine("\nHigh clicks Timer1 = {0:0.0}\n",highTime); Console.Out.WriteLine("Low clicks Timer1 = {0:0.0}\n",lowTime); Console.Out.WriteLine("Duty cycle Timer1 = {0:0.0}\n",dutyCycle); //Disable all timers and counters. aEnableTimers[0] = 0; aEnableTimers[1] = 0; aEnableCounters[0] = 0; aEnableCounters[1] = 0; LJUD.eTCConfig(u3.ljhandle, aEnableTimers, aEnableCounters, 4, (int)timerClockBaseIndex, timerClockDivisor, aTimerModes, adblTimerValues, 0, 0); } catch (LabJackUDException e) { showErrorMessage(e); } Console.ReadLine(); // Pause for user }
private void connectToLabjack() { int teller = 0; //Maak verbinding met de Labjack tsslbl_Status.Text = " Verbonden met de Labjack "; try { while (u3 == null && teller++ < 1000000) { u3 = new U3(LJUD.CONNECTION.USB, "0", true); //Probeer direct weer te verbinden } } catch (LabJackUDException e) //Reset en probeer opnieuw { ShowErrorMessage(e); try { resetLabjack(); while (u3 == null && teller++ < 1000000) { u3 = new U3(LJUD.CONNECTION.USB, "0", true); //Probeer direct weer te verbinden } } catch (Exception) { tsslbl_Status.Text = "Geen Labjack aangesloten "; } } if (u3 != null) //test voor labjack aanwezigheid { //Read and display the hardware version of this U3. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.SERIAL_NUMBER, ref dblValue, 0); serienummerToolStripMenuItem1.Text = "Serienummer: " + String.Format("{0:0}", dblValue); //Read and display the hardware version of this U3. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.HARDWARE_VERSION, ref dblValue, 0); hardwareVersieToolStripMenuItem.Text = "Hardware versie: " + String.Format("{0:0.000}", dblValue); //Read and display the firmware version of this U3. LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.FIRMWARE_VERSION, ref dblValue, 0); firmwareVersieToolStripMenuItem.Text = "Firmware versie:" + String.Format("{0:0.000}", dblValue); //Hv or Lv LJUD.eGet(u3.ljhandle, LJUD.IO.GET_CONFIG, LJUD.CHANNEL.U3HV, ref dblValue, 0); if (dblValue >= 1.0) tsmi_LabjackHV.Text = "U3-HV (High Voltage, 0-10 V)"; else { tsmi_LabjackHV.Text = "U3-LV (Low Voltage)"; blLabjackHV = false; } } }
private U3 unit2, unit3; // Units with ids 2 and 3 #endregion Fields #region Methods public void performActions() { double dblDriverVersion; LJUD.IO ioType=0; LJUD.CHANNEL channel=0; double dblValue=0; double Value22=9999,Value32=9999,Value42=9999; double Value23=9999,Value33=9999,Value43=9999; // Variables to satisfy certain method signatures int dummyInt = 0; double dummyDouble = 0; //Read and display the UD version. dblDriverVersion = LJUD.GetDriverVersion(); Console.Out.WriteLine("UD Driver Version = {0:0.000}\n\n",dblDriverVersion); //Open the U3 with local ID 2. try { unit2 = new U3(LJUD.CONNECTION.USB, "2", false); // Connection through USB unit3 = new U3(LJUD.CONNECTION.USB, "3", false); // Connection through USB //Start by using the pin_configuration_reset IOType so that all //pin assignments are in the factory default condition. LJUD.ePut (unit2.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); LJUD.ePut (unit3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0); //First a configuration command. These will be done with the ePut //function which combines the add/go/get into a single call. //Configure FIO2-FIO4 as analog, all else as digital, on both devices. //That means we will start from channel 0 and update all 16 flexible bits. //We will pass a value of b0000000000011100 or d28. LJUD.ePut (unit2.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 28, 16); LJUD.ePut (unit3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 28, 16); //The following commands will use the add-go-get method to group //multiple requests into a single low-level function. //Request a single-ended reading from AIN2. LJUD.AddRequest (unit2.ljhandle, LJUD.IO.GET_AIN, 2, 0, 0, 0); LJUD.AddRequest (unit3.ljhandle, LJUD.IO.GET_AIN, 2, 0, 0, 0); //Request a single-ended reading from AIN3. LJUD.AddRequest (unit2.ljhandle, LJUD.IO.GET_AIN, 3, 0, 0, 0); LJUD.AddRequest (unit3.ljhandle, LJUD.IO.GET_AIN, 3, 0, 0, 0); //Request a reading from AIN4 using the Special 0-3.6 range. LJUD.AddRequest (unit2.ljhandle, LJUD.IO.GET_AIN_DIFF, 4, 0, 32, 0); LJUD.AddRequest (unit3.ljhandle, LJUD.IO.GET_AIN_DIFF, 4, 0, 32, 0); } catch (LabJackUDException e) { showErrorMessage(e); } bool isFinished = false; while (!isFinished) { try { //Execute all requests on all open LabJacks. LJUD.Go(); //Get all the results for unit 2. The input measurement results are stored. LJUD.GetFirstResult(unit2.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { showErrorMessage(e); } bool unit2Finished = false; while(!unit2Finished) { switch(ioType) { case LJUD.IO.GET_AIN : switch((int)channel) { case 2: Value22=dblValue; break; case 3: Value32=dblValue; break; } break; case LJUD.IO.GET_AIN_DIFF : Value42=dblValue; break; } try { LJUD.GetNextResult(unit2.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { // If we get an error, report it. If the error is NO_MORE_DATA_AVAILABLE we are done if(e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE) unit2Finished = true; else showErrorMessage(e); } } //Get all the results for unit 3. The input measurement results are stored. try { LJUD.GetFirstResult(unit3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { showErrorMessage(e); } bool unit3Finished = false; while(!unit3Finished) { switch(ioType) { case LJUD.IO.GET_AIN : switch((int)channel) { case 2: Value23=dblValue; break; case 3: Value33=dblValue; break; } break; case LJUD.IO.GET_AIN_DIFF : Value43=dblValue; break; } try { LJUD.GetNextResult(unit3.ljhandle, ref ioType, ref channel, ref dblValue, ref dummyInt, ref dummyDouble); } catch (LabJackUDException e) { // If we get an error, report it. If the error is NO_MORE_DATA_AVAILABLE we are done if(e.LJUDError == UE9.LJUDERROR.NO_MORE_DATA_AVAILABLE) unit3Finished = true; else showErrorMessage(e); } } Console.Out.WriteLine("AIN2 (Unit 2) = {0:0.###}\n",Value22); Console.Out.WriteLine("AIN2 (Unit 3) = {0:0.###}\n",Value23); Console.Out.WriteLine("AIN3 (Unit 2) = {0:0.###}\n",Value32); Console.Out.WriteLine("AIN3 (Unit 3) = {0:0.###}\n",Value33); Console.Out.WriteLine("AIN4 (Unit 2) = {0:0.###}\n",Value42); Console.Out.WriteLine("AIN4 (Unit 3) = {0:0.###}\n",Value43); Console.Out.WriteLine("\nPress Enter to go again or (q) to quit\n"); isFinished = Console.ReadLine() == "q"; // Pause for user } }