You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;using System.Threading;//-------------------------------------------//WARNING ://-------------------------------------------//instead to call System.Diagnostics; //you need to call System.Diagnostics.Uart; only//otherwise you should have conflict between System.Diagnostics and System.Diagnostics.Uart//-------------------------------------------using System.Diagnostics.Uart;namespaceDebugToUart{publicclassProgram{publicstaticvoidMain(){DebugWritelnToUartDebug=new DebugWritelnToUart("COM6",57600);intcnt=0;while(true){//-------------------------------------------// Debug.xxx// works in same way ...//-------------------------------------------
Debug.WriteLine("Hello nanoFramework World >>"+cnt);cnt++;
Thread.Sleep(500);}}}}
class / DebugWritelnToUart.cs
/*// ----------------------------------------------------------------// Copyright (c) 2018 The nanoFramework project contributors// See LICENSE file in the project root for full license information.// ----------------------------------------------------------------// Valon Hoti @ Prishtine // Jul 23 - 2020 // this class made to work only on debug mode ...// ----------------------------------------------------------------// usage :// ---------------------------------------------------------------- DebugWritelnToUart debug = new DebugWritelnToUart("COM2", 57600); debug.WriteLine("Hello to uart ! \n"); if you do not want to use more this class you can also dispose like debug.Dispose();// ----------------------------------------------------------------// Warning :// ---------------------------------------------------------------- you need to choose what to use System.Diagnostics or System.Dianogstics.Uart you can not use both, just only ... */using System;namespace System.Diagnostics.Uart
{//-------------------------------------------// include references //-------------------------------------------// nanoFramework.Runtime.Events.dll// nanoFramework.System.Text.dll// Windows.Devices.SerialCommunication.dll// Windows.Storage.Stream.dll//-------------------------------------------using System.Diagnostics;using Windows.Devices.SerialCommunication;using Windows.Storage.Streams;publicclassDebugWritelnToUart:IDisposable{privateSerialDeviceuart;privateDataWriteruartoutput;/// <summary>/// Set which COM port you want to use and what baudrate/// </summary>/// <param name="Comuart"></param>/// <param name="BaudRate"></param>publicDebugWritelnToUart(stringComuart,uintBaudRate){
#if DEBUG
uart= SerialDevice.FromId(Comuart);
uart.WatchChar ='\n';
uart.BaudRate =BaudRate;
uart.Parity = SerialParity.None;
uart.StopBits = SerialStopBitCount.One;
uart.Handshake = SerialHandshake.None;
uart.DataBits =8;uartoutput=new DataWriter(uart.OutputStream);
uart.WriteTimeout =new TimeSpan(0,0,5);
#endif
}/// <summary>/// use in same way as Debug.Write/// </summary>/// <param name="message"></param>publicvoidWrite(stringmessage){
Debug.Write(message);
#if DEBUG
uartoutput.WriteString(message);
uartoutput.Store();
#endif
}/// <summary>/// use in same way as Debug.WriteLine/// </summary>/// <param name="message"></param>publicvoidWriteLine(stringmessage){
Debug.WriteLine(message);
#if DEBUG
uartoutput.WriteString(message+"\r\n");
uartoutput.Store();
#endif
}/// <summary>/// use in same way as Debug.Assert/// </summary>/// <param name="condition"></param>publicvoidAssert(boolcondition){
Debug.Assert(condition);
#if DEBUG
uartoutput.WriteString("Assert["+ condition.ToString()+"]"+"\r\n");
uartoutput.Store();
#endif
}/// <summary>/// use in same way as Debug.Assert/// </summary>/// <param name="condition"></param>/// <param name="message"></param>publicvoidAssert(boolcondition,stringmessage){
Debug.Assert(condition, message);
#if DEBUG
uartoutput.WriteString("Assert["+condition.ToString()+"], Message["+message+"]"+"\r\n");
uartoutput.Store();
#endif
}/// <summary>/// use in same way as Debug.Assert/// </summary>/// <param name="condition"></param>/// <param name="message"></param>/// <param name="detailedMessage"></param>publicvoidAssert(boolcondition,stringmessage,stringdetailedMessage){
Debug.Assert(condition, message , detailedMessage);
#if DEBUG
uartoutput.WriteString("Assert["+ condition.ToString()+"], Message["+message+"], DetailedMessage["+detailedMessage+"]"+"\r\n");
uartoutput.Store();
#endif
}publicvoidDispose(){
uart.Dispose();}}}