Commit 07b72b9c 几米阳光

机器人调试修改

1 个父辈 55b8cbcc
......@@ -95,7 +95,6 @@
<Compile Include="util\AcSerialBean.cs" />
<Compile Include="util\SerialBean.cs" />
<Compile Include="util\StringUtil.cs" />
<Compile Include="util\URTcpClient.cs" />
<Compile Include="util\TcpClient.cs" />
<Compile Include="util\TcpServer.cs" />
<Compile Include="util\WaitUtil.cs" />
......
......@@ -188,7 +188,10 @@ namespace URSoldering.Common
{
urListenLog.Error(msg);
}
public static void URLDebug(string msg)
{
urListenLog.Debug(msg);
}
/// <summary>
......
......@@ -15,14 +15,12 @@ namespace URSoldering.Common
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public delegate void HandleMessage(string message);
public delegate void ByteHandleMessage(byte[] data);
public int DefaultDataLength = 1024;
public int ReviceSleepMS = 100;
private Socket m_clientSocket=null;
private Socket m_clientSocket = null;
private byte[] m_receiveBuffer = new byte[1024];
private string LogName = "";
private HandleMessage onReceived;
private ByteHandleMessage byteOnReceived;
public int TimeOutTime = 0;
/// <summary>
......@@ -91,20 +89,14 @@ namespace URSoldering.Common
return false;
}
}
public bool connect(string serverIP, int serverPort, ByteHandleMessage byteHandle)
{
return connect(serverIP, serverPort, null, byteHandle);
}
public bool connect(string serverIP, int serverPort, HandleMessage HandleMessage)
{
return connect(serverIP, serverPort, HandleMessage, null);
}
/// <summary>
/// 连接服务器
/// </summary>
private bool connect(string serverIP, int serverPort, HandleMessage HandleMessage,ByteHandleMessage byteHandle)
public bool connect(string serverIP, int serverPort, HandleMessage HandleMessage)
{
LogName = "【" + serverIP + " ," + serverPort + "】";
m_receiveBuffer = new byte[DefaultDataLength];
m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
if (TimeOutTime <= 0)
......@@ -124,21 +116,18 @@ namespace URSoldering.Common
{
onReceived = HandleMessage;
}
if (byteHandle != null)
{
byteOnReceived = byteHandle;
}
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " success!");
LogUtil.info(LOGGER, LogName+ "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
else
{
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " fail!");
LogUtil.info(LOGGER, LogName + "Connect to " + serverIP + ":" + serverPort + " fail!");
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(), 3);
LogUtil.error(LOGGER, LogName + "Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(), 3);
//m_clientSocket = null;
}
}
......@@ -150,9 +139,9 @@ namespace URSoldering.Common
connResult.AsyncWaitHandle.WaitOne(this.TimeOutTime, true); //等待2秒
if (!connResult.IsCompleted||(!m_clientSocket.Connected))
if (!connResult.IsCompleted || (!m_clientSocket.Connected))
{
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " fail!");
LogUtil.info(LOGGER, LogName + "Connect to " + serverIP + ":" + serverPort + " fail!");
m_clientSocket.Close();
//处理连接不成功的动作
return false;
......@@ -165,11 +154,8 @@ namespace URSoldering.Common
{
onReceived = HandleMessage;
}
if (byteHandle != null)
{
byteOnReceived = byteHandle;
}
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " success!");
LogUtil.info(LOGGER, LogName + "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
}
......@@ -183,20 +169,21 @@ namespace URSoldering.Common
{
try
{
if (m_clientSocket != null&&m_clientSocket.Connected)
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Shutdown(SocketShutdown.Both);
m_clientSocket.Close();
LogUtil.info(LOGGER, "Socket closed!");
LogUtil.info(LOGGER, LogName + "Socket closed!");
}
else
{
LogUtil.error(LOGGER, "No socket is running!");
LogUtil.error(LOGGER, LogName + "No socket is running!");
}
m_clientSocket = null;
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "close error :" + ex.ToString());
LogUtil.error(LOGGER, LogName + "close error :" + ex.ToString());
}
}
......@@ -211,7 +198,7 @@ namespace URSoldering.Common
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug(LOGGER, "Send >> " + strSendData);
LogUtil.debug(LOGGER, LogName + "Send >> " + strSendData);
}
}
/// <summary>
......@@ -219,14 +206,7 @@ namespace URSoldering.Common
/// </summary>
public void sendLine(string strSendData)
{
if (strSendData.StartsWith("save"))
{
LogUtil.debug(LOGGER, "发送数据:" + strSendData);
}
else
{
LogUtil.debug(LOGGER, "发送数据:" + strSendData);
}
strSendData = strSendData + "\r\n";
byte[] sendBuffer = new byte[DefaultDataLength];
......@@ -235,7 +215,7 @@ namespace URSoldering.Common
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug(LOGGER, "Send >> " + strSendData);
LogUtil.debug(LOGGER, LogName + "Send >> " + strSendData);
}
}
......@@ -247,17 +227,18 @@ namespace URSoldering.Common
if (m_clientSocket != null && m_clientSocket.Connected)
{
int REnd = m_clientSocket.EndReceive(ar);
byteOnReceived?.Invoke(m_receiveBuffer);
string strReceiveData = Encoding.Default.GetString(m_receiveBuffer, 0, REnd);
onReceived?.Invoke(strReceiveData);
Thread.Sleep(ReviceSleepMS);
//LOGGER.Debug("m_clientSocket:" + m_clientSocket + "\n m_receiveBuffer" + m_receiveBuffer);
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "socket received error:" + ex.ToString(), 4);
LogUtil.error(LOGGER, LogName + "socket received error:" + ex.ToString(), 4);
}
}
}
......
......@@ -107,7 +107,7 @@ namespace URSoldering.Common
{
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
byteOnReceived = byteHandle;
LogUtil.URLInfo("Connect to " + LogName + " success");
LogUtil.URLDebug("Connect to " + LogName + " success");
return true;
}
else
......@@ -161,7 +161,7 @@ namespace URSoldering.Common
{
m_clientSocket.Shutdown(SocketShutdown.Both);
m_clientSocket.Close();
LogUtil.URLInfo(LogName + "Socket closed!");
LogUtil.URLDebug(LogName + "Socket closed!");
}
else
{
......@@ -309,11 +309,11 @@ namespace URSoldering.Common
{
byteOnReceived(m_receiveBuffer);
});
Thread.Sleep(ReviceSleepMS);
// Thread.Sleep(ReviceSleepMS);
//LOGGER.Debug("m_clientSocket:" + m_clientSocket + "\n m_receiveBuffer" + m_receiveBuffer);
//Task.Factory.StartNew(delegate ()
//{
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
//m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
//});
}
}
......
......@@ -98,6 +98,7 @@
<Compile Include="deviceLibrary\kangnaide\MasterTcpClient.cs" />
<Compile Include="deviceLibrary\urRobot\URRobotControl.cs" />
<Compile Include="deviceLibrary\urRobot\URRobotClient.cs" />
<Compile Include="deviceLibrary\urRobot\URTcpClient.cs" />
<Compile Include="Robot\MoveType.cs" />
<Compile Include="Robot\soldering\AlarmType.cs" />
<Compile Include="bean\BoardManager.cs" />
......
......@@ -71,19 +71,16 @@ namespace URSoldering.DeviceLibrary
{
listenClient.sendLine(LastMoveCMD);
LastMoveCMD = "";
//Thread.Sleep(50);
}
StopListen();
try
{
//string reviceMsg = ByteToStr(reviceData);
//LogUtil.info("Read data:【" + reviceMsg + "】 ");
byte[] msgSizeArray = reviceData.Skip(0).Take(4).ToArray();
byte[] timeArray = reviceData.Skip(4).Take(8).ToArray();
byte[] qTargetArray = reviceData.Skip(12).Take(48).ToArray();
byte[] qdTargetArray = reviceData.Skip(60).Take(48).ToArray();
byte[] qddArray = reviceData.Skip(108).Take(48).ToArray();
byte[] iTargetArray = reviceData.Skip(156).Take(48).ToArray();
//byte[] timeArray = reviceData.Skip(4).Take(8).ToArray();
//byte[] qTargetArray = reviceData.Skip(12).Take(48).ToArray();
//byte[] qdTargetArray = reviceData.Skip(60).Take(48).ToArray();
//byte[] qddArray = reviceData.Skip(108).Take(48).ToArray();
//byte[] iTargetArray = reviceData.Skip(156).Take(48).ToArray();
int messageSize = BitToInt(reviceData.Skip(0).Take(4).ToArray().Reverse<byte>().ToArray());
int maxdouble = (messageSize - 4) / 8;
......@@ -114,7 +111,6 @@ namespace URSoldering.DeviceLibrary
}
if (doubleList.Count > 61)
{
string spilt = ",";
double x = doubleList[56] * 1000;
double y = doubleList[57] * 1000;
double z = doubleList[58] * 1000;
......@@ -122,16 +118,18 @@ namespace URSoldering.DeviceLibrary
double ry = doubleList[60] * 1;
double rz = doubleList[61] * 1;
URPointValue newp = new URPointValue(x, y, z, rx, ry, rz);
//string reviceMsg = ByteToStr(reviceData);
if (!URRobotControl.IsSamePoint(newp, URRobotControl.LastPoint))
{
LogUtil.URLInfo(LogName + "length[" + messageSize + "],data长[" + reviceData.Length + "]坐标" + newp.ToShowStr());
}
URRobotControl.LastPoint = newp;
string reviceMsg = ByteToStr(reviceData);
//LogUtil.info("Read data:【" + reviceMsg + "】 ");
LogUtil.URLInfo( LogName+"length[" + messageSize + "],data长[" + reviceData.Length + "]坐标"+newp.ToShowStr());
}
}
else
{
string reviceMsg = ByteToStr(reviceData);
//LogUtil.URLError(LogName + "Read data:【" + reviceMsg + "】 ");
LogUtil.URLError(LogName + "length[" + messageSize + "],data长[" + reviceData.Length + "]无法获取坐标,数据长度不正确");
}
}
......
......@@ -124,7 +124,7 @@ namespace URSoldering.DeviceLibrary
{
reconnectTimer = new System.Timers.Timer();
reconnectTimer.AutoReset = true;
reconnectTimer.Interval = 1000;
reconnectTimer.Interval = 400;
reconnectTimer.Elapsed += reconnectTimer_Elapsed;
reconnectTimer.Enabled = false;
}
......@@ -199,7 +199,7 @@ namespace URSoldering.DeviceLibrary
if (IsRun&& IsStartConnect)
{
TimeSpan span = DateTime.Now - preCheckTime;
if (span.TotalSeconds > 30)
if (span.TotalSeconds > 2)
{
preCheckTime = DateTime.Now;
//判断500在连接上,则获取急停状态
......@@ -415,7 +415,7 @@ namespace URSoldering.DeviceLibrary
{
IsRun = false;
startCount--;
controlTcp.sendLine(CMD_powerOff);
//controlTcp.sendLine(CMD_powerOff);
controlTcp.close();
}
catch (Exception ex)
......@@ -432,6 +432,7 @@ namespace URSoldering.DeviceLibrary
{
IsStartConnect = false;
reconnectTimer.Enabled = false;
URRobotClient.StopListen();
stopTcp();
}
catch (Exception ex)
......@@ -507,7 +508,7 @@ namespace URSoldering.DeviceLibrary
}
}return false;
}
private static bool IsSamePoint(URPointValue p1,URPointValue p2)
public static bool IsSamePoint(URPointValue p1,URPointValue p2)
{
if (p1 == null && p2 == null)
{
......@@ -519,7 +520,7 @@ namespace URSoldering.DeviceLibrary
double rxCha = Math.Abs(p1.RX - p2.RX);
double ryCha = Math.Abs(p1.RY - p2.RY);
double rzCha = Math.Abs(p1.RZ - p2.RZ);
if (xCha < 1 && yCha < 1 && zCha < 1 && rxCha < 0.01 && ryCha < 0.01 && rzCha < 0.01)
if (xCha < 1 && yCha < 1 && zCha < 1 && rxCha < 0.02 && ryCha < 0.02 && rzCha < 0.02)
{
return true;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!