static void Main(string[] args) { Console.WriteLine("\nGPIO Pin Toggle Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); // Create GPIO pin object Console.Write("GPIO channel number? "); IO.Interfaces.GPIO.Pin Output = new IO.Remote.GPIO(dev, int.Parse(Console.ReadLine()), IO.Interfaces.GPIO.Direction.Output); // Toggle the GPIO output Console.WriteLine("\nPress CONTROL-C to exit"); for (;;) { Output.state = !Output.state; } }
static void Main(string[] args) { Console.WriteLine("\nHDC1080 Temperature/Humidity Sensor Test\n"); IO.Interfaces.Message64.Messenger msg = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device remdev = new IO.Remote.Device(msg); IO.Interfaces.I2C.Bus bus = new IO.Remote.I2C(remdev, 0); IO.Devices.HDC1080.Device dev = new IO.Devices.HDC1080.Device(bus); Console.Write("Manufacturer ID: 0x" + dev.ManufacturerID.ToString("X4")); Console.Write(" "); Console.WriteLine("Device ID: 0x" + dev.DeviceID.ToString("X4")); Console.WriteLine(); for (;;) { Console.Write("Temperature: " + dev.Temperature.ToString("F1")); Console.Write(" "); Console.Write("Humidity: " + dev.Humidity.ToString("F1")); Console.WriteLine(); System.Threading.Thread.Sleep(1000); } }
static void Main(string[] args) { Console.WriteLine("\nGrove I2C A/D Converter Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); IO.Interfaces.I2C.Bus bus = new IO.Remote.I2C(dev, 0); IO.Interfaces.ADC.Sample adc = new IO.Devices.ADC121C021.Sample(bus, 0x50); IO.Interfaces.ADC.Input inp = new IO.Interfaces.ADC.Input(adc, 3.0, 0.5); Console.WriteLine("Resolution: " + adc.resolution.ToString() + " bits\n"); for (;;) { Console.WriteLine("Voltage => " + inp.voltage.ToString("F2")); Thread.Sleep(1000); } }
static void Main(string[] args) { Console.WriteLine("\nRaw HID Query Test\n"); IO.Objects.libsimpleio.HID.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); Console.WriteLine("Device Name: " + m.name); Console.WriteLine("Bus type: " + m.bustype.ToString()); Console.WriteLine("Vendor ID: " + m.vendor.ToString("X4")); Console.WriteLine("Product ID: " + m.product.ToString("X4")); }
static void Main(string[] args) { Console.WriteLine("\nUSB HID Remote I/O Analog Input Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); Console.Write("Channels: "); foreach (int input in dev.ADC_Available()) { Console.Write(" " + input.ToString()); } Console.WriteLine(); ArrayList S = new ArrayList(); foreach (int c in dev.ADC_Available()) { S.Add(new IO.Remote.ADC(dev, c)); } Console.Write("Resolutions: "); foreach (IO.Interfaces.ADC.Sample inp in S) { Console.Write(" " + inp.resolution.ToString()); } Console.WriteLine(); for (;;) { Console.Write("Samples: "); foreach (IO.Interfaces.ADC.Sample inp in S) { Console.Write(String.Format(" {0:00000}", inp.sample)); } Console.WriteLine(); Thread.Sleep(2000); } }
static void Main(string[] args) { Console.WriteLine("\nDAC Output Test using libsimpleio\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); Console.Write("Channels: "); foreach (int output in dev.DAC_Available()) { Console.Write(" " + output.ToString()); } Console.WriteLine(); ArrayList S = new ArrayList(); foreach (int c in dev.DAC_Available()) { S.Add(new IO.Remote.DAC(dev, c)); } Console.Write("Resolutions: "); foreach (IO.Interfaces.DAC.Sample output in S) { Console.Write(" " + output.resolution.ToString()); } Console.WriteLine(); for (;;) { int n; for (n = 0; n < 4096; n++) { foreach (IO.Interfaces.DAC.Sample output in S) { output.sample = n; } } } }
static void Main(string[] args) { Console.WriteLine("\nUSB HID Remote I/O Button and LED Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device d = new IO.Remote.Device(m); // Configure LED output IO.Interfaces.GPIO.Pin LD1 = new IO.Remote.GPIO(d, 0, IO.Interfaces.GPIO.Direction.Output); // Configure button input IO.Interfaces.GPIO.Pin SW1 = new IO.Remote.GPIO(d, 1, IO.Interfaces.GPIO.Direction.Input); bool OldState = !SW1.state; bool NewState = OldState; // Read the button and write the LED for (;;) { NewState = SW1.state; if (NewState != OldState) { if (NewState) { Console.WriteLine("PRESSED"); LD1.state = true; } else { Console.WriteLine("RELEASED"); LD1.state = false; } OldState = NewState; } System.Threading.Thread.Sleep(100); } }
static void Main(string[] args) { Console.WriteLine("\nPWM Output Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); Console.Write("Channels:"); foreach (int output in dev.PWM_Available()) { Console.Write(" " + output.ToString()); } Console.WriteLine(); ArrayList S = new ArrayList(); foreach (int c in dev.PWM_Available()) { S.Add(new IO.Remote.PWM(dev, c, 1000)); } for (;;) { int n; for (n = 0; n < 500; n++) { foreach (IO.Interfaces.PWM.Output output in S) { output.dutycycle = n / 5.0; } } for (n = 500; n >= 0; n--) { foreach (IO.Interfaces.PWM.Output output in S) { output.dutycycle = n / 5.0; } } } }
static void Main(string[] args) { Console.WriteLine("\nServo Output Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); Console.Write("Channels:"); foreach (int output in dev.PWM_Available()) { Console.Write(" " + output.ToString()); } Console.WriteLine(); ArrayList S = new ArrayList(); foreach (int c in dev.PWM_Available()) { S.Add(new IO.Objects.Servo.PWM.Output(new IO.Remote.PWM(dev, c, 50), 50)); } for (;;) { int n; for (n = -300; n <= 300; n++) { foreach (IO.Interfaces.Servo.Output output in S) { output.position = n / 300.0; } } for (n = 300; n >= -300; n--) { foreach (IO.Interfaces.Servo.Output output in S) { output.position = n / 300.0; } } } }
static void Main(string[] args) { Console.WriteLine("\nUSB HID Remote I/O Device LED Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); IO.Interfaces.GPIO.Pin LED = dev.GPIO_Create(0, IO.Interfaces.GPIO.Direction.Output); for (;;) { LED.state = !LED.state; Thread.Sleep(500); } }
/// <summary> /// Create a Remote I/O device object for a Munts Technologies /// USB raw HID (VID=0x16D0, PID=0x0AFA) device Remote I/O Server. /// </summary> public Device() { transport = new IO.Objects.libsimpleio.HID.Messenger(); Message cmd = new Message(0); Message resp = new Message(); cmd.payload[0] = (byte)MessageTypes.VERSION_REQUEST; cmd.payload[1] = 1; transport.Transaction(cmd, resp); Version_string = System.Text.Encoding.UTF8.GetString(resp.payload, 3, Message.Size - 3).Trim('\0'); cmd.payload[0] = (byte)MessageTypes.CAPABILITY_REQUEST; cmd.payload[1] = 2; transport.Transaction(cmd, resp); Capability_string = System.Text.Encoding.UTF8.GetString(resp.payload, 3, Message.Size - 3).Trim('\0'); }
static void Main(string[] args) { Console.WriteLine("\nUSB HID Remote I/O PCA8574 GPIO Port Toggle Test\n"); IO.Interfaces.Message64.Messenger msg = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device remdev = new IO.Remote.Device(msg); IO.Interfaces.I2C.Bus bus = new IO.Remote.I2C(remdev, 0); IO.Devices.PCA8574.Device dev = new IO.Devices.PCA8574.Device(bus, 0x38); for (;;) { dev.Write(0x55); dev.Write(0xAA); } }
static void Main(string[] args) { Console.WriteLine("\nHID Button and LED Test\n"); // Open the raw HID device IO.Interfaces.Message64.Messenger dev = new IO.Objects.libsimpleio.HID.Messenger(IO.Devices.USB.Munts.HID.Vendor, IO.Devices.USB.Munts.HID.Product, 0); IO.Interfaces.Message64.Message ButtonState = new IO.Interfaces.Message64.Message(0); IO.Interfaces.Message64.Message LEDCommand = new IO.Interfaces.Message64.Message(0); // Process incoming keypress reports for (;;) { dev.Receive(ButtonState); switch (ButtonState.payload[0]) { case 0: Console.WriteLine("RELEASE"); LEDCommand.payload[0] = 0; dev.Send(LEDCommand); break; case 1: Console.WriteLine("PRESS"); LEDCommand.payload[0] = 1; dev.Send(LEDCommand); break; default: Console.WriteLine("ERROR: Unexpected keypress status value"); break; } } }
static void Main(string[] args) { Console.WriteLine("\nUSB HID Remote I/O PCA9534 GPIO Pin Toggle Test\n"); IO.Interfaces.Message64.Messenger msg = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device remdev = new IO.Remote.Device(msg); IO.Interfaces.I2C.Bus bus = new IO.Remote.I2C(remdev, 0); IO.Devices.PCA9534.Device dev = new IO.Devices.PCA9534.Device(bus, 0x27); IO.Interfaces.GPIO.Pin GPIO0 = new IO.Devices.PCA9534.GPIO.Pin(dev, 0, IO.Interfaces.GPIO.Direction.Output, false); for (;;) { GPIO0.state = !GPIO0.state; } }
static void Main(string[] args) { Console.WriteLine("\nUSB HID Remote I/O Device Information Query Test\n"); IO.Interfaces.Message64.Messenger m = new IO.Objects.libsimpleio.HID.Messenger(); IO.Remote.Device dev = new IO.Remote.Device(m); // Display some device information Console.WriteLine(dev.Version); Console.WriteLine(dev.Capabilities); Console.WriteLine(); // Display the available ADC inputs Console.Write("ADC inputs: "); foreach (int input in dev.ADC_Available()) { Console.Write(input.ToString() + " "); } Console.WriteLine(); // Display the available DAC outputs Console.Write("DAC outputs: "); foreach (int output in dev.DAC_Available()) { Console.Write(output.ToString() + " "); } Console.WriteLine(); // Display the available GPIO pins Console.Write("GPIO Pins: "); foreach (int pin in dev.GPIO_Available()) { Console.Write(pin.ToString() + " "); } Console.WriteLine(); // Display the available I2C buses Console.Write("I2C buses: "); foreach (int bus in dev.I2C_Available()) { Console.Write(bus.ToString() + " "); } Console.WriteLine(); // Display the available PWM outputs Console.Write("PWM outputs: "); foreach (int bus in dev.PWM_Available()) { Console.Write(bus.ToString() + " "); } Console.WriteLine(); // Display the available SPI devices Console.Write("SPI devices: "); foreach (int bus in dev.SPI_Available()) { Console.Write(bus.ToString() + " "); } Console.WriteLine(); }