public void TestEncodeDecode() { Encoder encoder = new Encoder(); encoder.SystemReset(); Assert.AreEqual(1,encoder.Count); encoder.SampleRate = 50; // Set to 50 Hz Assert.AreEqual(6,encoder.Count); Console.WriteLine(encoder); encoder.RequestFirmwareInformation(); Assert.AreEqual(9,encoder.Count); Console.WriteLine(encoder); //encoder.DigitalWrite(9,1); //encoder.AnalogWrite(15, 64); //Assert.AreEqual(15,encoder.Count); //encoder.DigitalWrite(11,1); //Assert.AreEqual(15,encoder.Count); //encoder.AnalogWrite(1, 768); //Assert.AreEqual(18,encoder.Count); Console.WriteLine(encoder); for (int i = 0; i < 16; i++) { for (int j = 0; j < 256; j++) { encoder.AnalogWrite(i, j ); } } // Console.WriteLine(encoder); encoder.DigitalWrite(new int[128]); encoder.DigitalWrite(new int[] { 1, 1, 0, 0, 0, 0, 0, 0}); Console.WriteLine(encoder); /// ------------------------------------ // Decode the formerly encoded stream Decoder decoder = new Decoder(); decoder.AnalogEvent += OnAnalog; decoder.DigitalEvent += OnDigital; decoder.SysexEvent += OnSysex; decoder.Parse(encoder.BaseStream); Assert.That (true); }
public void TestPartialData() { Console.WriteLine("Testing partial data insertion..."); Decoder decoder = new Decoder(); decoder.AnalogEvent += OnAnalog; decoder.DigitalEvent += OnDigital; decoder.SysexEvent += OnSysex; Stream stream = new MemoryStream(); stream.Write(new byte[] { 0xFF, 0xF0, 0x7A }, 0, 3); Console.WriteLine("First parse!"); decoder.Parse(stream); Console.WriteLine("Internal buffer {0}: {1}",decoder.buffer.Count.ToString(),BitConverter.ToString(decoder.buffer.ToArray())); stream.Close(); stream = new MemoryStream(); stream.Write(new byte[] { 0x14, 0x00, 0xF7 }, 0, 3); Console.WriteLine("Second parse!"); decoder.Parse(stream); Console.WriteLine("Internal buffer {0}: {1}",decoder.buffer.Count.ToString(),BitConverter.ToString(decoder.buffer.ToArray())); }