格式化代码

This commit is contained in:
zhengxuan.zhang
2024-02-21 17:05:21 +08:00
parent 4c87a3c425
commit 08daf2ced4
11 changed files with 1061 additions and 1077 deletions
File diff suppressed because it is too large Load Diff
+39 -39
View File
@@ -12,32 +12,32 @@ namespace HexcalMC.Base
{
public class DebugDfn
{
public static string strDebugFile = Application.StartupPath + "\\File\\Debug.txt";
public static string strDebugSavePath = Application.StartupPath + "\\File\\DebugFiles";
public static string strDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看
static string strStartTime = ""; //程序启动时间
static string strEndTime = ""; //程序关闭时间
public static string StrDebugFile = Application.StartupPath + "\\File\\Debug.txt";
public static string StrDebugSavePath = Application.StartupPath + "\\File\\DebugFiles";
public static string StrDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看
static string _strStartTime = ""; //程序启动时间
static string _strEndTime = ""; //程序关闭时间
public static RichTextBox textBox_Msg;
public static RichTextBox TextBoxMsg;
//=================================================================
public static void StartDebugObj()
{
System.IO.TextWriter log = new System.IO.StreamWriter(DebugDfn.strDebugFile);
System.IO.TextWriter log = new System.IO.StreamWriter(DebugDfn.StrDebugFile);
TextWriterTraceListener logger = new TextWriterTraceListener(log);
Trace.Listeners.Add(logger);
strStartTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
_strStartTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
}
public static void SaveDebugFile()
{
AddLog("软件关闭!");
strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss");
string CopyFileName = strDebugSavePath + "\\DebugFiles\\" + "Debug(" + strStartTime + " To " +
strEndTime + ")" + ".txt";
if (File.Exists(strDebugFile))
File.Copy(strDebugFile, CopyFileName, true);
_strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss");
string copyFileName = StrDebugSavePath + "\\DebugFiles\\" + "Debug(" + _strStartTime + " To " +
_strEndTime + ")" + ".txt";
if (File.Exists(StrDebugFile))
File.Copy(StrDebugFile, copyFileName, true);
}
//=================================================================
@@ -49,45 +49,45 @@ namespace HexcalMC.Base
MyBase.TraceWriteLine(str);
}
public static void AddLogText(string str, Color m_Color = new Color())
public static void AddLogText(string str, Color mColor = new Color())
{
MyBase.TraceWriteLine(str);
try
{
textBox_Msg.BeginInvoke((EventHandler)delegate
TextBoxMsg.BeginInvoke((EventHandler)delegate
{
Color SetColor = Color.White;
if (m_Color == new Color())
Color setColor = Color.White;
if (mColor == new Color())
{
if (str.ToUpper().Contains("ERROR") || str.ToUpper().Contains("错误") ||
str.ToUpper().Contains("出错") || str.ToUpper().Contains("EXCEPTION") ||
str.ToUpper().Contains("异常") || str.ToUpper().Contains("失败"))
{
SetColor = Color.Red;
setColor = Color.Red;
}
else if (str.ToUpper().Contains("WARNING") || str.ToUpper().Contains("警告"))
{
SetColor = Color.DarkOrange;
setColor = Color.DarkOrange;
}
}
else
{
SetColor = m_Color;
setColor = mColor;
}
string strText = DateTime.Now.ToString("HH:mm:ss.ff") + "--" + str + Environment.NewLine;
textBox_Msg.SelectionStart = textBox_Msg.TextLength;
TextBoxMsg.SelectionStart = TextBoxMsg.TextLength;
if (string.IsNullOrEmpty(str))
SetText(textBox_Msg, str, SetColor, false, 16);
SetText(TextBoxMsg, str, setColor, false, 16);
else
SetText(textBox_Msg, strText, SetColor, false, 16);
if (textBox_Msg.Lines.Length > 800)
SetText(TextBoxMsg, strText, setColor, false, 16);
if (TextBoxMsg.Lines.Length > 800)
{
textBox_Msg.Select(0, textBox_Msg.TextLength / 2);
textBox_Msg.Cut();
TextBoxMsg.Select(0, TextBoxMsg.TextLength / 2);
TextBoxMsg.Cut();
}
textBox_Msg.ScrollToCaret();
TextBoxMsg.ScrollToCaret();
});
}
catch
@@ -95,32 +95,32 @@ namespace HexcalMC.Base
}
}
public static void SetText(RichTextBox m_RichTextBox, string strText, Color m_Color, bool bBold = false,
float Size = 16)
public static void SetText(RichTextBox mRichTextBox, string strText, Color mColor, bool bBold = false,
float size = 16)
{
m_RichTextBox.Invoke(((EventHandler)delegate
mRichTextBox.Invoke(((EventHandler)delegate
{
SetFont(m_RichTextBox, m_Color, bBold, Size);
m_RichTextBox.SelectedText = strText;
SetFont(mRichTextBox, mColor, bBold, size);
mRichTextBox.SelectedText = strText;
}));
}
public static void SetFont(RichTextBox m_RichTextBox, Color m_Color, bool bBold = false, float Size = 16)
public static void SetFont(RichTextBox mRichTextBox, Color mColor, bool bBold = false, float size = 16)
{
m_RichTextBox.SelectionColor = m_Color;
mRichTextBox.SelectionColor = mColor;
if (bBold)
m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size, System.Drawing.FontStyle.Bold,
mRichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", size, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
else
m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size,
mRichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", size,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
}
public static void SetErrorColor(Color InColor)
public static void SetErrorColor(Color inColor)
{
if (textBox_Msg != null)
if (TextBoxMsg != null)
{
textBox_Msg.BeginInvoke((EventHandler)delegate { textBox_Msg.BackColor = InColor; });
TextBoxMsg.BeginInvoke((EventHandler)delegate { TextBoxMsg.BackColor = inColor; });
}
}
+130 -135
View File
@@ -1,25 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;
namespace HexcalMC.Hexcal
{
public class TcpIpServer
{
/// <summary>
/// 使用模式,默认=1,接收任意数据显示;2=前两个字节为数据长度
/// </summary>
public int UseMode = 1;
public delegate void EventHandlerRaisedMessage(string clientIp, string msg);
string strServerIP = "127.0.0.1"; //服务器的IP地址
string strServerPort = "8080"; //端口号
public enum EnumTcpIpServer : int
public delegate void EventHandlerRaisedStatus(EnumTcpIpServer type, string msg);
public enum EnumTcpIpServer
{
StartListen = 1,
ClientConnect = 2,
@@ -28,68 +25,55 @@ namespace HexcalMC.Hexcal
Exception = -1
}
#region 510,
private readonly Dictionary<string, Socket> _dictSocket = new Dictionary<string, Socket>();
private readonly Dictionary<string, Thread> _dictThread = new Dictionary<string, Thread>();
private Socket _mWatchSocket;
System.Windows.Forms.Timer ServerTimer = new System.Windows.Forms.Timer();
private Thread _mWatchThread; // 负责监听客户端连接请求的线程;
private void ServerTimerLoop(object sender, EventArgs e)
private readonly string _strServerIp = "127.0.0.1"; //服务器的IP地址
private readonly string _strServerPort = "8080"; //端口号
/// <summary>
/// 使用模式,默认=1,接收任意数据显示;2=前两个字节为数据长度
/// </summary>
public int UseMode = 1;
//=========================================================================
public TcpIpServer(string serverIp, string serverPort)
{
ServerTimer.Interval = 20000; //监听timer的间隔
if (DictSocket != null)
{
if (DictSocket.Count != 0)
{
DictSocket.Values.ToArray();
for (int i = DictSocket.Values.ToArray().Length - 1; i >= 0; i--)
{
if (DictSocket.Values.ToArray()[i].Poll(10, SelectMode.SelectRead)) //10毫秒,检查套接字状态, SelectMode 参数指定要监视的套接字的类别。
{
// DictSocket.Remove(DictSocket.Keys.ToArray()[i]);
_strServerIp = serverIp;
_strServerPort = serverPort;
}
RaisedStatus(EnumTcpIpServer.ConnectException,
"连接已断开:" + DictSocket.Keys.ToArray()[i]); //刷新界面显示,触发一个连接异常状态枚举,并将消息传递为异常的状态
RemoveSocketClient(DictSocket.Keys.ToArray()[i]);
}
}
}
public string[] SocketNames => _dictSocket.Keys.ToArray();
public bool ConnectStatus
{
get
{
if (_mWatchSocket == null)
return false;
return _mWatchSocket.Connected && _mWatchThread != null;
}
}
#endregion
Thread m_WatchThread = null; // 负责监听客户端连接请求的线程;
Socket m_WatchSocket = null;
Dictionary<string, Thread> DictThread = new Dictionary<string, Thread>();
Dictionary<string, Socket> DictSocket = new Dictionary<string, Socket>();
bool bStartListen = false;
public string[] SocketNames
{
get { return (string[])DictSocket.Keys.ToArray(); }
}
//=========================================================================
public TcpIpServer(string ServerIP, string ServerPort)
{
strServerIP = ServerIP;
strServerPort = ServerPort;
}
public bool WatchStatus { get; private set; }
public bool StartListen()
{
try
{
ServerTimer.Tick += new EventHandler(ServerTimerLoop); //510,增加时钟,判断是否有断掉的连接。
ServerTimer.Start();
_serverTimer.Tick += ServerTimerLoop; //510,增加时钟,判断是否有断掉的连接。
_serverTimer.Start();
m_WatchSocket =
_mWatchSocket =
new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //创建负责监听的套接字,注意其中的参数;
IPAddress m_IpAddr = IPAddress.Parse(strServerIP); //获得文本框中的IP对象;
IPEndPoint m_EndPoint = new IPEndPoint(m_IpAddr, int.Parse(strServerPort)); //创建包含ip和端口号的网络节点对象;
IPAddress mIpAddr = IPAddress.Parse(_strServerIp); //获得文本框中的IP对象;
IPEndPoint mEndPoint = new IPEndPoint(mIpAddr, int.Parse(_strServerPort)); //创建包含ip和端口号的网络节点对象;
try
{
m_WatchSocket.Bind(m_EndPoint); // 将负责监听的套接字绑定到唯一的ip和端口上;
_mWatchSocket.Bind(mEndPoint); // 将负责监听的套接字绑定到唯一的ip和端口上;
}
catch (SocketException se)
{
@@ -97,12 +81,12 @@ namespace HexcalMC.Hexcal
return false;
}
bStartListen = true;
m_WatchSocket.Listen(10); // 设置监听队列的长度
m_WatchThread = new Thread(WatchThread); // 创建负责监听的线程
m_WatchThread.IsBackground = true;
m_WatchThread.Start();
RaisedStatus(EnumTcpIpServer.StartListen, "服务器启动监听成功!IP=" + strServerIP + ", Port=" + strServerPort);
WatchStatus = true;
_mWatchSocket.Listen(10); // 设置监听队列的长度
_mWatchThread = new Thread(WatchThread); // 创建负责监听的线程
_mWatchThread.IsBackground = true;
_mWatchThread.Start();
RaisedStatus(EnumTcpIpServer.StartListen, "服务器启动监听成功!IP=" + _strServerIp + ", Port=" + _strServerPort);
return true;
}
catch (Exception ex)
@@ -116,75 +100,58 @@ namespace HexcalMC.Hexcal
{
try
{
bStartListen = false;
m_WatchSocket.Close();
m_WatchSocket.Dispose();
m_WatchSocket = null;
WatchStatus = false;
_mWatchSocket.Close();
_mWatchSocket.Dispose();
_mWatchSocket = null;
DictThread.Clear();
DictSocket.Clear();
_dictThread.Clear();
_dictSocket.Clear();
}
catch
{
}
}
public bool ConnectStatus
{
get
{
if (m_WatchSocket == null)
return false;
return m_WatchSocket.Connected && m_WatchThread != null;
}
}
public bool WatchStatus
{
get { return bStartListen; }
}
//监听线程
void WatchThread()
private void WatchThread()
{
try
{
while (bStartListen) // 持续不断的监听客户端的连接请求;
while (WatchStatus) // 持续不断的监听客户端的连接请求;
{
// 开始监听客户端连接请求,Accept方法会阻断当前的线程;
Socket sokClient = m_WatchSocket.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的套接字;
Socket sokClient = _mWatchSocket.Accept(); // 一旦监听到一个客户端的请求,就返回一个与该客户端通信的套接字;
#region
#region 510,
if (DictSocket != null)
if (_dictSocket != null)
{
if (DictSocket.Count != 0)
if (_dictSocket.Count != 0)
{
DictSocket.Values.ToArray();
for (int i = DictSocket.Values.ToArray().Length - 1; i >= 0; i--)
_dictSocket.Values.ToArray();
for (int i = _dictSocket.Values.ToArray().Length - 1; i >= 0; i--)
{
if (DictSocket.Values.ToArray()[i].Poll(10, SelectMode.SelectRead))
if (_dictSocket.Values.ToArray()[i].Poll(10, SelectMode.SelectRead))
{
//DictSocket.Remove(DictSocket.Keys.ToArray()[i]);
RemoveSocketClient(DictSocket.Keys.ToArray()[i]);
RemoveSocketClient(_dictSocket.Keys.ToArray()[i]);
}
}
}
}
#endregion
#endregion
DictSocket.Add(sokClient.RemoteEndPoint.ToString(), sokClient); // 将与客户端连接的套接字对象添加到集合中;
_dictSocket.Add(sokClient.RemoteEndPoint.ToString(), sokClient); // 将与客户端连接的套接字对象添加到集合中;
RaisedStatus(EnumTcpIpServer.ClientConnect,
"客户端连接成功!RemoteEndPoint=" + sokClient.RemoteEndPoint.ToString());
"客户端连接成功!RemoteEndPoint=" + sokClient.RemoteEndPoint);
Thread thread = new Thread(ReceiveThread);
thread.IsBackground = true;
thread.Start(sokClient);
DictThread.Add(sokClient.RemoteEndPoint.ToString(), thread); // 将新建的线程 添加 到线程的集合中去。
_dictThread.Add(sokClient.RemoteEndPoint.ToString(), thread); // 将新建的线程 添加 到线程的集合中去。
}
}
catch
@@ -193,10 +160,10 @@ namespace HexcalMC.Hexcal
}
//接收线程
void ReceiveThread(object sokObj)
private void ReceiveThread(object sokObj)
{
Socket sokClient = sokObj as Socket;
while (bStartListen)
while (WatchStatus)
{
// 定义一个2M的缓存区;
byte[] arrMsgRec = new byte[sokClient.Available];
@@ -226,9 +193,9 @@ namespace HexcalMC.Hexcal
if (length > 0)
{
// TcpIpDfn.SongLiang_arrMsgRec = arrMsgRec; //510
string strData = System.Text.Encoding.Default.GetString(arrMsgRec); // 将接受到的字节数据转化成字符串;
//strData = strData.Substring(0, length);
//RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData.Replace("\0", "<0>"));
string strData = Encoding.Default.GetString(arrMsgRec); // 将接受到的字节数据转化成字符串;
//strData = strData.Substring(0, length);
//RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData.Replace("\0", "<0>"));
RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData.Replace("\0", "."));
}
}
@@ -238,7 +205,7 @@ namespace HexcalMC.Hexcal
{
// TcpIpDfn.SongLiang_arrMsgRec = arrMsgRec; //510
string strData =
System.Text.Encoding.Default.GetString(arrMsgRec, 2,
Encoding.Default.GetString(arrMsgRec, 2,
arrMsgRec.Length - 2); // 将接受到的字节数据转化成字符串;
RaisedMessage(sokClient.RemoteEndPoint.ToString(), strData);
@@ -253,40 +220,42 @@ namespace HexcalMC.Hexcal
}
//删除客户端对象
void RemoveSocketClient(string strRemoteEndPoint)
private void RemoveSocketClient(string strRemoteEndPoint)
{
// 从通信套接字集合中 删除被中断连接的通信套接字;
DictSocket.Remove(strRemoteEndPoint);
_dictSocket.Remove(strRemoteEndPoint);
// 从通信线程集合中 删除被中断连接的通信线程对象;
DictThread.Remove(strRemoteEndPoint);
_dictThread.Remove(strRemoteEndPoint);
}
//发送消息
public void SendMessage(string strSocketKey, string strMsg)
{
byte[] arrMsg = System.Text.Encoding.Default.GetBytes(strMsg);
DictSocket[strSocketKey].Send(arrMsg);
byte[] arrMsg = Encoding.Default.GetBytes(strMsg);
_dictSocket[strSocketKey].Send(arrMsg);
}
public void SendMessage(string strSocketKey, byte[] arrMsg)
{
DictSocket[strSocketKey].Send(arrMsg);
_dictSocket[strSocketKey].Send(arrMsg);
}
/// <summary> 发送数据函数(字符串, 自动添加长度(byte格式))</summary>
/// <summary>
/// 发送数据函数(字符串, 自动添加长度(byte格式))
/// </summary>
public string SendMessage2(string strSocketKey, string strMsg)
{
try
{
if (DictSocket[strSocketKey].Connected)
if (_dictSocket[strSocketKey].Connected)
{
byte[] arrLength = new byte[2];
arrLength = BitConverter.GetBytes(Convert.ToInt16(strMsg.Length));
byte[] WriteBuffer = Encoding.Default.GetBytes(strMsg);
WriteBuffer = arrLength.Concat(WriteBuffer).ToArray();
byte[] writeBuffer = Encoding.Default.GetBytes(strMsg);
writeBuffer = arrLength.Concat(writeBuffer).ToArray();
DictSocket[strSocketKey].Send(WriteBuffer);
_dictSocket[strSocketKey].Send(writeBuffer);
return "";
}
@@ -300,8 +269,8 @@ namespace HexcalMC.Hexcal
public void SendMessageToAllClients(string strMsg)
{
byte[] arrMsg = System.Text.Encoding.Default.GetBytes(strMsg);
foreach (Socket soc in DictSocket.Values)
byte[] arrMsg = Encoding.Default.GetBytes(strMsg);
foreach (Socket soc in _dictSocket.Values)
{
soc.Send(arrMsg);
}
@@ -309,31 +278,29 @@ namespace HexcalMC.Hexcal
public void SendMessageToAllClients(byte[] arrMsg)
{
foreach (Socket soc in DictSocket.Values)
foreach (Socket soc in _dictSocket.Values)
{
soc.Send(arrMsg);
}
}
public delegate void EventHandler_RaisedStatus(EnumTcpIpServer Type, string Msg);
public event EventHandler_RaisedStatus OnRaisedStatus;
public event EventHandlerRaisedStatus OnRaisedStatus;
// 异步或同步触发自定义事件,并在目标控件是 Windows Forms 控件的情况下添加到目标控件的消息队列中。它主要的目的是使得自定义事件处理程序在UI线程上执行,以避免线程上的卡顿或UI更新问题。
private void RaisedStatus(EnumTcpIpServer ReturnType, string Msg)
private void RaisedStatus(EnumTcpIpServer returnType, string msg)
{
try
{
if (OnRaisedStatus != null)
{
if (OnRaisedStatus.Target is System.Windows.Forms.Control)
if (OnRaisedStatus.Target is Control)
{
Control targetForm = OnRaisedStatus.Target as System.Windows.Forms.Control;
targetForm.BeginInvoke(OnRaisedStatus, new object[] { ReturnType, Msg });
Control targetForm = OnRaisedStatus.Target as Control;
targetForm.BeginInvoke(OnRaisedStatus, returnType, msg);
}
else
{
OnRaisedStatus(ReturnType, Msg);
OnRaisedStatus(returnType, msg);
}
}
}
@@ -342,24 +309,22 @@ namespace HexcalMC.Hexcal
}
}
public delegate void EventHandler_RaisedMessage(string ClientIP, string Msg);
public event EventHandlerRaisedMessage OnRaisedMessage;
public event EventHandler_RaisedMessage OnRaisedMessage;
private void RaisedMessage(string ClientIP, string Msg)
private void RaisedMessage(string clientIp, string msg)
{
try
{
if (OnRaisedMessage != null)
{
if (OnRaisedMessage.Target is System.Windows.Forms.Control)
if (OnRaisedMessage.Target is Control)
{
Control targetForm = OnRaisedMessage.Target as System.Windows.Forms.Control;
targetForm.BeginInvoke(OnRaisedMessage, new object[] { ClientIP, Msg });
Control targetForm = OnRaisedMessage.Target as Control;
targetForm.BeginInvoke(OnRaisedMessage, clientIp, msg);
}
else
{
OnRaisedMessage(ClientIP, Msg);
OnRaisedMessage(clientIp, msg);
}
}
}
@@ -367,5 +332,35 @@ namespace HexcalMC.Hexcal
{
}
}
#region
private readonly Timer _serverTimer = new Timer();
private void ServerTimerLoop(object sender, EventArgs e)
{
_serverTimer.Interval = 20000; //监听timer的间隔
if (_dictSocket != null)
{
if (_dictSocket.Count != 0)
{
_dictSocket.Values.ToArray();
for (int i = _dictSocket.Values.ToArray().Length - 1; i >= 0; i--)
{
if (_dictSocket.Values.ToArray()[i]
.Poll(10, SelectMode.SelectRead)) //10毫秒,检查套接字状态, SelectMode 参数指定要监视的套接字的类别。
{
// DictSocket.Remove(DictSocket.Keys.ToArray()[i]);
RaisedStatus(EnumTcpIpServer.ConnectException,
"连接已断开:" + _dictSocket.Keys.ToArray()[i]); //刷新界面显示,触发一个连接异常状态枚举,并将消息传递为异常的状态
RemoveSocketClient(_dictSocket.Keys.ToArray()[i]);
}
}
}
}
}
#endregion
}
}
}
+4 -4
View File
@@ -66,11 +66,11 @@
<Reference Include="ACS.SPiiPlusNET">
<HintPath>bin\Debug\ACS.SPiiPlusNET.dll</HintPath>
</Reference>
<Reference Include="ScottPlot, Version=4.1.68.0, Culture=neutral, PublicKeyToken=86698dc10387c39e, processorArchitecture=MSIL">
<HintPath>packages\ScottPlot.4.1.68\lib\net462\ScottPlot.dll</HintPath>
<Reference Include="ScottPlot, Version=4.1.67.0, Culture=neutral, PublicKeyToken=86698dc10387c39e, processorArchitecture=MSIL">
<HintPath>packages\ScottPlot.4.1.67\lib\net462\ScottPlot.dll</HintPath>
</Reference>
<Reference Include="ScottPlot.WinForms, Version=4.1.68.0, Culture=neutral, PublicKeyToken=5df1dfa5321e734b, processorArchitecture=MSIL">
<HintPath>packages\ScottPlot.WinForms.4.1.68\lib\net461\ScottPlot.WinForms.dll</HintPath>
<Reference Include="ScottPlot.WinForms, Version=4.1.67.0, Culture=neutral, PublicKeyToken=5df1dfa5321e734b, processorArchitecture=MSIL">
<HintPath>packages\ScottPlot.WinForms.4.1.67\lib\net461\ScottPlot.WinForms.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
+1 -1
View File
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
VisualStudioVersion = 17.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HexcalMC", "HexcalMC.csproj", "{19741897-37D8-43EE-94A2-637975035CEA}"
EndProject
+32 -31
View File
@@ -78,6 +78,7 @@
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.groupBox7 = new System.Windows.Forms.GroupBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lamp_hexcal = new HexcalMC.Lamp();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.btn_HexcalStop = new System.Windows.Forms.Button();
@@ -121,6 +122,7 @@
this.btnEnable = new System.Windows.Forms.Button();
this.btnDisable = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.lamp_acs = new HexcalMC.Lamp();
this.txtPort = new System.Windows.Forms.TextBox();
this.txtIP = new System.Windows.Forms.TextBox();
this.btn_ACSStop = new System.Windows.Forms.Button();
@@ -133,8 +135,6 @@
this.textBox_Msg = new System.Windows.Forms.TextBox();
this.tmrMonitor = new System.Windows.Forms.Timer(this.components);
this.timer_RefreshUI = new System.Windows.Forms.Timer(this.components);
this.lamp_hexcal = new HexcalMC.Lamp();
this.lamp_acs = new HexcalMC.Lamp();
((System.ComponentModel.ISupportInitialize)(this.radRibbonBar1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.radRibbonBarBackstageView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.radStatusStrip1)).BeginInit();
@@ -377,12 +377,12 @@
//
this.radRibbonBar1.RootElement.AutoSizeMode = Telerik.WinControls.RadAutoSizeMode.WrapAroundChildren;
this.radRibbonBar1.ShowExpandButton = false;
this.radRibbonBar1.Size = new System.Drawing.Size(1192, 173);
this.radRibbonBar1.Size = new System.Drawing.Size(1192, 176);
this.radRibbonBar1.StartButtonImage = global::HexcalMC.Properties.Resources.Hexagon;
this.radRibbonBar1.StartMenuItems.AddRange(new Telerik.WinControls.RadItem[] {
this.radMenuItem2});
this.radRibbonBar1.TabIndex = 0;
this.radRibbonBar1.Text = "直线电机平台运动补偿";
this.radRibbonBar1.Text = "运动补偿中间件";
//
// radRibbonBarBackstageView1
//
@@ -583,7 +583,7 @@
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 173);
this.splitContainer1.Location = new System.Drawing.Point(0, 176);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
@@ -597,7 +597,7 @@
//
this.splitContainer1.Panel2.BackColor = System.Drawing.SystemColors.Control;
this.splitContainer1.Panel2.Controls.Add(this.groupBox3);
this.splitContainer1.Size = new System.Drawing.Size(1192, 696);
this.splitContainer1.Size = new System.Drawing.Size(1192, 693);
this.splitContainer1.SplitterDistance = 760;
this.splitContainer1.TabIndex = 2;
//
@@ -627,6 +627,18 @@
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Hexcal通讯设置";
//
// lamp_hexcal
//
this.lamp_hexcal.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
this.lamp_hexcal.Location = new System.Drawing.Point(57, 49);
this.lamp_hexcal.LText = "";
this.lamp_hexcal.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.lamp_hexcal.Name = "lamp_hexcal";
this.lamp_hexcal.Shadow = false;
this.lamp_hexcal.Size = new System.Drawing.Size(24, 24);
this.lamp_hexcal.State = -1;
this.lamp_hexcal.TabIndex = 29;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(103, 52);
@@ -660,6 +672,7 @@
this.btn_HexcalStart.TabIndex = 25;
this.btn_HexcalStart.Text = "启动";
this.btn_HexcalStart.UseVisualStyleBackColor = true;
this.btn_HexcalStart.Click += new System.EventHandler(this.btn_HexcalStart_Click);
//
// label3
//
@@ -1056,6 +1069,18 @@
this.groupBox2.TabStop = false;
this.groupBox2.Text = "ACS通讯设置";
//
// lamp_acs
//
this.lamp_acs.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
this.lamp_acs.Location = new System.Drawing.Point(57, 50);
this.lamp_acs.LText = "";
this.lamp_acs.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.lamp_acs.Name = "lamp_acs";
this.lamp_acs.Shadow = false;
this.lamp_acs.Size = new System.Drawing.Size(24, 24);
this.lamp_acs.State = -1;
this.lamp_acs.TabIndex = 30;
//
// txtPort
//
this.txtPort.Location = new System.Drawing.Point(103, 52);
@@ -1160,30 +1185,6 @@
this.timer_RefreshUI.Interval = 1000;
this.timer_RefreshUI.Tick += new System.EventHandler(this.timer_RefreshUI_Tick);
//
// lamp_hexcal
//
this.lamp_hexcal.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
this.lamp_hexcal.Location = new System.Drawing.Point(57, 49);
this.lamp_hexcal.LText = "";
this.lamp_hexcal.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.lamp_hexcal.Name = "lamp_hexcal";
this.lamp_hexcal.Shadow = false;
this.lamp_hexcal.Size = new System.Drawing.Size(24, 24);
this.lamp_hexcal.State = -1;
this.lamp_hexcal.TabIndex = 29;
//
// lamp_acs
//
this.lamp_acs.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
this.lamp_acs.Location = new System.Drawing.Point(57, 50);
this.lamp_acs.LText = "";
this.lamp_acs.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.lamp_acs.Name = "lamp_acs";
this.lamp_acs.Shadow = false;
this.lamp_acs.Size = new System.Drawing.Size(24, 24);
this.lamp_acs.State = -1;
this.lamp_acs.TabIndex = 30;
//
// MainFrom
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -1201,7 +1202,7 @@
//
this.RootElement.ApplyShapeToControl = true;
this.ShowIcon = false;
this.Text = "直线电机平台运动补偿 ";
this.Text = "运动补偿中间件";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainFrom_FormClosed);
this.Load += new System.EventHandler(this.MainFrom_Load);
((System.ComponentModel.ISupportInitialize)(this.radRibbonBar1)).EndInit();
+140 -144
View File
@@ -1,67 +1,63 @@
using ACS.SPiiPlusNET;
using HexcalMC.Hexcal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HexcalMC.Base;
using HexcalMC.Form;
using HexcalMC.Hexcal;
using HexcalMC.Properties;
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Telerik.WinControls.UI;
namespace HexcalMC
{
public partial class MainFrom : Telerik.WinControls.UI.RadRibbonForm
public partial class MainFrom : RadRibbonForm
{
#region hexcal变量区
private TcpIpServer m_tcpIpServer; //创建tcpserver,用于接收hexcal传来的指令,并解析传递平台
private bool m_bHexcalConnected = false;
private TcpIpServer _mTcpIpServer; //创建tcpserver,用于接收hexcal传来的指令,并解析传递平台
private readonly bool _mBHexcalConnected = false;
#endregion
#endregion hexcal变量区
#region
private Api _ACS;
private Api _acs;
private const int MAX_UI_LIMIT_CNT = 8;
private const int MAX_UI_IO_CNT = 8;
private const int MaxUiLimitCnt = 8;
private const int MaxUiIoCnt = 8;
private int m_nTotalAxis = 0;
private int m_nTotalBuffer = 0;
private Axis[] m_arrAxisList = null;
private readonly int _mNTotalAxis = 0;
private int _mNTotalBuffer = 0;
private Axis[] _mArrAxisList = null;
private bool m_bConnected = false;
private readonly bool _mBConnected = false;
// For update values
private MotorStates m_nMotorState; //运动状态
private ProgramStates m_nProgramState; //程序状态
private object m_objReadVar = null;
private Array m_arrReadVector = null;
private double m_lfRPos, m_lfFPos, m_lfPE, m_lfFVEL; //参考位置,反馈位置 位置误差 反馈速度 double类型
private int m_nValues, m_nOutputState;
private MotorStates _mNMotorState; //运动状态
private ProgramStates _mNProgramState; //程序状态
private object _mObjReadVar;
private Array _mArrReadVector;
private double _mLfRPos, _mLfFPos, _mLfPe, _mLfFvel; //参考位置,反馈位置 位置误差 反馈速度 double类型
private int _mNValues, _mNOutputState;
private Label[] m_lblLeftLimit; //左限位
private Label[] m_lblRightLimit; //右限位
private Label[] _mLblLeftLimit; //左限位
private Label[] _mLblRightLimit; //右限位
#endregion
#endregion
public MainFrom()
{
InitializeComponent();
}
private void MainFrom_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.FixedSingle; // 设置窗体边框样式为固定大小
this.MaximizeBox = false; // 禁用窗体的最大化按钮
FormBorderStyle = FormBorderStyle.FixedSingle; // 设置窗体边框样式为固定大小
MaximizeBox = false; // 禁用窗体的最大化按钮
double[] dataX = new double[] { 1, 2, 3, 4, 5 };
double[] dataY = new double[] { 1, 4, 9, 16, 25 };
double[] dataX = { 1, 2, 3, 4, 5 };
double[] dataY = { 1, 4, 9, 16, 25 };
formsPlot1.Plot.AddScatter(dataX, dataY);
formsPlot1.Refresh();
@@ -70,20 +66,22 @@ namespace HexcalMC
timer_RefreshUI.Start();
}
#region hexcal软件相关
private void StartServer()
{
//启动服务器,并获取数据,解析
m_tcpIpServer = new TcpIpServer("100.0.0.1", Convert.ToString(1234));
_mTcpIpServer = new TcpIpServer("100.0.0.1", Convert.ToString(1234));
try
{
//启动监听
if (m_tcpIpServer.StartListen())
if (_mTcpIpServer.StartListen())
{
//绑定两个事件 OnRaisedStatus 和OnRaisedMessage
m_tcpIpServer.OnRaisedMessage += ReceiveMessage;
m_tcpIpServer.OnRaisedStatus += ReceiveStatus;
_mTcpIpServer.OnRaisedMessage += ReceiveMessage;
_mTcpIpServer.OnRaisedStatus += ReceiveStatus;
DebugDfn.AddLogText("TCP服务端启动成功 ");
}
else
@@ -93,259 +91,255 @@ namespace HexcalMC
}
catch (Exception ex)
{
DebugDfn.AddLogText("启动TCP服务端异常" + ex.ToString());
DebugDfn.AddLogText("启动TCP服务端异常" + ex);
}
}
private void ReceiveMessage(string ClientIP, string Msg) //接收的内容
private void ReceiveMessage(string clientIp, string msg) //接收的内容
{
//打印ClientIP 和 Msg
DebugDfn.AddLogText("接收到" + ClientIP + ": " + Msg);
DebugDfn.AddLogText("接收到" + clientIp + ": " + msg);
//根据源地址的不同,执行不同处理
//如果 ClientIP 来自L2系统的话,执行解析
switch (ClientIP)
switch (clientIp)
{
case "172.19.153.80": //L2系统
//解析处理数据
ParseHexcalPacket(Msg);
ParseHexcalPacket(msg);
break;
case "127.0.0.1": //模拟长宽系统
break;
}
}
private void ParseHexcalPacket(string Msg) //编写一个Hexcal协议解析函数
private void ParseHexcalPacket(string msg) //编写一个Hexcal协议解析函数
{
//根据不同的指令进行解析,3个层次,不合法,故障,最后是正常
//判断Msg的长度,如果不是指定长度,直接返回
if (Msg.Length != 8) return;
if (msg.Length != 8) return;
//判断是否含有故障ERROR字样
if (Msg.Contains("ERROR")) return;
if (msg.Contains("ERROR")) return;
//指令解析
string[] tokens = Msg.Split(',');
string[] tokens = msg.Split(',');
foreach (string token in tokens)
{
Console.WriteLine(token);
}
//可能涉及到 将指令提取并单独处理的问题
if (string.Equals("CMMTYP", Msg))
if (string.Equals("CMMTYP", msg))
{
SendMsgToHexcal("CMMTYP MA 19617, FDC V15.00, 6 6 2 , 0");
}
else if (string.Equals("VERSION", Msg)) //版本号
else if (string.Equals("VERSION", msg)) //版本号
{
SendMsgToHexcal("00-000-000-00000 FDC V51.04.0000 DATE: 12/21/22 TIME: 12:50:55");
}
else if (string.Equals("^B", Msg)) //查询状态
else if (string.Equals("^B", msg)) //查询状态
{
//todo 启动指令
}
else if (string.Equals("SHOW MAXSTROKESW", Msg)) //最大行程
else if (string.Equals("SHOW MAXSTROKESW", msg)) //最大行程
{
SendMsgToHexcal("MAXSTROKESW 233.200000,346.500000,15.100000,0.000000,0.000000,0.000000,0.000000");
}
else if (string.Equals("00000003", Msg)) //最小行程
else if (string.Equals("00000003", msg)) //最小行程
{
SendMsgToHexcal("MINSTROKESW -68.800000,-55.500000,-286.900000,0.000000,0.000000,0.000000,0.000000");
}
else if (string.Equals("SHOW MAXVEL", Msg)) //最大速度
else if (string.Equals("SHOW MAXVEL", msg)) //最大速度
{
SendMsgToHexcal("MAXVEL 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000");
}
else if (string.Equals("SHOW MAXACC", Msg)) //最大加速度
else if (string.Equals("SHOW MAXACC", msg)) //最大加速度
{
SendMsgToHexcal(
"MAXACC 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000");
}
else if (string.Equals("SHOW TEMPCOMPTYPE", Msg)) //温度补偿,温度补偿 >1 表示支持温度补偿
else if (string.Equals("SHOW TEMPCOMPTYPE", msg)) //温度补偿,温度补偿 >1 表示支持温度补偿
{
SendMsgToHexcal("TEMPCOMPTYPE 1");
}
else if (string.Equals("READTP", Msg))
else if (string.Equals("READTP", msg))
{
SendMsgToHexcal("READTP 0.000000");
}
else if (string.Equals("SHOW SENSWKP", Msg))
else if (string.Equals("SHOW SENSWKP", msg))
{
SendMsgToHexcal("X_ SENSWKP 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
}
else if (string.Equals("SHOW X_SENSAXIS", Msg))
else if (string.Equals("SHOW X_SENSAXIS", msg))
{
SendMsgToHexcal("X_SENSAXIS 6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
}
else if (string.Equals("SHOW Y_SENSAXIS", Msg))
else if (string.Equals("SHOW Y_SENSAXIS", msg))
{
SendMsgToHexcal("Y_SENSAXIS 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
}
else if (string.Equals("SHOW Z_SENSAXIS", Msg))
else if (string.Equals("SHOW Z_SENSAXIS", msg))
{
SendMsgToHexcal("Z_SENSAXIS 7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
}
else if (string.Equals("SHOW MOVPAR", Msg)) //获取速度
else if (string.Equals("SHOW MOVPAR", msg)) //获取速度
{
SendMsgToHexcal(
"MOVPAR 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.00000 0,0.000000");
}
else if (string.Equals("MOVPAR 300.0,300.0,300.0,0.0,0.0,0.0", Msg)) //设置速度 xyz 轴的速度
else if (string.Equals("MOVPAR 300.0,300.0,300.0,0.0,0.0,0.0", msg)) //设置速度 xyz 轴的速度
{
SendMsgToHexcal("%");
}
else if (string.Equals("SHOW MAXVEL", Msg))
else if (string.Equals("SHOW MAXVEL", msg))
{
SendMsgToHexcal("MAXVEL 300.000000,300.000000,300.000000,0.000000,0.000000,0.000000,0.000000,0.000000");
}
else if (string.Equals("SHOW ACCEL", Msg)) //获取加速
else if (string.Equals("SHOW ACCEL", msg)) //获取加速
{
SendMsgToHexcal(
"ACCEL 1000.000000,1000.000000,1000.000000,0.000000,0.000000,0.000000,0.000000,0.000000");
}
else if (string.Equals("ACCEL 1000.0,1000.0,1000.0", Msg)) //设置加速度
else if (string.Equals("ACCEL 1000.0,1000.0,1000.0", msg)) //设置加速度
{
SendMsgToHexcal("%");
}
else if (string.Equals(
"PRBPIN 0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000",
Msg))
"PRBPIN 0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000,0.000000,0.000000,0.000000,0.000000,0.000000, 0.000000",
msg))
{
SendMsgToHexcal("%");
}
else if (string.Equals("ENABLE TEMP", Msg))
else if (string.Equals("ENABLE TEMP", msg))
{
SendMsgToHexcal("");
}
else if (string.Equals("WKPPAR 20,0.0000115,20", Msg))
else if (string.Equals("WKPPAR 20,0.0000115,20", msg))
{
SendMsgToHexcal("");
}
else if (string.Equals("SCLTMP", Msg))
else if (string.Equals("SCLTMP", msg))
{
SendMsgToHexcal("");
}
else if (string.Equals("MOVABS 167.553848,-55.400002,-208.548203,0.000000", Msg)) //移动指令
else if (string.Equals("MOVABS 167.553848,-55.400002,-208.548203,0.000000", msg)) //移动指令
{
SendMsgToHexcal("%");
}
else if (string.Equals("GETPOS", Msg)) //获取位置
else if (string.Equals("GETPOS", msg)) //获取位置
{
SendMsgToHexcal("POS 167.553898,-55.400421,-208.548678,0.000000,0.000000,0.000000,0.000000");
}
else if (string.Equals("SHOW ESTOP", Msg))
else if (string.Equals("SHOW ESTOP", msg))
{
SendMsgToHexcal("ESTOP FALSE");
}
else if (string.Equals("", Msg))
else if (string.Equals("", msg))
{
}
else
{
//todo 未知指令
}
//todo 未知指令
}
private void ReceiveStatus(TcpIpServer.EnumTcpIpServer iType, string Msg)
private void ReceiveStatus(TcpIpServer.EnumTcpIpServer iType, string msg)
{
//记录到日志
DebugDfn.AddLogText(iType + " : " + Msg);
DebugDfn.AddLogText(iType + " : " + msg);
}
private void SendMsgToHexcal(string Msg)
private void SendMsgToHexcal(string msg)
{
//发送数据
m_tcpIpServer.SendMessageToAllClients(Msg);
_mTcpIpServer.SendMessageToAllClients(msg);
}
#endregion
#endregion hexcal软件相关
#region ACS平台相关
private void btnEnable_Click(object sender, EventArgs e) //使能所有轴
{
Axis[] AxisList = new Axis[]
Axis[] axisList =
{
Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_4, Axis.ACSC_NONE
}; //!!!! Important !! Must insert '-1' at the last
_ACS.EnableM(AxisList);
_acs.EnableM(axisList);
}
private void btnDisable_Click(object sender, EventArgs e) //轴取消
{
// Disable all of axes
_ACS.DisableAll();
_acs.DisableAll();
}
private void tmrMonitor_Tick(object sender, EventArgs e) //用于刷新状态
{
int iAxisNo = cboAxisNo.SelectedIndex;
if (m_bConnected)
if (_mBConnected)
{
try
{
// Instruction 1. Using library functions - acsc_GetFPosition, acsc_GetRPosition, ....
// Instruction 2. Read ACS variable - Already defined almost things (FPOS, RPOS, ...)
// Motion parameters and state is array (Max length is total number of axes)
// Instruction 1. Using library functions - acsc_GetFPosition,
// acsc_GetRPosition, .... Instruction 2. Read ACS variable - Already defined
// almost things (FPOS, RPOS, ...) Motion parameters and state is array (Max
// length is total number of axes)
//
// * Library function can read only 1 axis information, so if you want to read several axes, you have to call the function many times.
// (This may cause communication delay.)
// Recommand (if you want to read many axes) : read/write variable using ReadVariable, ReadVariableScalar, ReadVariableVector, ReadVariableMatrix
// * Library function can read only 1 axis information, so if you want to read
// several axes, you have to call the function many times. (This may cause
// communication delay.) Recommand (if you want to read many axes) : read/write
// variable using ReadVariable, ReadVariableScalar, ReadVariableVector, ReadVariableMatrix
//
// Get Motor State
// ACSPL+ Variable : MST (integer)
m_nMotorState = _ACS.GetMotorState((Axis)iAxisNo);
// Get Motor State ACSPL+ Variable : MST (integer)
_mNMotorState = _acs.GetMotorState((Axis)iAxisNo);
// Returned value is integer, you need to use bitmaks
if ((m_nMotorState & MotorStates.ACSC_MST_MOVE) != 0) lblMoving.Image = Properties.Resources.On;
else lblMoving.Image = Properties.Resources.Off; // 运动中
if ((m_nMotorState & MotorStates.ACSC_MST_INPOS) != 0) lblInPos.Image = Properties.Resources.On;
else lblInPos.Image = Properties.Resources.Off; // 就位
if ((m_nMotorState & MotorStates.ACSC_MST_ACC) != 0) lblAcc.Image = Properties.Resources.On;
else lblAcc.Image = Properties.Resources.Off; // 加速
if ((m_nMotorState & MotorStates.ACSC_MST_ENABLE) != 0) lblEnable.Image = Properties.Resources.On;
else lblEnable.Image = Properties.Resources.Off; // 使能
// Returned value is integer, you need to use bitmaks
if ((_mNMotorState & MotorStates.ACSC_MST_MOVE) != 0) lblMoving.Image = Resources.On;
else lblMoving.Image = Resources.Off; // 运动中
if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0) lblInPos.Image = Resources.On;
else lblInPos.Image = Resources.Off; // 就位
if ((_mNMotorState & MotorStates.ACSC_MST_ACC) != 0) lblAcc.Image = Resources.On;
else lblAcc.Image = Resources.Off; // 加速
if ((_mNMotorState & MotorStates.ACSC_MST_ENABLE) != 0) lblEnable.Image = Resources.On;
else lblEnable.Image = Resources.Off; // 使能
// Reference position
// ACSPL+ Variable : RPOS (real)
m_lfRPos = _ACS.GetRPosition((Axis)iAxisNo); // 参考位置
// Reference position ACSPL+ Variable : RPOS (real)
_mLfRPos = _acs.GetRPosition((Axis)iAxisNo); // 参考位置
// Feedback position (Encoder value)
// ACSPL+ Variable : FPO (real)
m_lfFPos = _ACS.GetFPosition((Axis)iAxisNo); //反馈位置
// Feedback position (Encoder value) ACSPL+ Variable : FPO (real)
_mLfFPos = _acs.GetFPosition((Axis)iAxisNo); //反馈位置
// PE (Position Error)
// There is no function in library. We need to use ReadVariable function
m_lfPE = (double)_ACS.ReadVariable("PE", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //位置误差
// PE (Position Error) There is no function in library. We need to use
// ReadVariable function
_mLfPe = (double)_acs.ReadVariable("PE", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //位置误差
// Feedback Velocity
m_lfFVEL = (double)_ACS.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //实际速度
_mLfFvel = (double)_acs.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //实际速度
// txtRPOS.Text = String.Format("{0:0.0000}", m_lfRPos); //参考位置
rtb_xPos.Text = String.Format("{0:0.0000}", m_lfFPos); //反馈位置
// txtPE.Text = String.Format("{0:0.0000}", m_lfPE); //实际速度
// txtFVEL.Text = String.Format("{0:0.0000}", m_lfFVEL);//位置误差
rtb_xPos.Text = string.Format("{0:0.0000}", _mLfFPos); //反馈位置
// txtPE.Text =
// String.Format("{0:0.0000}",
// m_lfPE); //实际速度
// txtFVEL.Text =
// String.Format("{0:0.0000}", m_lfFVEL);//位置误差
// Read left/right hardware limits state
// ACSPL+ Variable : FAULT (integer)
m_objReadVar =
_ACS.ReadVariableAsVector("FAULT", ProgramBuffer.ACSC_NONE, 0, m_nTotalAxis - 1, -1, -1);
if (m_objReadVar != null)
// Read left/right hardware limits state ACSPL+ Variable : FAULT (integer)
_mObjReadVar =
_acs.ReadVariableAsVector("FAULT", ProgramBuffer.ACSC_NONE, 0, _mNTotalAxis - 1);
if (_mObjReadVar != null)
{
m_arrReadVector = m_objReadVar as Array;
if (m_arrReadVector != null)
_mArrReadVector = _mObjReadVar as Array;
if (_mArrReadVector != null)
{
for (int i = 0; i < m_nTotalAxis; i++)
for (int i = 0; i < _mNTotalAxis; i++)
{
UpdateLimitState(i, (int)m_arrReadVector.GetValue(i));
UpdateLimitState(i, (int)_mArrReadVector.GetValue(i));
}
}
}
@@ -353,18 +347,16 @@ namespace HexcalMC
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
System.Diagnostics.Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.Message);
}
}
}
private void btn_ACSStart_Click(object sender, EventArgs e) //连接
{
btn_ACSStart.Enabled = false;
btn_ACSStop.Enabled = true;
// Set updating timer
tmrMonitor.Interval = 50;
tmrMonitor.Start();
@@ -372,7 +364,7 @@ namespace HexcalMC
private void btn_ACSStop_Click(object sender, EventArgs e) //断开连接
{
if (m_bConnected) _ACS.CloseComm();
if (_mBConnected) _acs.CloseComm();
tmrMonitor.Stop();
@@ -385,20 +377,24 @@ namespace HexcalMC
timer_RefreshUI.Stop();
}
private void btn_HexcalStart_Click(object sender, EventArgs e)
{
}
private void UpdateLimitState(int axisNo, int fault) //刷新限位
{
if (axisNo < MAX_UI_LIMIT_CNT)
if (axisNo < MaxUiLimitCnt)
{
if ((fault & (int)SafetyControlMasks.ACSC_SAFETY_LL) != 0)
m_lblLeftLimit[axisNo].Image = Properties.Resources.Error;
else m_lblLeftLimit[axisNo].Image = Properties.Resources.Off;
_mLblLeftLimit[axisNo].Image = Resources.Error;
else _mLblLeftLimit[axisNo].Image = Resources.Off;
if ((fault & (int)SafetyControlMasks.ACSC_SAFETY_RL) != 0)
m_lblRightLimit[axisNo].Image = Properties.Resources.Error;
else m_lblRightLimit[axisNo].Image = Properties.Resources.Off;
_mLblRightLimit[axisNo].Image = Resources.Error;
else _mLblRightLimit[axisNo].Image = Resources.Off;
}
}
#endregion
#endregion ACS平台相关
#region
@@ -418,14 +414,14 @@ namespace HexcalMC
private void timer_RefreshUI_Tick(object sender, EventArgs e) //UI刷新
{
//状态灯刷新
lamp_acs.State = m_bConnected ? LampColor.Green : LampColor.Silver;
lamp_hexcal.State = m_bHexcalConnected ? LampColor.Green : LampColor.Silver;
lamp_acs.State = _mBConnected ? LampColor.Green : LampColor.Silver;
lamp_hexcal.State = _mBHexcalConnected ? LampColor.Green : LampColor.Silver;
//时间栏
//时间栏
//获取当前时间,构造形如 精确到秒,例如 2023-10-08 16:01:23
rle_timer.Text = "当前时间: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
#endregion
#endregion
}
}
+33 -33
View File
@@ -271,7 +271,7 @@
this.btnClose.TabIndex = 14;
this.btnClose.Text = "断开";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
this.btnClose.Click += new System.EventHandler(this.BtnClose_Click);
//
// btnOpen
//
@@ -281,7 +281,7 @@
this.btnOpen.TabIndex = 13;
this.btnOpen.Text = "连接";
this.btnOpen.UseVisualStyleBackColor = true;
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
this.btnOpen.Click += new System.EventHandler(this.BtnOpen_Click);
//
// label2
//
@@ -311,7 +311,7 @@
this.rdoTCP.TabStop = true;
this.rdoTCP.Text = "TCP";
this.rdoTCP.UseVisualStyleBackColor = true;
this.rdoTCP.CheckedChanged += new System.EventHandler(this.rdoTCP_CheckedChanged);
this.rdoTCP.CheckedChanged += new System.EventHandler(this.RdoTCP_CheckedChanged);
//
// rdoSimu
//
@@ -323,12 +323,12 @@
this.rdoSimu.TabStop = true;
this.rdoSimu.Text = "模拟器";
this.rdoSimu.UseVisualStyleBackColor = true;
this.rdoSimu.CheckedChanged += new System.EventHandler(this.rdoSimu_CheckedChanged);
this.rdoSimu.CheckedChanged += new System.EventHandler(this.RdoSimu_CheckedChanged);
//
// tmrMonitor
//
this.tmrMonitor.Interval = 50;
this.tmrMonitor.Tick += new System.EventHandler(this.tmrMonitor_Tick);
this.tmrMonitor.Tick += new System.EventHandler(this.TmrMonitor_Tick);
//
// grpMotionTest
//
@@ -359,7 +359,7 @@
this.btnHallAll.TabIndex = 10;
this.btnHallAll.Text = "停止全部";
this.btnHallAll.UseVisualStyleBackColor = true;
this.btnHallAll.Click += new System.EventHandler(this.btnHallAll_Click);
this.btnHallAll.Click += new System.EventHandler(this.BtnHallAll_Click);
//
// btnHalt
//
@@ -369,7 +369,7 @@
this.btnHalt.TabIndex = 10;
this.btnHalt.Text = "停止";
this.btnHalt.UseVisualStyleBackColor = true;
this.btnHalt.Click += new System.EventHandler(this.btnHalt_Click);
this.btnHalt.Click += new System.EventHandler(this.BtnHalt_Click);
//
// grpMst
//
@@ -482,7 +482,7 @@
this.btnSetZero.TabIndex = 7;
this.btnSetZero.Text = "设置零位";
this.btnSetZero.UseVisualStyleBackColor = true;
this.btnSetZero.Click += new System.EventHandler(this.btnSetZero_Click);
this.btnSetZero.Click += new System.EventHandler(this.BtnSetZero_Click);
//
// txtFVEL
//
@@ -568,7 +568,7 @@
this.btnDisableAll.TabIndex = 7;
this.btnDisableAll.Text = "取消全部";
this.btnDisableAll.UseVisualStyleBackColor = true;
this.btnDisableAll.Click += new System.EventHandler(this.btnDisableAll_Click);
this.btnDisableAll.Click += new System.EventHandler(this.BtnDisableAll_Click);
//
// btnDisable
//
@@ -578,7 +578,7 @@
this.btnDisable.TabIndex = 7;
this.btnDisable.Text = "单轴取消";
this.btnDisable.UseVisualStyleBackColor = true;
this.btnDisable.Click += new System.EventHandler(this.btnDisable_Click);
this.btnDisable.Click += new System.EventHandler(this.BtnDisable_Click);
//
// cboAxisNo
//
@@ -588,7 +588,7 @@
this.cboAxisNo.Name = "cboAxisNo";
this.cboAxisNo.Size = new System.Drawing.Size(60, 20);
this.cboAxisNo.TabIndex = 0;
this.cboAxisNo.SelectedIndexChanged += new System.EventHandler(this.cboAxisNo_SelectedIndexChanged);
this.cboAxisNo.SelectedIndexChanged += new System.EventHandler(this.CboAxisNo_SelectedIndexChanged);
//
// btnEnable
//
@@ -598,7 +598,7 @@
this.btnEnable.TabIndex = 7;
this.btnEnable.Text = "单轴使能";
this.btnEnable.UseVisualStyleBackColor = true;
this.btnEnable.Click += new System.EventHandler(this.btnEnable_Click);
this.btnEnable.Click += new System.EventHandler(this.BtnEnable_Click);
//
// grpJog
//
@@ -621,8 +621,8 @@
this.btnJogPos.TabIndex = 8;
this.btnJogPos.Text = "正向 >>";
this.btnJogPos.UseVisualStyleBackColor = true;
this.btnJogPos.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnJogPos_MouseDown);
this.btnJogPos.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnJog_MouseUp);
this.btnJogPos.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BtnJogPos_MouseDown);
this.btnJogPos.MouseUp += new System.Windows.Forms.MouseEventHandler(this.BtnJog_MouseUp);
//
// btnJogNeg
//
@@ -632,8 +632,8 @@
this.btnJogNeg.TabIndex = 8;
this.btnJogNeg.Text = "<< 负向";
this.btnJogNeg.UseVisualStyleBackColor = true;
this.btnJogNeg.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnJogNeg_MouseDown);
this.btnJogNeg.MouseUp += new System.Windows.Forms.MouseEventHandler(this.btnJog_MouseUp);
this.btnJogNeg.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BtnJogNeg_MouseDown);
this.btnJogNeg.MouseUp += new System.Windows.Forms.MouseEventHandler(this.BtnJog_MouseUp);
//
// txtJogVel
//
@@ -800,7 +800,7 @@
this.btnPTP_R_Pos.TabIndex = 7;
this.btnPTP_R_Pos.Text = "相对位置 (+)";
this.btnPTP_R_Pos.UseVisualStyleBackColor = true;
this.btnPTP_R_Pos.Click += new System.EventHandler(this.btnPTP_R_Pos_Click);
this.btnPTP_R_Pos.Click += new System.EventHandler(this.BtnPTP_R_Pos_Click);
//
// btnPTP_R_Neg
//
@@ -810,7 +810,7 @@
this.btnPTP_R_Neg.TabIndex = 7;
this.btnPTP_R_Neg.Text = "相对位置 (-)";
this.btnPTP_R_Neg.UseVisualStyleBackColor = true;
this.btnPTP_R_Neg.Click += new System.EventHandler(this.btnPTP_R_Neg_Click);
this.btnPTP_R_Neg.Click += new System.EventHandler(this.BtnPTP_R_Neg_Click);
//
// btnPTP
//
@@ -820,7 +820,7 @@
this.btnPTP.TabIndex = 7;
this.btnPTP.Text = "移动到绝对位置";
this.btnPTP.UseVisualStyleBackColor = true;
this.btnPTP.Click += new System.EventHandler(this.btnPTP_Click);
this.btnPTP.Click += new System.EventHandler(this.BtnPTP_Click);
//
// txtPTP_Pos
//
@@ -1191,7 +1191,7 @@
this.btnStopBuffer.TabIndex = 8;
this.btnStopBuffer.Text = "停止";
this.btnStopBuffer.UseVisualStyleBackColor = true;
this.btnStopBuffer.Click += new System.EventHandler(this.btnStopBuffer_Click);
this.btnStopBuffer.Click += new System.EventHandler(this.BtnStopBuffer_Click);
//
// btnRunBuffer
//
@@ -1201,7 +1201,7 @@
this.btnRunBuffer.TabIndex = 8;
this.btnRunBuffer.Text = "启动";
this.btnRunBuffer.UseVisualStyleBackColor = true;
this.btnRunBuffer.Click += new System.EventHandler(this.btnRunBuffer_Click);
this.btnRunBuffer.Click += new System.EventHandler(this.BtnRunBuffer_Click);
//
// txtLabelName
//
@@ -1308,7 +1308,7 @@
this.btnSW7.TabIndex = 7;
this.btnSW7.Text = "OFF";
this.btnSW7.UseVisualStyleBackColor = true;
this.btnSW7.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW7.Click += new System.EventHandler(this.BtnSW_Click);
//
// btnSW6
//
@@ -1319,7 +1319,7 @@
this.btnSW6.TabIndex = 6;
this.btnSW6.Text = "OFF";
this.btnSW6.UseVisualStyleBackColor = true;
this.btnSW6.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW6.Click += new System.EventHandler(this.BtnSW_Click);
//
// btnSW5
//
@@ -1330,7 +1330,7 @@
this.btnSW5.TabIndex = 5;
this.btnSW5.Text = "OFF";
this.btnSW5.UseVisualStyleBackColor = true;
this.btnSW5.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW5.Click += new System.EventHandler(this.BtnSW_Click);
//
// btnSW4
//
@@ -1341,7 +1341,7 @@
this.btnSW4.TabIndex = 4;
this.btnSW4.Text = "OFF";
this.btnSW4.UseVisualStyleBackColor = true;
this.btnSW4.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW4.Click += new System.EventHandler(this.BtnSW_Click);
//
// btnSW3
//
@@ -1352,7 +1352,7 @@
this.btnSW3.TabIndex = 3;
this.btnSW3.Text = "OFF";
this.btnSW3.UseVisualStyleBackColor = true;
this.btnSW3.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW3.Click += new System.EventHandler(this.BtnSW_Click);
//
// btnSW2
//
@@ -1363,7 +1363,7 @@
this.btnSW2.TabIndex = 2;
this.btnSW2.Text = "OFF";
this.btnSW2.UseVisualStyleBackColor = true;
this.btnSW2.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW2.Click += new System.EventHandler(this.BtnSW_Click);
//
// btnSW0
//
@@ -1374,7 +1374,7 @@
this.btnSW0.TabIndex = 0;
this.btnSW0.Text = "OFF";
this.btnSW0.UseVisualStyleBackColor = true;
this.btnSW0.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW0.Click += new System.EventHandler(this.BtnSW_Click);
//
// btnSW1
//
@@ -1385,7 +1385,7 @@
this.btnSW1.TabIndex = 1;
this.btnSW1.Text = "OFF";
this.btnSW1.UseVisualStyleBackColor = true;
this.btnSW1.Click += new System.EventHandler(this.btnSW_Click);
this.btnSW1.Click += new System.EventHandler(this.BtnSW_Click);
//
// label29
//
@@ -1650,7 +1650,7 @@
this.btnEventProgramEnd.TabIndex = 0;
this.btnEventProgramEnd.Text = "程序结束";
this.btnEventProgramEnd.UseVisualStyleBackColor = true;
this.btnEventProgramEnd.Click += new System.EventHandler(this.btnEventProgramEnd_Click);
this.btnEventProgramEnd.Click += new System.EventHandler(this.BtnEventProgramEnd_Click);
//
// btnEventMotionEnd
//
@@ -1660,7 +1660,7 @@
this.btnEventMotionEnd.TabIndex = 0;
this.btnEventMotionEnd.Text = "运动结束";
this.btnEventMotionEnd.UseVisualStyleBackColor = true;
this.btnEventMotionEnd.Click += new System.EventHandler(this.btnEventMotionEnd_Click);
this.btnEventMotionEnd.Click += new System.EventHandler(this.BtnEventMotionEnd_Click);
//
// rtxtTerminal
//
@@ -1690,7 +1690,7 @@
this.btnSend.TabIndex = 8;
this.btnSend.Text = "发送";
this.btnSend.UseVisualStyleBackColor = true;
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
this.btnSend.Click += new System.EventHandler(this.BtnSend_Click);
//
// txtCommand
//
@@ -1698,7 +1698,7 @@
this.txtCommand.Name = "txtCommand";
this.txtCommand.Size = new System.Drawing.Size(769, 21);
this.txtCommand.TabIndex = 7;
this.txtCommand.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtCommand_KeyPress);
this.txtCommand.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TxtCommand_KeyPress);
//
// groupBox5
//
+303 -310
View File
File diff suppressed because it is too large Load Diff
+3 -4
View File
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
@@ -28,14 +27,14 @@ using System.Windows.Forms;
namespace HexcalMC
{
static class Program
internal static class Program
{
[STAThread]
static void Main()
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainFrom());
}
}
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ScottPlot" version="4.1.68" targetFramework="net462" />
<package id="ScottPlot.WinForms" version="4.1.68" targetFramework="net462" />
<package id="ScottPlot" version="4.1.67" targetFramework="net462" />
<package id="ScottPlot.WinForms" version="4.1.67" targetFramework="net462" />
<package id="System.Drawing.Common" version="4.7.2" targetFramework="net462" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />