public override bool Setup()
        {
            spiPort = YSpiPort.FirstSpiPort();
            if (spiPort == null)
            {
                Console.WriteLine("No Yocto-Spi detected");
                return(false);
            }

            YModule      module       = spiPort.get_module();
            string       errmsg       = "";
            string       serialNumber = module.get_serialNumber();
            YPowerOutput powerOutput  = YPowerOutput.FindPowerOutput(serialNumber + ".powerOutput");

            powerOutput.set_voltage(YPowerOutput.VOLTAGE_OUT3V3);
            spiPort.set_voltageLevel(YSpiPort.VOLTAGELEVEL_TTL3V);
            spiPort.set_spiMode("2000000,0,msb");
            spiPort.set_protocol("Frame:1ms");
            spiPort.set_ssPolarity(YSpiPort.SSPOLARITY_ACTIVE_LOW);
            module.saveToFlash();
            YAPI.Sleep(25, ref errmsg);
            spiPort.writeHex(SET_MODE_4);
            YAPI.Sleep(5, ref errmsg);

            string[] commands = { READ_STATUS, READ_STATUS, READ_STATUS, READ_ID, SET_ANGLES };
            Frame[]  result;
            if (!SendAndReceive(commands, out result))
            {
                Console.WriteLine("Failed to initialize SCL3300 (communication error)");
                return(false);
            }
            if (!_chip_ready)
            {
                Console.WriteLine("SCL3300 startup failed (rs={4})", result[2].rs);
                return(false);
            }
            if ((result[3].data & 0xff) != 0xc1)
            {
                Console.WriteLine("Unexpected SCL3300 identification (WHOAMI={0})", (result[3].data & 0xff));
                return(false);
            }
            if (!DecodeStatus(result[2]))
            {
                Console.WriteLine("SCL3300 Status bad, chip reset is required");
                return(false);
            }
            Console.WriteLine("SCL3300 is ready");
            return(true);
        }
Пример #2
0
        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();
        }
Пример #3
0
        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);
        }