|
@@ -1,9 +1,14 @@
|
|
|
using System;
|
|
|
+using System.Collections;
|
|
|
using System.IO.Ports;
|
|
|
using System.Text;
|
|
|
+using System.Diagnostics;
|
|
|
using Aitex.Core.RT.Event;
|
|
|
using Aitex.Core.RT.Log;
|
|
|
using MECF.Framework.Common.Utilities;
|
|
|
+using Aitex.Core.RT.SCCore;
|
|
|
+using MECF.Framework.Common.SCCore;
|
|
|
+using Aitex.Core.Util;
|
|
|
|
|
|
namespace MECF.Framework.Common.Communications
|
|
|
{
|
|
@@ -30,6 +35,7 @@ namespace MECF.Framework.Common.Communications
|
|
|
public bool EnableLog { get; set; }
|
|
|
|
|
|
private bool _isAsciiMode;
|
|
|
+ private static BitArray _EnableLog;
|
|
|
|
|
|
public AsyncSerialPort(string name, int baudRate, int dataBits, Parity parity = Parity.None, StopBits stopBits = StopBits.One, string newline = "\r", bool isAsciiMode=true)
|
|
|
{
|
|
@@ -54,6 +60,8 @@ namespace MECF.Framework.Common.Communications
|
|
|
|
|
|
_port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
|
|
|
_port.ErrorReceived += new SerialErrorReceivedEventHandler(ErrorReceived);
|
|
|
+
|
|
|
+ EnableLog = GetEnableFlag(name);
|
|
|
}
|
|
|
|
|
|
public void Dispose()
|
|
@@ -254,6 +262,43 @@ namespace MECF.Framework.Common.Communications
|
|
|
if (OnErrorHappened != null)
|
|
|
OnErrorHappened(reason);
|
|
|
}
|
|
|
+
|
|
|
+ bool GetEnableFlag(string portName)
|
|
|
+ {
|
|
|
+ if (_EnableLog == null)
|
|
|
+ {
|
|
|
+ Process cur = Process.GetCurrentProcess();
|
|
|
+ if (cur.ProcessName != "Venus_RT")
|
|
|
+ return false;
|
|
|
+
|
|
|
+ string[] strArray = SC.GetStringValue("System.COMLogFlag").Split(',');
|
|
|
+ int[] bitData = new int[8];
|
|
|
+ for (int i = 0; i < strArray.Length; i++)
|
|
|
+ {
|
|
|
+ if (int.TryParse(strArray[i], System.Globalization.NumberStyles.HexNumber, null, out int Flag))
|
|
|
+ {
|
|
|
+ bitData[i] = Flag;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bitData[i] = 0;
|
|
|
+ LOG.Write(eEvent.WARN_DEVICE_INFO, "System", $"Parse System.COMLogFlag failed: {strArray[i]}.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ _EnableLog = new BitArray(bitData);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (int.TryParse(portName.Substring(3), out int nCom))
|
|
|
+ {
|
|
|
+ if (_EnableLog.Length > nCom)
|
|
|
+ {
|
|
|
+ return _EnableLog[nCom];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|