using System; using System.Collections.Generic; using System.Linq; using System.Text; using Cosmos.Hardware; using Cosmos.Core; namespace StructTest { /// /// Enables logging to a Com Port. /// public class Logger { private readonly Cosmos.Core.IOGroup.COM iop; /// /// The default constructor. /// /// This should be either 1, 2, 3, or 4. public Logger(byte comPort) { iop = new Cosmos.Core.IOGroup.COM(comPort); Initialize(); } private void Initialize() { iop.InterruptEnable.Byte = 0x00; iop.LineControl.Byte = 0x80; iop.Data.Byte = 0x03; iop.InterruptEnable.Byte = 0x00; iop.LineControl.Byte = 0x03; iop.FIFOControl.Byte = 0xC7; iop.ModemControl.Byte = 0x0B; } public void WriteLine(string s) { WriteString(s + "\r\n"); } private int IsTransmitEmpty() { return iop.LineStatus.Byte & 0x20; } /// /// Writes the specified byte to the Log. /// /// The byte to write. public void WriteData(byte b) { // Empty loop, will allow us to timeout for (uint i = 0; i < 1000 && (IsTransmitEmpty() == 0); i++) ; iop.Data.Byte = b; } /// /// Writes the specified string to the Log. /// /// The string to write. public void WriteString(string s) { for (int i = 0; i < s.Length; i++) { WriteData((byte)s[i]); } } } }