/// <summary> /// Initialize this instance with standard settings. /// 9600:N:8:1, handshaking disabled. /// </summary> /// <param name="index">The port index - 1,2,...</param> public void Initialize(int index) { portName = "COM" + index.ToString() + ":"; baudRate = LineSpeed.Baud_9600; txFlowCTS = false; txFlowDSR = false; dtrControl = PinState.Disable; rxDSRsense = false; txContinue = true; txFlowXoff = false; rxFlowXoff = false; errReplace = false; nulDiscard = false; rtsControl = PinState.Disable; abortOnErr = false; xonLimit = 0; // 0=OS managed xoffLimit = 0; // 0=OS managed dataBits = ByteSize.Eight; parity = Parity.None; stopBits = StopBits.One; xonChar = (byte)CtrlChar.DC1; xoffChar = (byte)CtrlChar.DC3; errChar = (byte)'?'; eofChar = (byte)CtrlChar.SUB; evtChar = (byte)CtrlChar.NULL; handshake = Handshake.None; rxQueLen = 0; // 0=OS managed txQueLen = 0; // 0=OS managed txTmoMulti = 0; txTmoConst = 0; receiveMode = false; startup = 0; return; }
/// <summary> /// Initialize this instance with standard settings. /// 9600:N:8:1, handshaking disabled. /// </summary> /// <param name="index">The port index - 1,2,...</param> public void Initialize(int index) { portName = "COM" + index.ToString() + ":"; baudRate = LineSpeed.Baud_9600; txFlowCTS = false; txFlowDSR = false; dtrControl = PinState.Disable; rxDSRsense = false; txContinue = true; txFlowXoff = false; rxFlowXoff = false; errReplace = false; nulDiscard = false; rtsControl = PinState.Disable; abortOnErr = false; xonLimit = 0; // 0=OS managed xoffLimit = 0; // 0=OS managed dataBits = ByteSize.Eight; parity = Parity.None; stopBits = StopBits.One; xonChar = (byte) CtrlChar.DC1; xoffChar = (byte) CtrlChar.DC3; errChar = (byte) '?'; eofChar = (byte) CtrlChar.SUB; evtChar = (byte) CtrlChar.NULL; handshake = Handshake.None; rxQueLen = 0; // 0=OS managed txQueLen = 0; // 0=OS managed txTmoMulti = 0; txTmoConst = 0; receiveMode = false; return; }
/// <summary> /// Load the message definition list from a text file. /// </summary> public void Load(string fName) { // Quit if file doesn't exist. FileInfo fi = new FileInfo(fName); if (fi.Exists == false) { return; } // Open text definitions file in read-only mode. FileStream fs = new FileStream(fName, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); // Set file pointer to beginning of file. sr.BaseStream.Seek(0, SeekOrigin.Begin); string line = ""; string data = ""; while ((line = sr.ReadLine()) != null) { data = line.Substring(line.IndexOf(":") + 1); if (line.StartsWith("<Port Name>")) { this.portName = data; } else if (line.StartsWith("<Baud Rate>")) { this.baudRate = (LineSpeed)int.Parse(data); } else if (line.StartsWith("<CTS Flow>")) { this.txFlowCTS = bool.Parse(data); } else if (line.StartsWith("<DSR Flow>")) { this.txFlowDSR = bool.Parse(data); } else if (line.StartsWith("<DTR Ctrl>")) { this.dtrControl = (PinState)byte.Parse(data); } else if (line.StartsWith("<DSR Sense>")) { this.rxDSRsense = bool.Parse(data); } else if (line.StartsWith("<TX Continue>")) { this.txContinue = bool.Parse(data); } else if (line.StartsWith("<TX Xoff Flow>")) { this.txFlowXoff = bool.Parse(data); } else if (line.StartsWith("<RX Xoff Flow>")) { this.rxFlowXoff = bool.Parse(data); } else if (line.StartsWith("<Error Replace>")) { this.errReplace = bool.Parse(data); } else if (line.StartsWith("<Null Discard>")) { this.nulDiscard = bool.Parse(data); } else if (line.StartsWith("<RTS Control>")) { this.rtsControl = (PinState)byte.Parse(data); } else if (line.StartsWith("<Abort On Error>")) { this.abortOnErr = bool.Parse(data); } else if (line.StartsWith("<Xon Limit>")) { this.xonLimit = short.Parse(data); } else if (line.StartsWith("<Xoff Limit>")) { this.xoffLimit = short.Parse(data); } else if (line.StartsWith("<Bits/Byte>")) { this.dataBits = (ByteSize)byte.Parse(data); } else if (line.StartsWith("<Parity>")) { this.parity = (Parity)byte.Parse(data); } else if (line.StartsWith("<Stop Bits>")) { this.stopBits = (StopBits)byte.Parse(data); } else if (line.StartsWith("<Xon Char>")) { this.xonChar = byte.Parse(data); } else if (line.StartsWith("<Xoff Char>")) { this.xoffChar = byte.Parse(data); } else if (line.StartsWith("<Error Char>")) { this.errChar = byte.Parse(data); } else if (line.StartsWith("<EOF Char>")) { this.eofChar = byte.Parse(data); } else if (line.StartsWith("<Event Char>")) { this.evtChar = byte.Parse(data); } else if (line.StartsWith("<Handshaking>")) { this.handshake = (Handshake)byte.Parse(data); } else if (line.StartsWith("<RX Q Length>")) { this.rxQueLen = int.Parse(data); } else if (line.StartsWith("<TX Q Length>")) { this.txQueLen = int.Parse(data); } else if (line.StartsWith("<TX Timeout(M)>")) { this.txTmoMulti = uint.Parse(data); } else if (line.StartsWith("<TX Timeout(C)>")) { this.txTmoConst = uint.Parse(data); } else if (line.StartsWith("<Receive Mode>")) { this.receiveMode = bool.Parse(data); } else if (line.StartsWith("<Startup>")) { this.startup = uint.Parse(data); } } // FClose. fs.Close(); return; }
/// <summary> /// Load the message definition list from a text file. /// </summary> public void Load(string fName) { // Quit if file doesn't exist. FileInfo fi = new FileInfo(fName); if(fi.Exists == false) return; // Open text definitions file in read-only mode. FileStream fs = new FileStream(fName, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); // Set file pointer to beginning of file. sr.BaseStream.Seek(0, SeekOrigin.Begin); string line = ""; string data = ""; while((line = sr.ReadLine()) != null) { data = line.Substring(line.IndexOf(":")+1); if(line.StartsWith("<Port Name>")) this.portName = data; if(line.StartsWith("<Baud Rate>")) this.baudRate = (LineSpeed) int.Parse(data); if(line.StartsWith("<CTS Flow>")) this.txFlowCTS = bool.Parse(data); if(line.StartsWith("<DSR Flow>")) this.txFlowDSR = bool.Parse(data); if(line.StartsWith("<DTR Ctrl>")) this.dtrControl = (PinState) byte.Parse(data); if(line.StartsWith("<DSR Sense>")) this.rxDSRsense = bool.Parse(data); if(line.StartsWith("<TX Continue>")) this.txContinue = bool.Parse(data); if(line.StartsWith("<TX Xoff Flow>")) this.txFlowXoff = bool.Parse(data); if(line.StartsWith("<RX Xoff Flow>")) this.rxFlowXoff = bool.Parse(data); if(line.StartsWith("<Error Replace>")) this.errReplace = bool.Parse(data); if(line.StartsWith("<Null Discard>")) this.nulDiscard = bool.Parse(data); if(line.StartsWith("<RTS Control>")) this.rtsControl = (PinState) byte.Parse(data); if(line.StartsWith("<Abort On Error>")) this.abortOnErr = bool.Parse(data); if(line.StartsWith("<Xon Limit>")) this.xonLimit = short.Parse(data); if(line.StartsWith("<Xoff Limit>")) this.xoffLimit = short.Parse(data); if(line.StartsWith("<Bits/Byte>")) this.dataBits = (ByteSize) byte.Parse(data); if(line.StartsWith("<Parity>")) this.parity = (Parity) byte.Parse(data); if(line.StartsWith("<Stop Bits>")) this.stopBits = (StopBits) byte.Parse(data); if(line.StartsWith("<Xon Char>")) this.xonChar = byte.Parse(data); if(line.StartsWith("<Xoff Char>")) this.xoffChar = byte.Parse(data); if(line.StartsWith("<Error Char>")) this.errChar = byte.Parse(data); if(line.StartsWith("<EOF Char>")) this.eofChar = byte.Parse(data); if(line.StartsWith("<Event Char>")) this.evtChar = byte.Parse(data); if(line.StartsWith("<Handshaking>")) this.handshake = (Handshake) byte.Parse(data); if(line.StartsWith("<RX Q Length>")) this.rxQueLen = int.Parse(data); if(line.StartsWith("<TX Q Length>")) this.txQueLen = int.Parse(data); if(line.StartsWith("<TX Timeout(M)>")) this.txTmoMulti = uint.Parse(data); if(line.StartsWith("<TX Timeout(C)>")) this.txTmoConst = uint.Parse(data); if(line.StartsWith("<Receive Mode>")) this.receiveMode = bool.Parse(data); } // FClose. fs.Close(); return; }