public void ta(PigpiodIf pigpiodIf, CancellationToken ct) { int h, b, e; string TEXT; byte[] recv = new byte[2048]; Console.WriteLine("\r\nSerial link tests."); /* this test needs RXD and TXD to be connected */ h = pigpiodIf.serial_open("/dev/ttyAMA0", 57600, 0); CHECK(10, 1, h, 0, 0, "serial open", ct); pigpiodIf.time_sleep(0.1); /* allow time for transmission */ b = pigpiodIf.serial_read((UInt32)h, recv); /* flush buffer */ b = pigpiodIf.serial_data_available((UInt32)h); CHECK(10, 2, b, 0, 0, "serial data available", ct); TEXT = @" To be, or not to be, that is the question - Whether 'tis Nobler in the mind to suffer The Slings and Arrows of outrageous Fortune, Or to take Arms against a Sea of troubles, "; var bytes = System.Text.Encoding.UTF8.GetBytes(TEXT); e = pigpiodIf.serial_write((UInt32)h, bytes); CHECK(10, 3, e, 0, 0, "serial write", ct); e = pigpiodIf.serial_write_byte((UInt32)h, 0xAA); e = pigpiodIf.serial_write_byte((UInt32)h, 0x55); e = pigpiodIf.serial_write_byte((UInt32)h, 0x00); e = pigpiodIf.serial_write_byte((UInt32)h, 0xFF); CHECK(10, 4, e, 0, 0, "serial write byte", ct); pigpiodIf.time_sleep(0.1); /* allow time for transmission */ b = pigpiodIf.serial_data_available((UInt32)h); CHECK(10, 5, b, bytes.Length + 4, 0, "serial data available", ct); recv = new byte[bytes.Length]; b = pigpiodIf.serial_read((UInt32)h, recv); CHECK(10, 6, b, bytes.Length, 0, "serial read", ct); recv = recv.Take(b).ToArray(); string text = System.Text.Encoding.UTF8.GetString(recv); CHECK(10, 7, string.Compare(TEXT, text), 0, 0, "serial read", ct); b = pigpiodIf.serial_read_byte((UInt32)h); CHECK(10, 8, b, 0xAA, 0, "serial read byte", ct); b = pigpiodIf.serial_read_byte((UInt32)h); CHECK(10, 9, b, 0x55, 0, "serial read byte", ct); b = pigpiodIf.serial_read_byte((UInt32)h); CHECK(10, 10, b, 0x00, 0, "serial read byte", ct); b = pigpiodIf.serial_read_byte((UInt32)h); CHECK(10, 11, b, 0xFF, 0, "serial read byte", ct); b = pigpiodIf.serial_data_available((UInt32)h); CHECK(10, 12, b, 0, 0, "serial data availabe", ct); e = pigpiodIf.serial_close((UInt32)h); CHECK(10, 13, e, 0, 0, "serial close", ct); }