//Breakout breakout = new Breakout(9); void timer_Tick(GT.Timer timer) { Debug.Print("--------"); AnalogInput analogInput = breakout.CreateAnalogInput(GT.Socket.Pin.Three); Debug.Print("Voltage: " + analogInput.ReadVoltage().ToString()); }
// This method is run when the mainboard is powered up or reset. void ProgramStarted() { /******************************************************************************************* * Modules added in the Program.gadgeteer designer view are used by typing * their name followed by a period, e.g. button. or camera. * * Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.: * button.ButtonPressed +=<tab><tab> * * If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.: * GT.Timer timer = new GT.Timer(1000); // every second (1000ms) * timer.Tick +=<tab><tab> * timer.Start(); *******************************************************************************************/ // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging. Debug.Print("Program Started"); Breakout breakout = new Breakout(9); AnalogInput analogInput = breakout.CreateAnalogInput(GT.Socket.Pin.Three); while (true) { Debug.Print("Voltage: " + analogInput.ReadVoltage().ToString()); Thread.Sleep(500); } /* * GT.Timer timer = new GT.Timer(500); * timer.Tick += timer_Tick; * timer.Start(); */ }
/// <summary> /// 返回所有通道的数据,格式处理在这里设置 /// </summary> /// <returns></returns> private Dictionary <int, string> GetAllChannelValue() { //string[] values = new string[channelTotal]; string value = ""; int startIndex = 1; int[] data; float[] fValue = new float[channelTotal]; if (adamModbus.Modbus().ReadInputRegs(startIndex, channelTotal, out data)) { for (int i = 0; i < channelTotal; i++) { fValue[i] = AnalogInput.GetScaledValue(adamType, channelRange[i], (ushort)data[i]); if (channelEnabled[i]) { string valueFormat = AnalogInput.GetFloatFormat(adamType, channelRange[i]); //values[i] = fValue[i].ToString(valueFormat) + " " + AnalogInput.GetUnitName(adamType, channelRange[i]); value = fValue[i].ToString(valueFormat); dataDic[i] = value; } } } else { throw new Adam6217OperationException("ip为:" + slaveIp + ",研华adam6217模块读取输入通道数据失败。"); } return(dataDic); }
private void RefreshChannelValueUshortFormat(object source, ElapsedEventArgs e) { int iStart = 1, iAiStatusStart = 101; int iIdx; int[] iData, iAiStatus; float[] fValue = new float[m_iAiTotal]; if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData)) { for (iIdx = 0; iIdx < m_iAiTotal; iIdx++) { fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], (ushort)iData[iIdx]); } if (adamModbus.Modbus().ReadInputRegs(iAiStatusStart, (m_iAiTotal * 2), out iAiStatus)) { // store data to db AddToDb(DateTime.Now, fValue[0], 0); AddToDb(DateTime.Now, fValue[1], 1); AddToDb(DateTime.Now, fValue[2], 2); AddToDb(DateTime.Now, fValue[3], 3); } } }
public void info() { #region 定义模块参数 // m_bStart = false; // the action stops at the beginning m_szIP1 = "10.0.0.2"; // modbus slave IP address m_szIP2 = "10.0.0.3"; // modbus slave IP address m_szIP3 = "10.0.0.4"; // modbus slave IP address m_szIP4 = "10.0.0.5"; // modbus slave IP address m_szIP5 = "10.0.0.6"; // modbus slave IP address m_szIP6 = "10.0.0.7"; // modbus slave IP address m_szIP7 = "10.0.0.8"; // modbus slave IP address m_szIP8 = "10.0.0.9"; // modbus slave IP address m_szIP9 = "10.0.0.10"; // modbus slave IP address m_iPort = 502; // modbus TCP port is 502 adamModbus1 = new AdamSocket(); adamModbus1.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus1.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus2 = new AdamSocket(); adamModbus2.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus2.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus3 = new AdamSocket(); adamModbus3.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus3.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus4 = new AdamSocket(); adamModbus4.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus4.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus5 = new AdamSocket(); adamModbus5.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus5.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus6 = new AdamSocket(); adamModbus6.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus6.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus7 = new AdamSocket(); adamModbus7.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus7.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus8 = new AdamSocket(); adamModbus8.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus8.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 adamModbus9 = new AdamSocket(); adamModbus9.SetTimeout(500, 500, 500); // 设置超时时间 adamModbus9.AdamSeriesType = AdamType.Adam6200; // set AdamSeriesType for ADAM-6217 m_Adam6000Type = Adam6000Type.Adam6217; // the sample is for ADAM-6217 m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type); m_bChEnabled = new bool[m_iAiTotal]; m_byRange = new ushort[m_iAiTotal]; #endregion red_net = new Thread(red); red_net.Start(); }
public static void Main() { int DacValue1 = 10; int DacValue2 = 10; Debug.Print(Resources.GetString(Resources.StringResources.String1)); // ADC AnalogInput ADC0 = new AnalogInput(ADC.PA1); AnalogInput ADC1 = new AnalogInput(ADC.PA2); AnalogInput ADC2 = new AnalogInput(ADC.PA3); AnalogInput ADC3 = new AnalogInput(ADC.PB0); // PB0 = PA0 ??? //DAC AnalogOutput DAC0 = new AnalogOutput(Cpu.AnalogOutputChannel.ANALOG_OUTPUT_0); AnalogOutput DAC1 = new AnalogOutput(Cpu.AnalogOutputChannel.ANALOG_OUTPUT_1); DAC0.Scale = 1; DAC0.Write(0.8); DAC1.Scale = 1; DAC1.Write(0.1); /* Initialize LEDs */ LED.LEDInit(); LED.GreenLedToggle(); while (true) { /* Display the ADC converted value */ //int AdcValue = (ADC0.ReadRaw() * 1); //string str = AdcValue.ToString(); Debug.Print("ADC0 (pin " + ADC0.Pin + ") = " + (ADC0.ReadRaw())); Debug.Print("ADC1 (pin " + ADC1.Pin + ") = " + (ADC1.ReadRaw())); Debug.Print("ADC2 (pin " + ADC2.Pin + ") = " + (ADC2.ReadRaw())); Debug.Print("ADC3 (pin " + ADC3.Pin + ") = " + (ADC3.ReadRaw())); Debug.Print("\r\n--------------------------------\r\n"); /* Wait for 1s */ Thread.Sleep(250); /* Toggle Green LED */ LED.GreenLedToggle(); LED.RedLedToggle(); DacValue1 += 100; if (DacValue1 > 4000) { DacValue1 = 0; } DAC0.WriteRaw(DacValue1); DacValue2 += 100; if (DacValue2 > 4000) { DacValue2 = 0; } DAC1.WriteRaw(DacValue2); } }
private void RefreshSingleAiChannel(int i_iIndex, ref TextBox txtCh, float fValue, int i_iStatus) { string szFormat; if (m_bChEnabled[i_iIndex]) { if (i_iStatus == 0) { szFormat = AnalogInput.GetFloatFormat(m_Adam6000Type, m_byAiRange[i_iIndex]); txtCh.Text = fValue.ToString(szFormat) + " " + AnalogInput.GetUnitName(m_Adam6000Type, m_byAiRange[i_iIndex]); } else if (i_iStatus == 1) { txtCh.Text = "Over(H)"; } else if (i_iStatus == 2) { txtCh.Text = "Over(L)"; } else { txtCh.Text = "Invalid(R)"; } } }
private void RefreshChannelValue() { int iStart = 1; int iIdx; int[] iData; float[] fValue = new float[m_iAiTotal]; if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData)) { for (iIdx = 0; iIdx < m_iAiTotal; iIdx++) { fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_byRange[iIdx], (ushort)iData[iIdx]); } RefreshSingleChannel(0, ref txtAIValue0, fValue[0]); RefreshSingleChannel(1, ref txtAIValue1, fValue[1]); RefreshSingleChannel(2, ref txtAIValue2, fValue[2]); RefreshSingleChannel(3, ref txtAIValue3, fValue[3]); RefreshSingleChannel(4, ref txtAIValue4, fValue[4]); RefreshSingleChannel(5, ref txtAIValue5, fValue[5]); RefreshSingleChannel(6, ref txtAIValue6, fValue[6]); RefreshSingleChannel(7, ref txtAIValue7, fValue[7]); } }
private void RefreshChannelValueUshortFormat() { int iStart = 1, iAiStatusStart = 101; int iIdx; int[] iData, iAiStatus; float[] fValue = new float[m_iAiTotal]; if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData)) { for (iIdx = 0; iIdx < m_iAiTotal; iIdx++) { fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], (ushort)iData[iIdx]); } if (adamModbus.Modbus().ReadInputRegs(iAiStatusStart, (m_iAiTotal * 2), out iAiStatus)) { RefreshSingleChannelWithAiStatus(0, ref txtAIValue0, fValue[0], (ushort)iAiStatus[(0 * 2)]); RefreshSingleChannelWithAiStatus(1, ref txtAIValue1, fValue[1], (ushort)iAiStatus[(1 * 2)]); RefreshSingleChannelWithAiStatus(2, ref txtAIValue2, fValue[2], (ushort)iAiStatus[(2 * 2)]); RefreshSingleChannelWithAiStatus(3, ref txtAIValue3, fValue[3], (ushort)iAiStatus[(3 * 2)]); RefreshSingleChannelWithAiStatus(4, ref txtAIValue4, fValue[4], (ushort)iAiStatus[(4 * 2)]); RefreshSingleChannelWithAiStatus(5, ref txtAIValue5, fValue[5], (ushort)iAiStatus[(5 * 2)]); RefreshSingleChannelWithAiStatus(6, ref txtAIValue6, fValue[6], (ushort)iAiStatus[(6 * 2)]); if ((m_Adam6000Type == Adam6000Type.Adam6017) || (m_Adam6000Type == Adam6000Type.Adam6018)) { RefreshSingleChannelWithAiStatus(7, ref txtAIValue7, fValue[7], (ushort)iAiStatus[(7 * 2)]); } } } }
public static void Main() { var currentState = GetCurrentState(); Debug.Print(currentState); AnalogInput analogInput = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); var data = analogInput.Read() * 10D; try { var setStateResult = SetCurrentState((int)data); Debug.Print(setStateResult); } catch (WebException wex) { //I expect this to time out - the gateway blocks the call and my netduino is going to //give up before completing. Debug.Print("Call did not return, check state manually"); } while (true) { currentState = GetCurrentState(); Debug.Print(currentState); Thread.Sleep(5000); } }
public Form1() { InitializeComponent(); int iIdx; m_bStart = false; // the action stops at the beginning m_szIP = "172.18.3.200"; // modbus slave IP address m_iPort = 502; // modbus TCP port is 502 adamModbus = new AdamSocket(); adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP m_Adam6000Type = Adam6000Type.Adam6024; // the sample is for ADAM-6050 // modbus current list view item m_iAiTotal = AnalogInput.GetChannelTotal(m_Adam6000Type); m_iDiTotal = DigitalInput.GetChannelTotal(m_Adam6000Type); m_iAoTotal = AnalogOutput.GetChannelTotal(m_Adam6000Type); m_iDoTotal = DigitalOutput.GetChannelTotal(m_Adam6000Type); m_bChEnabled = new bool[m_iAiTotal]; m_byAiRange = new byte[m_iAiTotal]; m_byAoRange = new byte[m_iAoTotal]; for (iIdx = 0; iIdx < m_iAoTotal; iIdx++) { // cbxAOChannel.Items.Add(iIdx.ToString()); // } cbxAOChannel.SelectedIndex = -1; txtModule.Text = m_Adam6000Type.ToString(); }
/// <summary> /// Constructor. /// </summary> /// <param name="xAccelPin"></param> /// <param name="yAccelPin"></param> /// <param name="zAccelPin"></param> /// <param name="xGyroPin"></param> /// <param name="yGyroPin"></param> public Analog5DOF(Cpu.Pin xAccelPin = Cpu.Pin.GPIO_NONE, Cpu.Pin yAccelPin = Cpu.Pin.GPIO_NONE, Cpu.Pin zAccelPin = Cpu.Pin.GPIO_NONE, Cpu.Pin xGyroPin = Cpu.Pin.GPIO_NONE, Cpu.Pin yGyroPin = Cpu.Pin.GPIO_NONE) { this.Acceleration = new Vector(0, 0, 0); this.RotationRate = new Vector(0, 0, 0); if (xAccelPin != Cpu.Pin.GPIO_NONE) { _xAccelInput = new AnalogInput(xAccelPin); } if (yAccelPin != Cpu.Pin.GPIO_NONE) { _yAccelInput = new AnalogInput(yAccelPin); } if (zAccelPin != Cpu.Pin.GPIO_NONE) { _zAccelInput = new AnalogInput(zAccelPin); } if (xGyroPin != Cpu.Pin.GPIO_NONE) { _xGyroInput = new AnalogInput(xGyroPin); } if (yGyroPin != Cpu.Pin.GPIO_NONE) { _yGyroInput = new AnalogInput(yGyroPin); } }
//This loop polls the aio value set by the trimpot to determine the duty cycle which // determines the amplitude on the sin curve of a given itteration. private void SinLEDLoop(AnalogInput pot, PWM led, OutputPort relay, LCD_Display display) { double startValue = 0; bool laststate = false; double potValue = 0.0; TimeSpan lastPeak = Utility.GetMachineTime(); while (true) { potValue = pot.Read(); startValue += .5 * potValue; if (startValue > 2 * System.Math.PI) { startValue = 0; laststate = !laststate; //relay.Write(laststate); if (display != null) { display.writeValue("Frequency: " + getFreq(lastPeak) + " Hz"); } lastPeak = Utility.GetMachineTime(); } Thread.Sleep(5); led.DutyCycle = System.Math.Max(0, System.Math.Sin(startValue)); } }
/// <summary> /// Calculate Temperature value /// </summary> /// <returns>Float value of current Temperature reading</returns> /// <remarks>Assuming AREF of 3.3v, the default for Rev. B Netduino Plus boards. /// It's an internal value, no feed to AREF required. /// Using code tutorial from adafruit http://www.ladyada.net/learn/sensors/thermistor.html </remarks> private float CalculateTemperature() { AnalogInput ain = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); // take 10 readings to even out the noise float average = 0.0F; for (int i = 0; i < 10; i++) { average += (int)ain.Read(); } average /= 10; if (average == 0) { return(10.0F); } // convert to a resistance average = 1023 / average - 1; average = SeriesResistor / average; // apply steinhart float tempValue = average / ThermistorNominal; tempValue = Extensions.Math.Log(tempValue); tempValue /= BetaCoefficient; tempValue += 1.0F / (TemperatureNominal + 273.15F); tempValue = 1.0F / tempValue; tempValue -= 273.15F; ain.Dispose(); return(tempValue); }
public static void SetUpBeforeClass() { compressor = new Compressor(); fakePressureSwitch = new DigitalOutput(11); fakeCompressor = new AnalogInput(1); fakeSolenoid1 = new DigitalInput(12); fakeSolenoid2 = new DigitalInput(13); if (RobotBase.IsSimulation) { /* * pressureSwitchCallback = (s, o) => * { * var comp = SimData.GetPCM(0).Compressor; * comp.PressureSwitch = o; * comp.On = o; * double voltage = o ? CompressorOffVoltage : CompressorOnVoltage; * SimData.AnalogIn[1].Voltage = voltage; * }; */ pressureSwitchCallback = (string name, HAL_Value value) => { SimData.PCM[0].SetPressureSwitch(value.GetBoolean()); SimData.PCM[0].SetCompressorOn(value.GetBoolean()); double voltage = value.GetBoolean() ? CompressorOffVoltage : CompressorOnVoltage; SimData.AnalogIn[1].SetVoltage(voltage); }; callbackId = SimData.DIO[11].RegisterValueCallback(pressureSwitchCallback, false); } }
private void RefreshAiChannelValue() { int iStart = 1, iStatusStart = 21; int iIdx; int[] iData; float[] fValue = new float[m_iAiTotal]; int[] iStatus = new int[m_iAiTotal]; if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData) && adamModbus.Modbus().ReadInputRegs(iStatusStart, m_iAiTotal, out iStatus)) { for (iIdx = 0; iIdx < m_iAiTotal; iIdx++) { fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_byAiRange[iIdx], iData[iIdx]); } RefreshSingleAiChannel(0, ref txtCh0, fValue[0], iStatus[0]); RefreshSingleAiChannel(1, ref txtCh1, fValue[1], iStatus[1]); RefreshSingleAiChannel(2, ref txtCh2, fValue[2], iStatus[2]); RefreshSingleAiChannel(3, ref txtCh3, fValue[3], iStatus[3]); RefreshSingleAiChannel(4, ref txtCh4, fValue[4], iStatus[4]); RefreshSingleAiChannel(5, ref txtCh5, fValue[5], iStatus[5]); } else { txtReadCount.Text += "ReadInputRegs() failed;"; } }
/// <summary> /// Create a new ADXL335 sensor object. /// </summary> /// <param name="x">Analog pin connected to the X axis output from the ADXL335 sensor.</param> /// <param name="y">Analog pin connected to the Y axis output from the ADXL335 sensor.</param> /// <param name="z">Analog pin connected to the Z axis output from the ADXL335 sensor.</param> /// <param name="updateInterval">Update interval for the sensor, set to 0 to put the sensor in polling mode.</param> /// <<param name="accelerationChangeNotificationThreshold">Acceleration change threshold.</param> public ADXL335(Cpu.AnalogChannel x, Cpu.AnalogChannel y, Cpu.AnalogChannel z, ushort updateInterval = 100, double accelerationChangeNotificationThreshold = 0.1F) { if ((updateInterval != 0) && (updateInterval < MinimumPollingPeriod)) { throw new ArgumentOutOfRangeException(nameof(updateInterval), "Update interval should be 0 or greater than " + MinimumPollingPeriod); } _x = new AnalogInput(x); _y = new AnalogInput(y); _z = new AnalogInput(z); // // Now set the default calibration data. // XVoltsPerG = 0.325; YVoltsPerG = 0.325; ZVoltsPerG = 0.550; SupplyVoltage = 3.3; if (updateInterval > 0) { StartUpdating(); } else { Update(); } }
public static void Main() { // AnalogInput przetwarza różnicę poziomów pomiędzy 0 a 3,3V na 1024 poziomy odczytu, lub liczbę niecałkowitą z zakresu 0;1 AnalogInput lux = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); // SerialPort połączony jest na COM2 (piny 2 i 3) do modułu Bluetooth na parametrach 38400, 8, N, 1 SerialPort sp = new SerialPort(SerialPorts.COM2, 38400, Parity.None, 8, StopBits.One); sp.Open(); // na wieczność while (true) { // wykonaj odczyt, przetwórz na string, dodaj znak końca linii var data = lux.Read().ToString() + "\r\n"; Debug.Print(data); // wyślij przez Bluetooth var buf = Encoding.UTF8.GetBytes(data); sp.Write(buf, 0, buf.Length); // czekaj 200 milisekund do następnego pomiaru Thread.Sleep(200); } sp.Close(); }
private void btnSetSafetyValue_Click(object sender, EventArgs e) { if (!CheckControllable()) { return; } timer1.Enabled = false; int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx]; float[] fAOSafetyVals = new float[iChannelTotal]; for (int i = 0; i < iChannelTotal; i++) { fAOSafetyVals[i] = AnalogOutput.GetScaledValue(m_usRanges[i], m_usAOSafetyVals[i]); } string[] szRanges = new string[iChannelTotal]; for (int idx = 0; idx < szRanges.Length; idx++) { szRanges[idx] = AnalogInput.GetRangeName(m_usRanges[idx]); } FormSafetySetting formSafety = new FormSafetySetting(iChannelTotal, fAOSafetyVals, szRanges); formSafety.ApplySafetyValueClick += new FormSafetySetting.EventHandler_ApplySafetyValueClick(formSafety_ApplySafetyValueClick); formSafety.ShowDialog(); formSafety.Dispose(); formSafety = null; timer1.Enabled = true; }
public override void OnInspectorGUI() { this.serializedObject.Update(); AnalogInput controller = (AnalogInput)target; GUI.enabled = false; EditorGUILayout.PropertyField(script, true, new GUILayoutOption[0]); GUI.enabled = true; foldout = EditorGUILayout.Foldout(foldout, "Sketch Options"); if (foldout) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(id, new GUIContent("id")); EditorGUILayout.PropertyField(pin, new GUIContent("pin(A_)")); EditorGUI.indentLevel--; } controller.enableUpdate = EditorGUILayout.Toggle("Enable update", controller.enableUpdate); EditorGUILayout.Slider("Value", controller.Value, 0f, 1f); if (Application.isPlaying && controller.enableUpdate) { EditorUtility.SetDirty(target); } this.serializedObject.ApplyModifiedProperties(); }
public static void Main() { AnalogInput analogSensor1 = new AnalogInput ( Pins.Analog.Socket1Pin1 //Pins.Analog.Socket2Pin1 //Pins.Analog.Socket3Pin1 //Pins.Analog.Socket4Pin1 ); AnalogInput analogSensor2 = new AnalogInput ( Pins.Analog.Socket1Pin2 //Pins.Analog.Socket2Pin2 //Pins.Analog.Socket3Pin2 //Pins.Analog.Socket4Pin2 ); Debug.Print("Program running"); while (true) { double sensorValue1 = analogSensor1.Read(); double sensorValue2 = analogSensor2.Read(); Debug.Print("Value 1:" + sensorValue1.ToString("F2") + " Value 2:" + sensorValue2.ToString("F2")); Thread.Sleep(500); } }
/// <summary> /// Get Channel information "Range" column /// </summary> /// <returns></returns> private bool RefreshRanges() { try { int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx]; if (m_adamCtl.Configuration().GetModuleConfig(m_idxID, out m_aConf)) { m_usRanges = m_aConf.wChRange; m_uiChMask = m_aConf.dwChMask; for (int i = 0; i < this.m_bChMask.Length; i++) { m_bChMask[i] = ((m_uiChMask & (0x01 << i)) > 0); } for (int i = 0; i < iChannelTotal; i++) { listViewChInfo.Items[i].SubItems[4].Text = AnalogInput.GetRangeName(m_usRanges[i]).ToString(); } } else { StatusBar_IO.Text += "GetModuleConfig(Error:" + m_adamCtl.Configuration().ApiLastError.ToString() + ") Failed! "; } return(true); } catch { return(false); } }
private static int pe2a_AI_getVal_cnv_choosing(AnalogInput pin, ref byte[] ptr) { switch (pin) { case AnalogInput.Gpio_J13_1: ptr[0] = 0x86; //conversion ch0 break; case AnalogInput.Gpio_J13_2: ptr[0] = 0x8e; //conversion ch1 break; case AnalogInput.Gpio_J13_3: ptr[0] = 0x96; //conversion ch2 break; case AnalogInput.Gpio_J13_4: ptr[0] = 0x9e; //conversion ch3 break; default: return(-1); } ptr[1] = 0x60; //setup ptr[2] = 0x3c; //ave return(0); }
public static void Main() { AnalogInput capt = new AnalogInput((Cpu.AnalogChannel)Cpu.AnalogChannel.ANALOG_0); OutputPort dir = new OutputPort(FEZSpider.Socket8.Pin9, true); InputPort microswitch = new InputPort(FEZSpider.Socket4.Pin3, false, Port.ResistorMode.PullDown); double frequence = 38000; // Période en microseconde double rapportCyclique = 0.5; // Période en microseconde PWM motorDriver = new PWM(FEZSpider.Socket8.Pwm7, frequence, rapportCyclique, false); motorDriver.Stop(); while (true) { if (microswitch.Read()) { motorDriver.Stop(); } Debug.Print("Distance : " + capt.Read().ToString()); Debug.Print(microswitch.Read().ToString()); Thread.Sleep(50); } }
/// <summary> /// Constructor /// </summary> /// <param name="channel"></param> public TMP36(Channel channel) { switch (channel) { case Channel.GPIO_PIN_A0: Sensor = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); break; case Channel.GPIO_PIN_A1: Sensor = new AnalogInput(AnalogChannels.ANALOG_PIN_A1); break; case Channel.GPIO_PIN_A2: Sensor = new AnalogInput(AnalogChannels.ANALOG_PIN_A2); break; case Channel.GPIO_PIN_A3: Sensor = new AnalogInput(AnalogChannels.ANALOG_PIN_A3); break; case Channel.GPIO_PIN_A4: Sensor = new AnalogInput(AnalogChannels.ANALOG_PIN_A4); break; case Channel.GPIO_PIN_A5: Sensor = new AnalogInput(AnalogChannels.ANALOG_PIN_A5); break; default: throw new ArgumentException("Invalid Channel (0-5)"); } Alpha = 0.01; }
/// <summary> /// When user select specific item of channel information, you should update channel range /// </summary> /// <param name="idxSel"></param> private void LvChInfo_SelectedIndexChanged(int idxSel) { this.cbxRange.SelectedIndex = GetChannelRangeIdx(AnalogInput.GetRangeName(m_usRanges[idxSel])); this.btnMaskEnable.Enabled = true; this.btnMaskDisable.Enabled = true; if ((m_usRanges[idxSel] <= (ushort)ApaxUnknown_InputRange.Btype_200To1820C && m_usRanges[idxSel] >= (ushort)ApaxUnknown_InputRange.Jtype_Neg210To1200C) || //0x0401~0x04C1 (m_usRanges[idxSel] <= (ushort)ApaxUnknown_InputRange.Ni518_0To100 && m_usRanges[idxSel] >= (ushort)ApaxUnknown_InputRange.Pt100_3851_Neg200To850)) //0x0200~0x0321 { this.chkBurnoutFcn.Enabled = true; this.btnBurnoutFcn.Enabled = true; } else { this.chkBurnoutFcn.Enabled = false; this.btnBurnoutFcn.Enabled = false; } //refresh burnout mask if (((m_uiBurnoutMask >> idxSel) & 0x1) > 0) { chkBurnoutFcn.Checked = true; } else { chkBurnoutFcn.Checked = false; } }
/// <summary> /// Frees the resources allocated for reading values from the analog joystick /// </summary> public void Dispose() { Xinput.Dispose(); Xinput = null; Yinput.Dispose(); Yinput = null; }
public Form1() { InitializeComponent(); m_b5000 = true; // set to true for module on ADAM-5000; set to false for module on ADAM-5000/TCP if (m_b5000) { m_iCom = 4; // using COM4 adamCom = new AdamCom(m_iCom); adamCom.Checksum = false; // disbale checksum } else { m_szIP = "172.18.3.179"; adamSocket = new AdamSocket(); adamSocket.SetTimeout(1000, 1000, 1000); // set timeout } m_iAddr = 3; // the slave address is 1 m_iSlot = 0; // the slot index of the module m_iCount = 0; // the counting start from 0 m_bStart = false; m_Adam5000Type = Adam5000Type.Adam5017H; // the sample is for ADAM-5017H //m_Adam5000Type = Adam5000Type.Adam5017UH; // the sample is for ADAM-5017UH //m_Adam5000Type = Adam5000Type.Adam5018P; // the sample is for ADAM-5018P m_iChTotal = AnalogInput.GetChannelTotal(m_Adam5000Type); m_byRange = new byte[m_iChTotal]; txtModule.Text = m_Adam5000Type.ToString(); // if (m_Adam5000Type == Adam5000Type.Adam5018P) { chkboxCh7.Visible = false; txtAIValue7.Visible = false; } }
private void RefreshChannelValueUshortFormat() { int iStart = 1, iAiStatusStart = 101; int iIdx; int[] iData, iAiStatus; float[] fValue = new float[m_iAiTotal]; if (adamModbus.Modbus().ReadInputRegs(iStart, m_iAiTotal, out iData)) { sensorValues.Clear(); for (iIdx = 0; iIdx < m_iAiTotal; iIdx++) { fValue[iIdx] = AnalogInput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], (ushort)iData[iIdx]); } if (adamModbus.Modbus().ReadInputRegs(iAiStatusStart, (m_iAiTotal * 2), out iAiStatus)) { // store data to db //AddToDb(DateTime.Now, fValue[0], 0); //AddToDb(DateTime.Now, fValue[1], 1); //AddToDb(DateTime.Now, fValue[2], 2); //AddToDb(DateTime.Now, fValue[3], 3); for (int num = 0; num < sensorNumber; num++) { sensorValues.Add("sensor" + (num + 1), fValue[num].ToString()); } sensorValues.Add("timeOperate", DateTime.Now.ToString("HH:mm:ss")); sensorStatus = "true"; } adamModbus.Disconnect(); } }
public PWM_AIO_Demo_Main() { //AIO pin connected to arbitrary range potentiometer. AnalogInput pot = new AnalogInput(AnalogChannels.ANALOG_PIN_A0); pot.Scale = 1; //sets range value that is returned by aio read() //Initialize I2C interface for HD44780 LCD. // Disabled while tinkering with MPU6050 //LCD_Display Display = new LCD_Display(LCD_I2C_ADDRESS, 20, 4); IMU_I2C imu = new IMU_I2C(IMU_I2C.MPU6050_DEFAULT_ADDRESS); SensorData imuData = imu.getSensorData(); bool onboardstate = false; OutputPort onboardled = new OutputPort(Pins.ONBOARD_LED, onboardstate); while (true) { Thread.Sleep(1); imuData = imu.getSensorData(); onboardstate = !onboardstate; onboardled.Write(onboardstate); Debug.Print("X Y Z X' Y' Z' " + imuData.Gyroscope_X.ToString() + " " + imuData.Gyroscope_Y.ToString() + " " + imuData.Gyroscope_Z.ToString() + " " + imuData.Acceleration_X.ToString() + " " + imuData.Acceleration_Y.ToString() + " " + imuData.Acceleration_Z.ToString()); } }
public void TestCreateExistingAnalogInput() { using (AnalogInput aIn = new AnalogInput(0)) using (AnalogGyro input = new AnalogGyro(aIn)) { Assert.IsTrue(GetGyroData(0).Initialized); } }
private void Initialize() { lock (this) { if (!initialized) { input = GiveAnalogInput(); output = GiveAnalogOutput(); initialized = true; } } }
static void Main() { var voltagePort = new AnalogInput(Parameters.AnalogPin); var lowPort = new OutputPort(Parameters.LowPin, false); var highPort = new OutputPort(Parameters.HighPin, true); voltagePort.Scale = 3.3; // convert to Volt while (true) { double value = voltagePort.Read(); Debug.Print(value.ToString("f")); // fixed-point format Thread.Sleep(3000); // 3 seconds } }
public void TestAnalogTriggerTakeAnalogInput() { using (AnalogInput aIn = new AnalogInput(0)) { Assert.That(SimData.AnalogIn[0].Initialized, Is.True); int index = 0; using (AnalogTrigger trigger = new AnalogTrigger(aIn)) { index = trigger.Index; Assert.That(GetData(index).Initialized, Is.True); } Assert.That(GetData(index).Initialized, Is.False); Assert.That(SimData.AnalogIn[0].Initialized, Is.True); } Assert.That(SimData.AnalogIn[0].Initialized, Is.False); }
static void Main() { const int samplingPeriod = 6000; // 6 seconds var voltagePort = new AnalogInput(Parameters.AnalogPin); var lowPort = new OutputPort(Parameters.LowPin, false); var highPort = new OutputPort(Parameters.HighPin, true); voltagePort.Scale = 3.3; // convert to Volt Socket connection = null; while (true) // main loop { WaitUntilNextPeriod(samplingPeriod); if (connection == null) // create connection { try { connection = Connect("api.xively.com", samplingPeriod / 2); } catch { Debug.Print("connection error"); } } if (connection != null) { try { double value = voltagePort.Read(); string sample = "HelloXivelySockets," + Debug.GC(true); // string sample = "voltage," + value.ToString("f"); SendRequest(connection, Parameters.ApiKey, Parameters.FeedId, sample); } catch (SocketException) { connection.Close(); connection = null; } } } }
public static void Main() { const string apiKey = "<insert your API key here>"; const string feedId = "<insert your feed ID here>"; const int samplingPeriod = 20000; // 20 seconds var voltagePort = new AnalogInput(AnalogChannel.ANALOG_Socket6_Pin3); voltagePort.Scale = 3.3; // convert to Volt while (true) { WaitUntilNextPeriod(samplingPeriod); double value = voltagePort.Read(); string sample = "voltage," + value.ToString("f"); Debug.Print("new message: " + sample); CosmClient.Send(apiKey, feedId, sample); } }
static void Main() { const int samplingPeriod = 6000; // 6 seconds var voltagePort = new AnalogInput(Parameters.AnalogPin); var lowPort = new OutputPort(Parameters.LowPin, false); var highPort = new OutputPort(Parameters.HighPin, true); voltagePort.Scale = 3.3; // convert to Volt while (true) { WaitUntilNextPeriod(samplingPeriod); double value = voltagePort.Read(); string sample = "voltage," + value.ToString("f"); Debug.Print("new message: " + sample); XivelyClient.Send(Parameters.ApiKey, Parameters.FeedId, sample); } }
public static void SetUpBeforeClass() { compressor = new Compressor(); fakePressureSwitch = new DigitalOutput(11); fakeCompressor = new AnalogInput(1); fakeSolenoid1 = new DigitalInput(12); fakeSolenoid2 = new DigitalInput(13); if (RobotBase.IsSimulation) { pressureSwitchCallback = (s, o) => { var comp = SimData.GetPCM(0).Compressor; comp.PressureSwitch = o; comp.On = o; double voltage = o ? CompressorOffVoltage : CompressorOnVoltage; SimData.AnalogIn[1].Voltage = voltage; }; SimData.DIO[11].Register("Value", pressureSwitchCallback); } }
public void TestCreationPreCreatedInput() { using (AnalogInput input = new AnalogInput(0)) { Assert.IsTrue(SimData.AnalogIn[0].Initialized); using (AnalogAccelerometer accel = new AnalogAccelerometer(input)) { Assert.IsTrue(GetInputData(0).Initialized); } Assert.IsTrue(SimData.AnalogIn[0].Initialized); } Thread.Sleep(100); Assert.IsFalse(GetInputData(0).Initialized); Assert.IsFalse(SimData.AnalogIn[0].Initialized); }
/// <summary> /// Calculate Temperature value /// </summary> /// <returns>Float value of current Temperature reading</returns> /// <remarks>Assuming AREF of 3.3v, the default for Rev. B Netduino Plus boards. /// It's an internal value, no feed to AREF required. /// Using code tutorial from adafruit http://www.ladyada.net/learn/sensors/thermistor.html </remarks> private float CalculateTemperature() { AnalogInput ain = new AnalogInput(Pins.GPIO_PIN_A0); // take 10 readings to even out the noise float average = 0.0F; for (int i = 0; i < 10; i++) { average += ain.Read(); } average /= 10; // convert to a resistance average = 1023 / average - 1; average = SeriesResistor / average; // apply steinhart float tempValue = average / ThermistorNominal; tempValue = Controller.Math.Log(tempValue); tempValue /= BetaCoefficient; tempValue += 1.0F / (TemperatureNominal + 273.15F); tempValue = 1.0F / tempValue; tempValue -= 273.15F; ain.Dispose(); return tempValue; }
public void TestPotentiometerCreatedWithAnalogInput() { using (AnalogInput aIn = new AnalogInput(0)) { Assert.That(GetInputData(0).Initialized, Is.True); using (AnalogPotentiometer pot = new AnalogPotentiometer(aIn)) { } Assert.That(GetInputData(0).Initialized, Is.True); } Assert.That(GetInputData(0).Initialized, Is.False); }
public AnalogueRangeFinder(AnalogInput pin) { this.pin = pin; }
public Photocell(AnalogInput input) { Input = input; }
public Tmp() { _port = new AnalogInput(Pins.GPIO_PIN_A0); }