public void ArrivalCallback(YModule module) { // Check if the device features a SPI Port for (int i = 0; i < module.functionCount(); i++) { if (module.functionType(i) == "SpiPort") { // SPI Port found, use it string identifier = module.get_serialNumber() + "." + module.functionId(i); Log("Using " + identifier); spiPort = YSpiPort.FindSpiPort(identifier); spiPort.set_spiMode("0,0,lsb"); spiPort.reset(); } } }
static void Main(string[] args) { string errmsg = ""; string target; int value; YSpiPort spiPort; if (args.Length < 2) { usage(); } target = args[0].ToUpper(); value = Convert.ToInt32(args[1]); if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS) { Console.WriteLine("RegisterHub error: " + errmsg); Environment.Exit(0); } if (target == "ANY") { spiPort = YSpiPort.FirstSpiPort(); if (spiPort == null) { Console.WriteLine("No module connected (check USB cable) "); Environment.Exit(0); } target = spiPort.get_module().get_serialNumber(); } spiPort = YSpiPort.FindSpiPort(target + ".spiPort"); if (spiPort.isOnline()) { spiPort.set_spiMode("250000,3,msb"); spiPort.set_ssPolarity(YSpiPort.SSPOLARITY_ACTIVE_LOW); spiPort.set_protocol("Frame:5ms"); spiPort.reset(); // do not forget to configure the powerOutput of the Yocto-SPI // ( for SPI7SEGDISP8.56 powerOutput need to be set at 5v ) Console.WriteLine("****************************"); Console.WriteLine("* make sure voltage levels *"); Console.WriteLine("* are properly configured *"); Console.WriteLine("****************************"); spiPort.writeHex("0c01"); // Exit from shutdown state spiPort.writeHex("09ff"); // Enable BCD for all digits spiPort.writeHex("0b07"); // Enable digits 0-7 (=8 in total) spiPort.writeHex("0a0a"); // Set medium brightness for (int i = 1; i <= 8; i++) { int digit = value % 10; // digit value spiPort.writeArray(new List <int> { i, digit }); value = value / 10; } } else { Console.WriteLine("Module not connected"); } Console.WriteLine("check identification and USB cable"); YAPI.FreeAPI(); }
public override async Task <int> Run() { try { await YAPI.RegisterHub(HubURL); YSpiPort spiPort; int value = Convert.ToInt32(Value); if (Target.ToLower() == "any") { spiPort = YSpiPort.FirstSpiPort(); if (spiPort == null) { WriteLine("No module connected (check USB cable) "); return(-1); } Target = await(await spiPort.get_module()).get_serialNumber(); } spiPort = YSpiPort.FindSpiPort(Target + ".spiPort"); if (await spiPort.isOnline()) { await spiPort.set_spiMode("250000,3,msb"); await spiPort.set_ssPolarity(YSpiPort.SSPOLARITY_ACTIVE_LOW); await spiPort.set_protocol("Frame:5ms"); await spiPort.reset(); // do not forget to configure the powerOutput of the Yocto-SPI // ( for SPI7SEGDISP8.56 powerOutput need to be set at 5v ) await spiPort.writeHex("0c01"); // Exit from shutdown state await spiPort.writeHex("09ff"); // Enable BCD for all digits await spiPort.writeHex("0b07"); // Enable digits 0-7 (=8 in total) await spiPort.writeHex("0a0a"); // Set medium brightness for (int i = 1; i <= 8; i++) { int digit = value % 10; // digit value await spiPort.writeArray(new List <int> { i, digit }); value = value / 10; } WriteLine("Done."); } else { WriteLine("Module not connected (check identification and USB cable)"); } } catch (YAPI_Exception ex) { WriteLine("error: " + ex.Message); } YAPI.FreeAPI(); return(0); }