仅供参考

This commit is contained in:
春风过客 2023-09-16 09:28:31 +08:00
parent 372e7d30f9
commit 7185fb99e2
16 changed files with 855 additions and 362 deletions

View File

@ -26,31 +26,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathADCP))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathADCP, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathADCP))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathADCP, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathADCP, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch(Exception ex)
{
using (FileStream fs = new FileStream(LogPathADCP, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteADCPError:" + ex.Message);
}
return success;
@ -60,31 +67,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathCO2))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathCO2, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathCO2))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathCO2, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathCO2, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathCO2, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteCO2Error:" + ex.Message);
}
return success;
@ -94,34 +108,40 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathCTD))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathCTD, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathCTD))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathCTD, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathCTD, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch(Exception ex)
{
using (FileStream fs = new FileStream(LogPathCTD, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteCTDError:" + ex.Message);
}
return success;
}
@ -129,31 +149,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathDZ))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathDZ, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathDZ))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathDZ, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathDZ, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch(Exception ex)
{
using (FileStream fs = new FileStream(LogPathDZ, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteDZError:" + ex.Message);
}
return success;
@ -163,31 +190,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathGDFL))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathGDFL, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathGDFL))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathGDFL, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathGDFL, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch(Exception ex)
{
using (FileStream fs = new FileStream(LogPathGDFL, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteGDFLError:" + ex.Message);
}
return success;
@ -197,31 +231,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathMulti))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathMulti, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathMulti))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathMulti, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathMulti, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch(Exception ex)
{
using (FileStream fs = new FileStream(LogPathMulti, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteMultiError:" + ex.Message);
}
return success;
@ -231,31 +272,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathOther))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathOther, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathOther))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathOther, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathOther, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathOther, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteOtherError:" + ex.Message);
}
return success;
@ -265,31 +313,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathCamAndVid))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathCamAndVid, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathCamAndVid))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathCamAndVid, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathCamAndVid, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathCamAndVid, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteCamAndVidError:" + ex.Message);
}
return success;
@ -299,31 +354,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathMQTT))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathMQTT, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathMQTT))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathMQTT, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathMQTT, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathMQTT, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteMQTTError:" + ex.Message);
}
return success;
@ -333,31 +395,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorDZ))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorDZ, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorDZ))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorDZ, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorDZ, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorDZ, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorDZError:" + ex.Message);
}
return success;
@ -367,31 +436,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorGDFL))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorGDFL, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorGDFL))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorGDFL, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorGDFL, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorGDFL, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorGDFLError:" + ex.Message);
}
return success;
@ -401,31 +477,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorEXO2))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorEXO2, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorEXO2))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorEXO2, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorEXO2, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorEXO2, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorEXO2Error:" + ex.Message);
}
return success;
@ -435,31 +518,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorCTD))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorCTD, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorCTD))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorCTD, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorCTD, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorCTD, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorCTDError:" + ex.Message);
}
return success;
@ -469,31 +559,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorADCP))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorADCP, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorADCP))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorADCP, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorADCP, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorADCP, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorADCPError:" + ex.Message);
}
return success;
@ -503,31 +600,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorCO2))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorCO2, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorCO2))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorCO2, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorCO2, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorCO2, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorCO2Error:" + ex.Message);
}
return success;
@ -537,31 +641,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorCamAndVid))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorCamAndVid, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorCamAndVid))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorCamAndVid, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorCamAndVid, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch (Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorCamAndVid, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorCamAndVidError:" + ex.Message);
}
return success;
@ -571,31 +682,38 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
bool success = false;
if (File.Exists(LogPathErrorOther))
try
{
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorOther, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
if (File.Exists(LogPathErrorOther))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
//追加文件
//由于设置了文件共享模式为允许随后写入,所以即使多个线程同时写入文件,也会等待之前的线程写入结束之后再执行,而不会出现错误
using (FileStream fs = new FileStream(LogPathErrorOther, FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
else
{
using (FileStream fs = new FileStream(LogPathErrorOther, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
}
}
else
catch(Exception ex)
{
using (FileStream fs = new FileStream(LogPathErrorOther, FileMode.CreateNew, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
{
//开始写入
sw.WriteLine(DateTime.Now + ": " + needWriteInfo);
success = true;
}
}
Console.WriteLine("WriteErrorOtherError:" + ex.Message);
}
return success;

View File

@ -725,7 +725,7 @@ namespace ZTTMS_Manage_yibayiyi_20230320
#endregion
private void MqttConnectAsync()
private bool MqttConnectAsync()
{
try
{
@ -748,11 +748,15 @@ namespace ZTTMS_Manage_yibayiyi_20230320
mqttClient.ApplicationMessageReceivedAsync += MqttClient_ApplicationMessageReceivedAsync;
Task task = mqttClient.ConnectAsync(mqttClientOptions, CancellationToken.None);
task.Wait();
return true;
}
catch (Exception ex)
{
Console.WriteLine($"Mqtt客户端尝试连接出错{ex.Message}");
EveryDayLog.WriteMQTT($"Mqtt客户端尝试连接出错{ex.Message}");
return false;
}
}
@ -794,15 +798,16 @@ namespace ZTTMS_Manage_yibayiyi_20230320
//建立连接
public void Connect()
public bool Connect()
{
if (string.IsNullOrEmpty(Server) && Port == 0)
{
Console.WriteLine("IP或端口未赋值");
return;
return false;
}
MqttConnectAsync();
bool result=MqttConnectAsync();
return result;
}

View File

@ -258,12 +258,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetGDFL()
{
string[] data = new string[6] { "", "", "", "", "", "" };
MySqlDataReader dataReader = null;
try
{
string serialnumber = "";
string sql = $"select * from tb_gdflstateinfo_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
serialnumber = dataReader[5].ToString();
@ -328,6 +329,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetGDFLError:" + ex.Message);
EveryDayLog.WriteMQTT("GetGDFLError:" + ex.Message);
}
finally
{
if(dataReader!= null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -338,12 +347,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
string[] data = new string[27];
for (int i = 0; i < data.Length; i++)
data[i] = "";
MySqlDataReader dataReader = null;
try
{
string serialnumber = "";
string sql = $"select * from tb_workstateinfo_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
serialnumber = dataReader[5].ToString();
@ -601,6 +611,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetDZError:" + ex.Message);
EveryDayLog.WriteMQTT("GetDZError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -612,13 +630,16 @@ namespace ZTTMS_Manage_yibayiyi_20230320
for (int i = 0; i < data.Length; i++)
data[i] = "";
MySqlDataReader dataReader = null;
MySqlDataReader dataReaderState = null;
try
{
string serialnumber = "";
string sql = $"select * from tb_outputstateinfo_data order by record_time desc limit 1;";
string sqlState = $"select * from tb_stateinfo_state where serialnumber!='' order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
MySqlDataReader dataReaderState = MySQL.ExecuteReader(sqlState);
dataReader = MySQL.ExecuteReader(sql);
dataReaderState = MySQL.ExecuteReader(sqlState);
if (dataReader.Read())
{
serialnumber = dataReader[5].ToString();
@ -945,6 +966,20 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetDZPortStateError:" + ex.Message);
EveryDayLog.WriteMQTT("GetDZPortStateError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
if(dataReaderState!=null)
{
dataReaderState.Close();
dataReaderState.Dispose();
}
}
return data;
}
@ -953,12 +988,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetEXO2Info()
{
string[] data = new string[6] { "", "", "", "", "", "" };
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_multi_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -997,6 +1033,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetEXO2InfoError:" + ex.Message);
EveryDayLog.WriteMQTT("GetEXO2InfoError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1005,12 +1049,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetEXO2Data()
{
string[] data = new string[6] { "", "", "", "", "", "" };
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_multi_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -1096,6 +1141,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetEXO2DataError:" + ex.Message);
EveryDayLog.WriteMQTT("GetEXO2DataError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1104,12 +1157,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetCO2Info()
{
string[] data = new string[6] { "", "", "", "", "", "" };
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_co2_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -1183,6 +1237,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetCO2InfoError:" + ex.Message);
EveryDayLog.WriteMQTT("GetCO2InfoError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1191,12 +1253,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetCO2Data()
{
string[] data = new string[1] { "" };
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_co2_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -1227,6 +1290,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetCO2DataError:" + ex.Message);
EveryDayLog.WriteMQTT("GetCO2DataError:" + ex.Message);
}
finally
{
if(dataReader!= null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1235,12 +1306,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetCTDInfo()
{
string[] data = new string[6] { "", "", "", "", "", "" };
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_ctd_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -1279,6 +1351,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetCTDInfoError:" + ex.Message);
EveryDayLog.WriteMQTT("GetCTDInfoError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1287,12 +1367,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetCTDData()
{
string[] data = new string[3] { "", "", "" };
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_ctd_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -1345,6 +1426,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetCTDDataError:" + ex.Message);
EveryDayLog.WriteMQTT("GetCTDDataError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1353,12 +1442,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetADCPInfo()
{
string[] data = new string[6] { "", "", "", "", "", "" };
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_adcp_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -1397,6 +1487,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetADCPInfoError:" + ex.Message);
EveryDayLog.WriteMQTT("GetADCPInfoError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1408,11 +1506,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
for (int i = 0; i < data.Length; i++)
data[i] = "";
MySqlDataReader dataReader = null;
try
{
string devicenumber = "";
string sql = $"select * from tb_adcp_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
devicenumber = dataReader[2].ToString();
@ -1586,6 +1686,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetADCPDataError:" + ex.Message);
EveryDayLog.WriteMQTT("GetADCPDataError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}
@ -1594,12 +1702,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public string[] GetYX()
{
string[] data = new string[10] { "", "", "", "", "", "", "", "", "", "" };
MySqlDataReader dataReader = null;
try
{
string serialnumber = "";
string sql = $"select * from tb_camandvid_data order by record_time desc limit 1;";
MySqlDataReader dataReader = MySQL.ExecuteReader(sql);
dataReader = MySQL.ExecuteReader(sql);
if (dataReader.Read())
{
serialnumber = dataReader[2].ToString();
@ -1759,6 +1868,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
Console.WriteLine("GetGDFLError:" + ex.Message);
EveryDayLog.WriteMQTT("GetGDFLError:" + ex.Message);
}
finally
{
if(dataReader!=null)
{
dataReader.Close();
dataReader.Dispose();
}
}
return data;
}

View File

@ -6,6 +6,7 @@ using Google.Protobuf.WellKnownTypes;
using Gst;
using Gst.Base;
using MySql.Data.MySqlClient;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json;
using Org.BouncyCastle.Utilities;
using Pango;
@ -212,7 +213,7 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public static RelayControlForm relayControlForm = new RelayControlForm();
public static OutputStatusInfoDataForm outputStatusInfoDataForm = new OutputStatusInfoDataForm();
public static OtherSettingForm otherSettingForm = new OtherSettingForm();
PhotoelectricSeparationDataForm photoelectricSeparationDataForm = new PhotoelectricSeparationDataForm();
public static PhotoelectricSeparationDataForm photoelectricSeparationDataForm = new PhotoelectricSeparationDataForm();
public static OutputPortStateData outputPortStateData = new OutputPortStateData();
@ -478,11 +479,11 @@ namespace ZTTMS_Manage_yibayiyi_20230320
EveryDayLog.WriteOther("定时器(生成化学数据记录小时级)已开启!");
Console.WriteLine("定时器(生成化学数据记录小时级)已开启!");
timerSendNorth.Enabled = true;
timerSendNorth.Interval = 60 * 1000;
timerSendNorth.Start();
EveryDayLog.WriteOther("定时器(常规水下设备信息上报)已开启!");
Console.WriteLine("定时器(常规水下设备信息上报)已开启!");
//timerSendNorth.Enabled = true;
//timerSendNorth.Interval = 60 * 1000;
//timerSendNorth.Start();
//EveryDayLog.WriteOther("定时器(常规水下设备信息上报)已开启!");
//Console.WriteLine("定时器(常规水下设备信息上报)已开启!");
////var watch = Stopwatch.StartNew();
////SendNorth();
@ -4316,7 +4317,7 @@ namespace ZTTMS_Manage_yibayiyi_20230320
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
public void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (Others.g_socketSend != null)
{
@ -5318,9 +5319,9 @@ namespace ZTTMS_Manage_yibayiyi_20230320
dataHX2[4] = time.ToString("yyyy-MM-dd");
dataHX2[5] = time.ToString("HH:mm:ss");
for (int i = 0; i < 13; i++)
for (int i = 0; i < 12; i++)
{
if (i != 12)
if (i != 11)
{
dataHX[2] += dataHX2[i] + ",";
}
@ -5524,9 +5525,9 @@ namespace ZTTMS_Manage_yibayiyi_20230320
dataHX2[4] = time.ToString("yyyy-MM-dd");
dataHX2[5] = time.ToString("HH:mm:ss");
for (int i = 0; i < 13; i++)
for (int i = 0; i < 12; i++)
{
if (i != 12)
if (i != 11)
{
dataHX[2] += dataHX2[i] + ",";
}
@ -5753,9 +5754,9 @@ namespace ZTTMS_Manage_yibayiyi_20230320
dataHX2[4] = time.ToString("yyyy-MM-dd");
dataHX2[5] = time.ToString("HH:mm:ss");
for (int i = 0; i < 13; i++)
for (int i = 0; i < 12; i++)
{
if (i != 12)
if (i != 11)
{
dataHX[2] += dataHX2[i] + ",";
}
@ -5803,7 +5804,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
try
{
ItfNHelper itfNHelper = new ItfNHelper(ip, port, userName, password, topic, subName);
itfNHelper.test.Connect();
bool result=itfNHelper.test.Connect();
if (!result)
{
Console.WriteLine("SendNorthError:Can not connect!");
EveryDayLog.WriteErrorOther("SendNorthError:Can not connect!");
return;
}
string[] basicInfo = new string[4]
{

View File

@ -13,8 +13,8 @@ namespace ZTTMS_Manage_yibayiyi_20230320
{
class MySQL
{
//public static string connectionString = @"server=41.244.68.54;port=3306;user=root;password=zttZTT123!;database=daojiao;sslMode=none;charset=utf8;pooling=true;max pool size=1024;connect timeout = 20;AllowPublicKeyRetrieval=true;";
public static string connectionString = @"server=127.0.0.1;port=3306;user=root;password=ztt12345;database=daojiao;sslMode=none;charset=utf8;pooling=true;max pool size=1024;connect timeout = 20;";
public static string connectionString = @"server=41.244.68.54;port=3306;user=root;password=zttZTT123!;database=daojiao;sslMode=none;charset=utf8;pooling=true;max pool size=1024;connect timeout = 20;AllowPublicKeyRetrieval=true;";
//public static string connectionString = @"server=127.0.0.1;port=3306;user=root;password=ztt12345;database=daojiao;sslMode=none;charset=utf8;pooling=true;max pool size=1024;connect timeout = 20;";
#region
@ -463,11 +463,42 @@ namespace ZTTMS_Manage_yibayiyi_20230320
}
/// <summary>
/// 执行查询语句返回MySqlDataReader ( 注意调用该方法后一定要对MySqlDataReader进行Close )
/// </summary>
/// <param name="strSQL">查询语句</param>
/// <returns>MySqlDataReader</returns>
//public static MySqlConnection connection = new MySqlConnection(connectionString);
///// <summary>
///// 执行查询语句返回MySqlDataReader ( 注意调用该方法后一定要对MySqlDataReader进行Close )
///// </summary>
///// <param name="strSQL">查询语句</param>
///// <returns>MySqlDataReader</returns>
//public static MySqlDataReader ExecuteReader(string strSQL)
//{
// MySqlCommand cmd = new MySqlCommand(strSQL, connection);
// MySqlDataReader myReader;
// try
// {
// if (connection.State == ConnectionState.Open)
// myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
// else
// {
// connection.Open();
// myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
// }
// return myReader;
// }
// catch (MySql.Data.MySqlClient.MySqlException e)
// {
// connection.Close();
// EveryDayLog.WriteErrorOther("ExecuteReaderError:" + e);
// //throw new Exception("异常信息:", e);
// //throw e;
// //Console.WriteLine(e);
// return null;
// }
//}
public static MySqlDataReader ExecuteReader(string strSQL)
{
MySqlConnection connection = new MySqlConnection(connectionString);

View File

@ -108,17 +108,17 @@ namespace ZTTMS_Manage_yibayiyi_20230320
public static string ftpCTDDataPath = @"/File/SensorData/CTDData";
public static string ftpRecordData = @"/File/RecordData";
//public static string totalPath = @"E:\Output\";
//public static string FFmpegPath = Environment.CurrentDirectory + @"\FFmpeg\bin\x86\ffmpeg.exe";
//public static string picPath = @"E:\Output\Image\Image_01\";
//public static string picPathShow = @"E:\Output\Image\Image_01";
//public static string vidPathShow = @"E:\Output\Video\Video_01";
public static string picPathShow = @"F:\Code\text\daojiao\Image\Image_01";
public static string vidPathShow = @"F:\Code\text\daojiao\Video\Video_01";
public static string picPath = @"F:\Code\text\daojiao\Image\Image_01\";
public static string totalPath = @"F:\Code\text\daojiao\";
public static string totalPath = @"E:\Output\";
public static string FFmpegPath = Environment.CurrentDirectory + @"\FFmpeg\bin\x86\ffmpeg.exe";
public static string picPath = @"E:\Output\Image\Image_01\";
public static string picPathShow = @"E:\Output\Image\Image_01";
public static string vidPathShow = @"E:\Output\Video\Video_01";
//public static string picPathShow = @"F:\Code\text\daojiao\Image\Image_01";
//public static string vidPathShow = @"F:\Code\text\daojiao\Video\Video_01";
//public static string picPath = @"F:\Code\text\daojiao\Image\Image_01\";
//public static string totalPath = @"F:\Code\text\daojiao\";
//public static string FFmpegPath = Environment.CurrentDirectory + @"\FFmpeg\bin\x86\ffmpeg.exe";
//标记设备是否使能

View File

@ -1428,6 +1428,10 @@ namespace ZTTMS_Manage_yibayiyi_20230320
g_flagSetLight = true;
g_timerSetLight.Stop();
CallInvokeUIUpdate("UpdateSetLightEnable", "true");
MainForm.videoRecordForm.g_flagSetLight = true;
MainForm.videoRecordForm.g_timerSetLight.Stop();
MainForm.videoRecordForm.CallInvokeUIUpdate("UpdateSetLightEnable", "true");
}
else
{
@ -2733,6 +2737,9 @@ namespace ZTTMS_Manage_yibayiyi_20230320
private void btnSetLight_Click(object sender, EventArgs e)
{
if (txtLight.Text == null)
txtLight.Text = "90";
Int16 bufferLength = 10 + 2;
byte[] length = new byte[2];
@ -2827,7 +2834,7 @@ namespace ZTTMS_Manage_yibayiyi_20230320
SetParam();
txtLight.Text = "";
txtLight.Text = "90";
btnSetLight_Click(null, null);
}
catch(Exception ex)
@ -2863,13 +2870,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
else
return;
txtExposure.Text = "";
txtFrameRate.Text = "";
txtGain.Text = "";
txtExposure.Text = "10000";
txtFrameRate.Text = "15";
txtGain.Text = "7.7";
SetParam();
txtLight.Text = "";
txtLight.Text = "90";
btnSetLight_Click(null, null);
}
catch (Exception ex)

View File

@ -91,7 +91,7 @@ namespace ZTTMS_Manage_yibayiyi_20230320
dataReader.Dispose();
//CO2传感器
string sqlCO2 = $"select * from tb_co2_data where pressure!='' order by record_time desc limit 1;";
string sqlCO2 = $"select * from tb_co2_data where potency!='' order by record_time desc limit 1;";
dataReader = MySQL.ExecuteReader(sqlCO2);
while (dataReader.Read())
{

View File

@ -55,6 +55,11 @@
this.timerLightClose = new System.Windows.Forms.Timer(this.components);
this.btnShow = new System.Windows.Forms.Button();
this.picReplay = new System.Windows.Forms.PictureBox();
this.label5 = new System.Windows.Forms.Label();
this.btnSetLight = new System.Windows.Forms.Button();
this.txtLight = new System.Windows.Forms.TextBox();
this.timerLight = new System.Windows.Forms.Timer(this.components);
this.timerNight = new System.Windows.Forms.Timer(this.components);
this.pnlTitle.SuspendLayout();
this.pnlVideoShow.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picVideo)).BeginInit();
@ -66,6 +71,9 @@
// pnlTitle
//
this.pnlTitle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(105)))), ((int)(((byte)(118)))), ((int)(((byte)(128)))));
this.pnlTitle.Controls.Add(this.label5);
this.pnlTitle.Controls.Add(this.btnSetLight);
this.pnlTitle.Controls.Add(this.txtLight);
this.pnlTitle.Controls.Add(this.lblConnectState);
this.pnlTitle.Controls.Add(this.lblTitle);
this.pnlTitle.Dock = System.Windows.Forms.DockStyle.Top;
@ -80,7 +88,7 @@
// lblConnectState
//
this.lblConnectState.AutoSize = true;
this.lblConnectState.Location = new System.Drawing.Point(1359, 31);
this.lblConnectState.Location = new System.Drawing.Point(879, 32);
this.lblConnectState.Name = "lblConnectState";
this.lblConnectState.Size = new System.Drawing.Size(121, 29);
this.lblConnectState.TabIndex = 37;
@ -337,6 +345,48 @@
this.picReplay.TabStop = false;
this.picReplay.Click += new System.EventHandler(this.picReplay_Click);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("方正楷体简体", 20.25F);
this.label5.Location = new System.Drawing.Point(1060, 32);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(74, 29);
this.label5.TabIndex = 40;
this.label5.Text = "亮度:";
//
// btnSetLight
//
this.btnSetLight.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSetLight.Font = new System.Drawing.Font("方正楷体简体", 24F);
this.btnSetLight.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.btnSetLight.Location = new System.Drawing.Point(1305, 12);
this.btnSetLight.Name = "btnSetLight";
this.btnSetLight.Size = new System.Drawing.Size(210, 60);
this.btnSetLight.TabIndex = 39;
this.btnSetLight.Text = "设置";
this.btnSetLight.UseVisualStyleBackColor = true;
this.btnSetLight.Click += new System.EventHandler(this.btnSetLight_Click);
//
// txtLight
//
this.txtLight.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(231)))), ((int)(((byte)(236)))), ((int)(((byte)(233)))));
this.txtLight.Font = new System.Drawing.Font("方正楷体简体", 20.25F);
this.txtLight.Location = new System.Drawing.Point(1142, 28);
this.txtLight.Name = "txtLight";
this.txtLight.Size = new System.Drawing.Size(144, 39);
this.txtLight.TabIndex = 38;
this.txtLight.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.txtLight.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtLight_KeyPress);
//
// timerLight
//
this.timerLight.Tick += new System.EventHandler(this.timerLight_Tick);
//
// timerNight
//
this.timerNight.Tick += new System.EventHandler(this.timerNight_Tick);
//
// VideoRecordForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(15F, 29F);
@ -403,5 +453,10 @@
public System.Windows.Forms.TextBox txtCloseTime;
public System.Windows.Forms.TextBox txtOpenTime;
private System.Windows.Forms.PictureBox picReplay;
public System.Windows.Forms.Label label5;
private System.Windows.Forms.Button btnSetLight;
public System.Windows.Forms.TextBox txtLight;
private System.Windows.Forms.Timer timerLight;
private System.Windows.Forms.Timer timerNight;
}
}

View File

@ -48,11 +48,13 @@ namespace ZTTMS_Manage_yibayiyi_20230320
#region Timer Set
public System.Timers.Timer g_timerVideo = new System.Timers.Timer();
public System.Timers.Timer g_timerLight = new System.Timers.Timer();
public System.Timers.Timer g_timerSetLight = new System.Timers.Timer();
public System.Timers.Timer g_timerUVC = new System.Timers.Timer();
public System.Timers.Timer g_timerSetUVC = new System.Timers.Timer();
public bool g_flagVideo = true;
public bool g_flagLight = true;
public bool g_flagSetLight = true;
public bool g_flagUVC = true;
public bool g_flagSetUVC = true;
@ -74,6 +76,15 @@ namespace ZTTMS_Manage_yibayiyi_20230320
}
}
private void methodSetLight(object sender, System.Timers.ElapsedEventArgs e)
{
if (g_flagSetLight == false)
{
Console.WriteLine("影像腔未响应,请重新点击发送!");
CallInvokeUIUpdate("UpdateSetLightEnable", "true");
}
}
private void methodUVC(object sender, System.Timers.ElapsedEventArgs e)
{
if (g_flagUVC == false)
@ -106,6 +117,11 @@ namespace ZTTMS_Manage_yibayiyi_20230320
g_timerLight.AutoReset = false;
g_timerLight.Elapsed += new System.Timers.ElapsedEventHandler(methodLight);
g_timerSetLight.Enabled = true;
g_timerSetLight.Interval = 20000;
g_timerSetLight.AutoReset = false;
g_timerSetLight.Elapsed += new System.Timers.ElapsedEventHandler(methodSetLight);
g_timerUVC.Enabled = true;
g_timerUVC.Interval = 20000;
g_timerUVC.AutoReset = false;
@ -115,6 +131,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
g_timerSetUVC.Interval = 20000;
g_timerSetUVC.AutoReset = false;
g_timerSetUVC.Elapsed += new System.Timers.ElapsedEventHandler(methodSetUVC);
timerLight.Enabled = true;
timerLight.Interval = 50000;
timerLight.Start();
timerNight.Enabled = true;
timerNight.Interval = 50000;
timerNight.Start();
}
@ -148,6 +172,9 @@ namespace ZTTMS_Manage_yibayiyi_20230320
case "UpdateLightEnable":
btnOpenCloseLight.Enabled = bool.Parse(arg);
break;
case "UpdateSetLightEnable":
btnSetLight.Enabled = bool.Parse(arg);
break;
case "UpdateUVCEnable":
btnOpenCloseUVC.Enabled = bool.Parse(arg);
break;
@ -662,6 +689,12 @@ namespace ZTTMS_Manage_yibayiyi_20230320
g_timerSetUVC.Start();
CallInvokeUIUpdate("UpdateSetUVCEnable", "false");
}
else if(str=="设置亮度")
{
g_flagSetLight = false;
g_timerSetLight.Start();
CallInvokeUIUpdate("UpdateSetLightEnable", "false");
}
}
catch (Exception ex)
{
@ -743,6 +776,14 @@ namespace ZTTMS_Manage_yibayiyi_20230320
e.Handled = true;
}
}
private void txtLight_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
{
e.Handled = true;
}
}
#endregion
@ -780,5 +821,110 @@ namespace ZTTMS_Manage_yibayiyi_20230320
videoForm.TopMost = true;
videoForm.Show();
}
private void btnSetLight_Click(object sender, EventArgs e)
{
if (txtLight.Text == null)
txtLight.Text = "90";
Int16 bufferLength = 10 + 2;
byte[] length = new byte[2];
length[0] = (byte)(bufferLength & 0xff);
length[1] = (byte)((bufferLength >> 8) & 0xff);
byte funcCode = 0x12;
byte[] sendBuffer = new byte[bufferLength];
sendBuffer[0] = CamAndVid.head;
sendBuffer[1] = CamAndVid.idHost;
sendBuffer[2] = CamAndVid.typeSend;
sendBuffer[3] = length[0];
sendBuffer[4] = length[1];
sendBuffer[5] = funcCode;
sendBuffer[6] = 0x00;
sendBuffer[7] = byte.Parse(txtLight.Text.Trim());
byte[] checkSum = CamAndVid.CheckSum(new byte[] { sendBuffer[1], sendBuffer[2], sendBuffer[3], sendBuffer[4], sendBuffer[5], sendBuffer[6], sendBuffer[7] });
sendBuffer[8] = checkSum[0];
sendBuffer[9] = checkSum[1];
sendBuffer[10] = CamAndVid.tail[0];
sendBuffer[11] = CamAndVid.tail[1];
SendMessage(sendBuffer, "设置亮度");
}
private void timerLight_Tick(object sender, EventArgs e)
{
Thread thSetLightLight = new Thread(SetLightLight);
thSetLightLight.IsBackground = true;
thSetLightLight.Start();
}
private void SetLightLight()
{
try
{
DateTime NowDate = DateTime.Now;
if (NowDate.Hour == 6 && NowDate.Minute == 0)
{
EveryDayLog.WriteADCP("摄像机将在2min后设置白天亮度");
Console.WriteLine("摄像机将在2min后设置白天亮度");
timerLight.Enabled = false;
timerLight.Stop();
Thread.Sleep(2 * 1000);
timerLight.Enabled = true;
timerLight.Start();
}
else
return;
txtLight.Text = "90";
btnSetLight_Click(null, null);
}
catch (Exception ex)
{
EveryDayLog.WriteErrorCamAndVid("SetParamLightError:" + ex.Message);
Console.WriteLine("SetParamLightError:" + ex.Message);
}
}
private void timerNight_Tick(object sender, EventArgs e)
{
Thread thSetLightNight = new Thread(SetLightNight);
thSetLightNight.IsBackground = true;
thSetLightNight.Start();
}
private void SetLightNight()
{
try
{
DateTime NowDate = DateTime.Now;
if (NowDate.Hour == 19 && NowDate.Minute == 0)
{
EveryDayLog.WriteADCP("摄像机将在2min后设置晚上亮度");
Console.WriteLine("摄像机将在2min后设置晚上亮度");
timerNight.Enabled = false;
timerNight.Stop();
Thread.Sleep(2 * 1000);
timerNight.Enabled = true;
timerNight.Start();
}
else
return;
txtLight.Text = "90";
btnSetLight_Click(null, null);
}
catch (Exception ex)
{
EveryDayLog.WriteErrorCamAndVid("SetParamNightError:" + ex.Message);
Console.WriteLine("SetParamNightError:" + ex.Message);
}
}
}
}

View File

@ -126,6 +126,12 @@
<metadata name="timerLightClose.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>567, 17</value>
</metadata>
<metadata name="timerLight.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>833, 17</value>
</metadata>
<metadata name="timerNight.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>945, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>50</value>
</metadata>