예제 #1
0
        public void t5(PigpiodIf pigpiodIf, CancellationToken ct)
        {
            PigpiodIf.Callback callback = null;
            try
            {
                int BAUD = 4800;

                string TEXT = @"
Now is the winter of our discontent
Made glorious summer by this sun of York;
And all the clouds that lour'd upon our house
In the deep bosom of the ocean buried.
Now are our brows bound with victorious wreaths;
Our bruised arms hung up for monuments;
Our stern alarums changed to merry meetings,
Our dreadful marches to delightful measures.
Grim - visaged war hath smooth'd his wrinkled front;
And now, instead of mounting barded steeds
To fright the souls of fearful adversaries,
He capers nimbly in a lady's chamber
To the lascivious pleasing of a lute.
";

                TEXT = TEXT.Replace("\r\n", "\n");

                PigpiodIf.GpioPulse[] wf = new PigpiodIf.GpioPulse[]
                {
                    new PigpiodIf.GpioPulse()
                    {
                        gpioOn = 1 << GPIO, gpioOff = 0, usDelay = 10000
                    },
                    new PigpiodIf.GpioPulse()
                    {
                        gpioOn = 0, gpioOff = 1 << GPIO, usDelay = 30000
                    },
                    new PigpiodIf.GpioPulse()
                    {
                        gpioOn = 1 << GPIO, gpioOff = 0, usDelay = 60000
                    },
                    new PigpiodIf.GpioPulse()
                    {
                        gpioOn = 0, gpioOff = 1 << GPIO, usDelay = 100000
                    },
                };

                int e, oc, c, wid;

                byte[] recv = new byte[2048];

                Console.WriteLine("\r\nWaveforms & serial read/write tests.");

                int t5_count = 0;
                callback = pigpiodIf.callback(GPIO, PigpiodIf.FALLING_EDGE, (gpio, level, tick, user) =>
                {
                    t5_count++;
                });

                pigpiodIf.set_mode(GPIO, PigpiodIf.PI_OUTPUT);

                e = pigpiodIf.wave_clear();
                CHECK(5, 1, e, 0, 0, "callback, set mode, wave clear", ct);

                e = pigpiodIf.wave_add_generic(wf);
                CHECK(5, 2, e, 4, 0, "pulse, wave add generic", ct);

                wid = pigpiodIf.wave_create();
                e   = pigpiodIf.wave_send_repeat((UInt32)wid);
                if (e < 14)
                {
                    CHECK(5, 3, e, 9, 0, "wave tx repeat", ct);
                }
                else
                {
                    CHECK(5, 3, e, 19, 0, "wave tx repeat", ct);
                }

                oc = t5_count;
                pigpiodIf.time_sleep(5.05);
                c = t5_count - oc;
                CHECK(5, 4, c, 50, 2, "callback", ct);

                e = pigpiodIf.wave_tx_stop();
                CHECK(5, 5, e, 0, 0, "wave tx stop", ct);

                e = pigpiodIf.bb_serial_read_open(GPIO, (UInt32)BAUD, 8);
                CHECK(5, 6, e, 0, 0, "serial read open", ct);

                pigpiodIf.wave_clear();
                var bytes = System.Text.Encoding.UTF8.GetBytes(TEXT);
                e = pigpiodIf.wave_add_serial(GPIO, (UInt32)BAUD, 8, 2, 5000000, bytes);
                CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial", ct);

                wid = pigpiodIf.wave_create();
                e   = pigpiodIf.wave_send_once((UInt32)wid);
                if (e < 6964)
                {
                    CHECK(5, 8, e, 6811, 0, "wave tx start", ct);
                }
                else
                {
                    CHECK(5, 8, e, 7116, 0, "wave tx start", ct);
                }

                oc = t5_count;
                pigpiodIf.time_sleep(3);
                c = t5_count - oc;
                CHECK(5, 9, c, 0, 0, "callback", ct);

                oc = t5_count;
                while (pigpiodIf.wave_tx_busy() != 0)
                {
                    pigpiodIf.time_sleep(0.1);
                }
                pigpiodIf.time_sleep(0.1);
                c = t5_count - oc;
                CHECK(5, 10, c, 1702, 0, "wave tx busy, callback", ct);

                c    = pigpiodIf.bb_serial_read(GPIO, recv);
                recv = recv.Take(c).ToArray();
                string text = System.Text.Encoding.UTF8.GetString(recv);
                CHECK(5, 11, string.Compare(TEXT, text), 0, 0, "wave tx busy, serial read", ct);

                e = pigpiodIf.bb_serial_read_close(GPIO);
                CHECK(5, 12, e, 0, 0, "serial read close", ct);

                c = pigpiodIf.wave_get_micros();
                CHECK(5, 13, c, 6158148, 0, "wave get micros", ct);

                c = pigpiodIf.wave_get_high_micros();
                if (c > 6158148)
                {
                    c = 6158148;
                }
                CHECK(5, 14, c, 6158148, 0, "wave get high micros", ct);

                c = pigpiodIf.wave_get_max_micros();
                CHECK(5, 15, c, 1800000000, 0, "wave get max micros", ct);

                c = pigpiodIf.wave_get_pulses();
                CHECK(5, 16, c, 3405, 0, "wave get pulses", ct);

                c = pigpiodIf.wave_get_high_pulses();
                CHECK(5, 17, c, 3405, 0, "wave get high pulses", ct);

                c = pigpiodIf.wave_get_max_pulses();
                CHECK(5, 18, c, 12000, 0, "wave get max pulses", ct);

                c = pigpiodIf.wave_get_cbs();
                if (c < 6963)
                {
                    CHECK(5, 19, c, 6810, 0, "wave get cbs", ct);
                }
                else
                {
                    CHECK(5, 19, c, 7115, 0, "wave get cbs", ct);
                }

                c = pigpiodIf.wave_get_high_cbs();
                if (c < 6963)
                {
                    CHECK(5, 20, c, 6810, 0, "wave get high cbs", ct);
                }
                else
                {
                    CHECK(5, 20, c, 7115, 0, "wave get high cbs", ct);
                }

                c = pigpiodIf.wave_get_max_cbs();
                CHECK(5, 21, c, 25016, 0, "wave get max cbs", ct);
            }
            finally
            {
                pigpiodIf.callback_cancel(callback);
            }
        }