public void TestBootload() { using (_device = FTDevice.Open()) { // reset device _device.SetBitMode(FTBitMode.CBUSBitBang, 0xF0); Thread.Sleep(10); _device.SetBitMode(FTBitMode.CBUSBitBang, 0xFF); Thread.Sleep(100); // empty any possible leftover data in the rx/tx queue // this is necessary because the serialtest program is blasting the usart with data // and some of it lives on after the reset in the ft queues _device.Purge(); _device.SetFlowControl(FTFlowControl.None); _device.SetDataCharacteristics(8, 1, FTParity.None); _device.SetBaudRate(19200); SendHELO(); ReceiveEHLO(); EnterProgrammingMode(); ParseHEX("serialtest.hex"); WriteImage(); VerifyImage(); LeaveProgrammingMode(); _device.SetBaudRate(38400); _device.WaitFor(FTEvent.RxChar); var msg = new byte[10]; _device.ReadFully(msg, 0, 10); var text = Encoding.ASCII.GetString(msg); Assert.AreEqual("serialtest", text); } }
public void TestBitMode() { using (var dev = FTDevice.Open()) { dev.SetBitMode(FTBitMode.CBUSBitBang, 0xF0); var val = dev.GetBitMode(); Assert.AreEqual(0xF0, val); } }
public void TestOpen() { using (var dev = FTDevice.Open()) { Assert.IsNotNull(dev); Assert.IsNotNull(dev.Info); Assert.AreEqual(dev.Index, dev.Info.Index); Assert.IsTrue(dev.Info.IsOpen); } }
public void TestDataCharacteristics() { using (var dev = FTDevice.Open(0)) { // throws on invalid data bits value Assert.Throws <ArgumentException>(() => dev.SetDataCharacteristics(1, 1, FTParity.None)); // throws on invalid stop bits value Assert.Throws <ArgumentException>(() => dev.SetDataCharacteristics(8, 5, FTParity.None)); Assert.DoesNotThrow(() => dev.SetDataCharacteristics(8, 1, FTParity.None)); } }
public void TestResetWriteRead() { using (FTDevice dev = FTDevice.Open(0)) { // reset dev.SetBitMode(FTBitMode.CBUSBitBang, 0xF0); Thread.Sleep(10); dev.SetBitMode(FTBitMode.CBUSBitBang, 0xFF); // allow some time for startup Thread.Sleep(100); // send hello to bootloader dev.SetBaudRate(19200); var data = new[] { (byte)'1', (byte)' ' }; dev.WriteFully(data, 0, 2); // read ehlo var buf = new byte[9]; int r = dev.ReadFully(buf, 0, 9); Assert.AreEqual(9, r); var text = Encoding.ASCII.GetString(buf); Assert.IsTrue(text.Contains("AVR ISP")); } }