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 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")); } }