Witam, chce zmodyfikować trochę program terminala alby po starcie zapisywał wszystko do pliku log. Cała konfiguracja portów, transmisji itp znajduje sie w pliku ini. brakuje tylko miejsca zapisu logu i startu logowania. chciałbym aby program zaraz po uruchomieniu zapisywał mi do pliku to co odbierze. w załączeniu cały projekt programu. jeśli może mi ktoś to zmienić to bede wdzięczny, ja próbowałem zmienić ale cos mi to nie wychodzi, zakomentowałem linie które dodałem using System; using System.IO; using System.IO.Ports; using System.Collections; using System.Windows.Forms; // for Application.StartupPath namespace Termie { /// <summary> /// Persistent settings /// </summary> public class Settings { /// <summary> Port settings. </summary> public class Port { public static string PortName = "COM1"; public static int BaudRate = 115200; public static int DataBits = 8; public static System.IO.Ports.Parity Parity = System.IO.Ports.Parity.None; public static System.IO.Ports.StopBits StopBits = System.IO.Ports.StopBits.One; public static System.IO.Ports.Handshake Handshake = System.IO.Ports.Handshake.None; } /// <summary> Option settings. </summary> public class Option { public enum AppendType { AppendNothing, AppendCR, AppendLF, AppendCRLF } public static AppendType AppendToSend = AppendType.AppendCR; public static bool HexOutput = false; public static bool MonoFont = true; public static bool LocalEcho = true; public static bool StayOnTop = false; public static bool FilterUseCase = false; public static string LogFileName = ""; } /// <summary> /// Read the settings from disk. </summary> public static void Read() { IniFile ini = new IniFile(Application.StartupPath + "\\Termie.ini"); Port.PortName = ini.ReadValue("Port", "PortName", Port.PortName); Port.BaudRate = ini.ReadValue("Port", "BaudRate", Port.BaudRate); Port.DataBits = ini.ReadValue("Port", "DataBits", Port.DataBits); Port.Parity = (Parity)Enum.Parse(typeof(Parity), ini.ReadValue("Port", "Parity", Port.Parity.ToString())); Port.StopBits = (StopBits)Enum.Parse(typeof(StopBits), ini.ReadValue("Port", "StopBits", Port.StopBits.ToString())); Port.Handshake = (Handshake)Enum.Parse(typeof(Handshake), ini.ReadValue("Port", "Handshake", Port.Handshake.ToString())); Option.AppendToSend = (Option.AppendType)Enum.Parse(typeof(Option.AppendType), ini.ReadValue("Option", "AppendToSend", Option.AppendToSend.ToString())); Option.HexOutput = bool.Parse(ini.ReadValue("Option", "HexOutput", Option.HexOutput.ToString())); Option.MonoFont = bool.Parse(ini.ReadValue("Option", "MonoFont", Option.MonoFont.ToString())); Option.LocalEcho = bool.Parse(ini.ReadValue("Option", "LocalEcho", Option.LocalEcho.ToString())); Option.StayOnTop = bool.Parse(ini.ReadValue("Option", "StayOnTop", Option.StayOnTop.ToString())); Option.FilterUseCase = bool.Parse(ini.ReadValue("Option", "FilterUseCase", Option.FilterUseCase.ToString())); //Option.LogFileName = string.Parse(ini.ReadValue("Option", "LogFileName", Option.LogFileName.ToString())); } /// <summary> /// Write the settings to disk. </summary> public static void Write() { IniFile ini = new IniFile(Application.StartupPath + "\\Termie.ini"); ini.WriteValue("Port", "PortName", Port.PortName); ini.WriteValue("Port", "BaudRate", Port.BaudRate); ini.WriteValue("Port", "DataBits", Port.DataBits); ini.WriteValue("Port", "Parity", Port.Parity.ToString()); ini.WriteValue("Port", "StopBits", Port.StopBits.ToString()); ini.WriteValue("Port", "Handshake", Port.Handshake.ToString()); ini.WriteValue("Option", "AppendToSend", Option.AppendToSend.ToString()); ini.WriteValue("Option", "HexOutput", Option.HexOutput.ToString()); ini.WriteValue("Option", "MonoFont", Option.MonoFont.ToString()); ini.WriteValue("Option", "LocalEcho", Option.LocalEcho.ToString()); ini.WriteValue("Option", "StayOnTop", Option.StayOnTop.ToString()); ini.WriteValue("Option", "FilterUseCase", Option.FilterUseCase.ToString()); //ini.WriteValue("Option", "LogFileName", Option.FilterUseCase.ToString()); } } }
Copyright (c) 2008, David McClurg
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
" AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Copyright (c) 2008, David McClurg
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
" AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
C:\Documents and Settings\user\Pulpit\loger\Termie\bin\Debug\Termie.exe
C:\Documents and Settings\user\Pulpit\loger\Termie\bin\Debug\Termie.pdb
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\ResolveAssemblyReference.cache
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\Termie.AboutBox.resources
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\Termie.Form1.resources
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\Termie.Form2.resources
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\Termie.Properties.Resources.resources
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\GenerateResource.read.1.tlog
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\GenerateResource.write.1.tlog
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\Termie.exe
C:\Documents and Settings\user\Pulpit\loger\Termie\obj\Debug\Termie.pdb