我只想将DateTime(HH:mm:ss)和0
或1
写成文本文件中的一行。
0
和UCAST
,则会显示 =g
,如果是,则我想写DateTime
和1
。这是收到邮件的DateTime
。
我的问题是我只获得了DateTIme
和1
,但却从未获得DateTime
和0
。该行始终由新DateTime
和1
替换,因此旧版本不再存在。
private void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
recievdata = SerialPort.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
using (Stream stream2 = File.Open(path, FileMode.OpenOrCreate))
using (StreamWriter sWriter1 = new StreamWriter(stream2))
{
if (recievdata.Contains("UCAST") && recievdata.Contains("=g"))
{
sWriter1.Write(DateTime.Now.ToString("HH:mm:ss"));
sWriter1.Write(" ; ");
sWriter1.WriteLine(1);
if (SleepMovChar.InvokeRequired)
{
SleepMovChar.Invoke(new MethodInvoker(delegate
{ SleepMovChar.Series["Bevægelse"].Points.AddXY(xValue = DateTime.Now.ToString("HH:mm:ss"), 1); }));
SleepMovChar.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
}
}
else
{
sWriter1.Write(DateTime.Now.ToString("HH:mm:ss"));
sWriter1.Write(" ; ");
sWriter1.WriteLine(0);
timer1.Tick += new EventHandler(timer1_Tick);
}
}
}