private static void Main(string[] args) { Console.WriteLine("Scanning for CH341 devices..."); var devices = Enumerator.Enumerate(); if (devices.Count == 0) { Console.WriteLine("No CH341 devices found!\nAre you correctly LibUSB backend (https://zadig.akeo.ie/)?"); Environment.Exit(-1); } foreach (var devreg in devices) { var ch341 = new CH341(devreg); Console.WriteLine($"Using device {ch341.ToString()}..."); int foud_count = 0; for (int i = CH341.I2C_AddressMin; i <= CH341.I2C_AddressMax; ++i) { if (ch341.I2C_Detect(i)) { ++foud_count; Console.WriteLine($"Found i2c slave device at address 0x{i:X}"); } } Console.WriteLine($"Scan complete, {foud_count} found."); } }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { Enumerator.Enumerate <string>(input, (value, name) => { try { var addr = new MailAddress(value); if (addr.Address != value) { // Verifying there are not funny configurations, creating name as first part throw new HyperlambdaException( $"'{value}' is not a valid email address for [{name}]", true, 400, name); } } catch { // Verifying there are not funny configurations, creating name as first part throw new HyperlambdaException( $"'{value}' is not a valid email address", true, 400, name); } }); }
static void Main(string[] args) { Console.WriteLine("Scanning for CH341 devices..."); var devices = Enumerator.Enumerate(); if (devices.Count == 0) { Console.WriteLine("No CH341 devices found!\nAre you correctly LibUSB backend (https://zadig.akeo.ie/)?"); Environment.Exit(-1); } var dev = new CH341(devices.First()); byte addr = 0x17; dev.I2C_Start(); dev.WriteByteCheckAck((byte)(addr << 1)); dev.WriteByteCheckAck(0x80); dev.I2C_Start(); dev.WriteByteCheckAck((byte)((addr << 1) | 1)); dev.ReadByteAck(); dev.ReadByteAck(); dev.ReadByteNak(); dev.I2C_Stop(); }
public void Enumerate() { var result = Enumerator.Enumerate(); Assert.NotNull(result); Assert.IsNotEmpty(result); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { Enumerator.Enumerate <string>(input, (value, name) => { bool result = Uri.TryCreate(value, UriKind.Absolute, out Uri res); if (!result || (res.Scheme != Uri.UriSchemeHttp && res.Scheme != Uri.UriSchemeHttps)) { throw new ArgumentException($"'{value}' in [{name}] is not a valid URL, it needs to be prepended with http:// or https:// and also be a valid URL"); } }); }
public void OpenTwice() { var ch341 = Enumerator.Enumerate().First(); Assert.True(ch341.Open(out UsbDevice d1)); Assert.False(ch341.Open(out UsbDevice d2)); Assert.NotNull(d1); Assert.Null(d2); d1.Close(); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { var min = input.Children.FirstOrDefault(x => x.Name == "min")?.GetEx <long>() ?? long.MinValue; var max = input.Children.FirstOrDefault(x => x.Name == "max")?.GetEx <long>() ?? long.MaxValue; Enumerator.Enumerate <long>(input, (value, name) => { if (value < min || value > max) { throw new ArgumentException($"'{value}' in [{name}] is not between {min} and {max}, which is a mandatory condition"); } }); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { Enumerator.Enumerate <string>(input, (value, name) => { if (!input.Children.Any(x2 => x2.Get <string>() == value)) { var legalValues = input.Children.Select(x2 => "'" + x2.Get <string>() + "'"); var legalValueString = string.Join(", ", legalValues.ToArray()); input.Clear(); throw new ArgumentException($"'{value}' in [{name}] is not a legal value for field, [{legalValueString}] is a legal value for input."); } }); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { var pattern = input.Children.First(x => x.Name == "regex").GetEx <string>(); Enumerator.Enumerate <string>(input, (value, name) => { var isMatch = new Regex(pattern).IsMatch(value); if (!isMatch) { throw new ArgumentException($"Value of '{value}' in [{name}] does not conform to regular expression of '{pattern}'"); } }); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { Enumerator.Enumerate <string>(input, (value, name) => { bool result = Uri.TryCreate(value, UriKind.Absolute, out Uri res); if (!result || (res.Scheme != Uri.UriSchemeHttp && res.Scheme != Uri.UriSchemeHttps)) { throw new HyperlambdaException( $"'{value}' is not a valid URL for [{name}]", true, 400, name); } }); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { var min = input.Children.FirstOrDefault(x => x.Name == "min")?.GetEx <int>() ?? 0; var max = input.Children.FirstOrDefault(x => x.Name == "max")?.GetEx <int>() ?? int.MaxValue; Enumerator.Enumerate <string>(input, (value, name) => { if (value.Length < min || value.Length > max) { throw new HyperlambdaException( $"'{value}' is not a valid string between {min} and {max} in length for [{name}]", true, 400, name); } }); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { var min = input.Children.FirstOrDefault(x => x.Name == "min")?.GetEx <long>() ?? long.MinValue; var max = input.Children.FirstOrDefault(x => x.Name == "max")?.GetEx <long>() ?? long.MaxValue; Enumerator.Enumerate <long>(input, (value, name) => { if (value < min || value > max) { throw new HyperlambdaException( $"'{value}' is not a valid number between {min} and {max} for [{name}]", true, 400, name); } }); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { Enumerator.Enumerate <string>(input, (value, name) => { if (!input.Children.Any(x2 => x2.Get <string>() == value)) { var legalValues = input.Children.Select(x2 => "'" + x2.Get <string>() + "'"); var legalValueString = string.Join(", ", legalValues.ToArray()); input.Clear(); throw new HyperlambdaException( $"'{value}' is not a valid enum of [{legalValueString}] for [{name}]", true, 400, name); } }); }
/// <summary> /// Implementation of slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to signal.</param> public void Signal(ISignaler signaler, Node input) { Enumerator.Enumerate <string>(input, (value, name) => { try { var addr = new MailAddress(value); if (addr.Address != value) { throw new ArgumentException($"'{value}' in [{name}] is not a valid email address"); // Verifying there are not funny configurations, creating name as first part } } catch { throw new ArgumentException($"'{value}' in [{name}] is not a valid email address"); // Verifying there are not funny configurations, creating name as first part } }); }
public TestReadWrite() { CH341registry = Enumerator.Enumerate().First(); }