Commit 16cc676d 几米阳光

1

1 个父辈 b93747cb
...@@ -345,10 +345,10 @@ namespace OnlineStore.AutoInOutStore ...@@ -345,10 +345,10 @@ namespace OnlineStore.AutoInOutStore
} }
private void UpdateAutoPosition() private void UpdateAutoPosition()
{ {
int inoutPosition = ACServerManager.GetTargetPosition(inout.DeviceName, inout.GetAxisValue()); int autoPosition = ACServerManager.GetTargetPosition(auto.DeviceName, auto.GetAxisValue());
if (!txtInOutPosition.Text.Equals(inoutPosition.ToString())) if (!txtAutoPosition.Text.Equals(autoPosition.ToString()))
{ {
txtInOutPosition.Text = inoutPosition.ToString(); txtAutoPosition.Text = autoPosition.ToString();
} }
} }
private void btnAutoMove_MouseDown(object sender, MouseEventArgs e) private void btnAutoMove_MouseDown(object sender, MouseEventArgs e)
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.btnSXil = new System.Windows.Forms.Button(); this.btnSXil = new System.Windows.Forms.Button();
this.btnSXi = new System.Windows.Forms.Button(); this.btnSXi = new System.Windows.Forms.Button();
this.btnDClose = new System.Windows.Forms.Button(); this.btnDClose = new System.Windows.Forms.Button();
...@@ -52,10 +56,6 @@ ...@@ -52,10 +56,6 @@
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.groupBox3 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBox4.SuspendLayout(); this.groupBox4.SuspendLayout();
this.groupBox3.SuspendLayout(); this.groupBox3.SuspendLayout();
...@@ -106,11 +106,55 @@ ...@@ -106,11 +106,55 @@
this.groupBox1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.groupBox1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.groupBox1.Location = new System.Drawing.Point(482, 8); this.groupBox1.Location = new System.Drawing.Point(482, 8);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(382, 514); this.groupBox1.Size = new System.Drawing.Size(382, 553);
this.groupBox1.TabIndex = 105; this.groupBox1.TabIndex = 105;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "DO写入"; this.groupBox1.Text = "DO写入";
// //
// button4
//
this.button4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button4.Location = new System.Drawing.Point(143, 438);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(102, 34);
this.button4.TabIndex = 266;
this.button4.Text = "停止吹气";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button5.Location = new System.Drawing.Point(143, 401);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(102, 34);
this.button5.TabIndex = 265;
this.button5.Text = "开始吹气";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button2.Location = new System.Drawing.Point(263, 260);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(102, 34);
this.button2.TabIndex = 264;
this.button2.Text = "关闭运转ON";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button3.Location = new System.Drawing.Point(263, 223);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(102, 34);
this.button3.TabIndex = 263;
this.button3.Text = "打开运转ON";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// btnSXil // btnSXil
// //
this.btnSXil.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnSXil.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
...@@ -432,7 +476,7 @@ ...@@ -432,7 +476,7 @@
// button1 // button1
// //
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button1.Location = new System.Drawing.Point(683, 531); this.button1.Location = new System.Drawing.Point(683, 570);
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(126, 37); this.button1.Size = new System.Drawing.Size(126, 37);
this.button1.TabIndex = 254; this.button1.TabIndex = 254;
...@@ -447,7 +491,7 @@ ...@@ -447,7 +491,7 @@
this.chbAutoRead.Checked = true; this.chbAutoRead.Checked = true;
this.chbAutoRead.CheckState = System.Windows.Forms.CheckState.Checked; this.chbAutoRead.CheckState = System.Windows.Forms.CheckState.Checked;
this.chbAutoRead.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.chbAutoRead.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbAutoRead.Location = new System.Drawing.Point(546, 536); this.chbAutoRead.Location = new System.Drawing.Point(546, 575);
this.chbAutoRead.Name = "chbAutoRead"; this.chbAutoRead.Name = "chbAutoRead";
this.chbAutoRead.Size = new System.Drawing.Size(75, 21); this.chbAutoRead.Size = new System.Drawing.Size(75, 21);
this.chbAutoRead.TabIndex = 244; this.chbAutoRead.TabIndex = 244;
...@@ -461,7 +505,7 @@ ...@@ -461,7 +505,7 @@
this.groupBox4.Controls.Add(this.tableLayoutPanel2); this.groupBox4.Controls.Add(this.tableLayoutPanel2);
this.groupBox4.Location = new System.Drawing.Point(247, 8); this.groupBox4.Location = new System.Drawing.Point(247, 8);
this.groupBox4.Name = "groupBox4"; this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(229, 562); this.groupBox4.Size = new System.Drawing.Size(229, 601);
this.groupBox4.TabIndex = 104; this.groupBox4.TabIndex = 104;
this.groupBox4.TabStop = false; this.groupBox4.TabStop = false;
this.groupBox4.Text = "DO列表"; this.groupBox4.Text = "DO列表";
...@@ -478,7 +522,7 @@ ...@@ -478,7 +522,7 @@
this.tableLayoutPanel2.RowCount = 2; this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F)); this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(218, 542); this.tableLayoutPanel2.Size = new System.Drawing.Size(218, 581);
this.tableLayoutPanel2.TabIndex = 103; this.tableLayoutPanel2.TabIndex = 103;
// //
// groupBox3 // groupBox3
...@@ -488,7 +532,7 @@ ...@@ -488,7 +532,7 @@
this.groupBox3.Controls.Add(this.tableLayoutPanel1); this.groupBox3.Controls.Add(this.tableLayoutPanel1);
this.groupBox3.Location = new System.Drawing.Point(12, 8); this.groupBox3.Location = new System.Drawing.Point(12, 8);
this.groupBox3.Name = "groupBox3"; this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(229, 562); this.groupBox3.Size = new System.Drawing.Size(229, 601);
this.groupBox3.TabIndex = 103; this.groupBox3.TabIndex = 103;
this.groupBox3.TabStop = false; this.groupBox3.TabStop = false;
this.groupBox3.Text = "DI列表"; this.groupBox3.Text = "DI列表";
...@@ -505,58 +549,14 @@ ...@@ -505,58 +549,14 @@
this.tableLayoutPanel1.RowCount = 2; this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(218, 542); this.tableLayoutPanel1.Size = new System.Drawing.Size(218, 581);
this.tableLayoutPanel1.TabIndex = 102; this.tableLayoutPanel1.TabIndex = 102;
// //
// button2
//
this.button2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button2.Location = new System.Drawing.Point(263, 260);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(102, 34);
this.button2.TabIndex = 264;
this.button2.Text = "关闭运转ON";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button3.Location = new System.Drawing.Point(263, 223);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(102, 34);
this.button3.TabIndex = 263;
this.button3.Text = "打开运转ON";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button4.Location = new System.Drawing.Point(143, 438);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(102, 34);
this.button4.TabIndex = 266;
this.button4.Text = "停止吹气";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.button5.Location = new System.Drawing.Point(143, 401);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(102, 34);
this.button5.TabIndex = 265;
this.button5.Text = "开始吹气";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// FrmIOStatus // FrmIOStatus
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(876, 580); this.ClientSize = new System.Drawing.Size(876, 619);
this.Controls.Add(this.button1); this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox4);
......
...@@ -334,7 +334,7 @@ namespace OnlineStore.AutoInOutStore ...@@ -334,7 +334,7 @@ namespace OnlineStore.AutoInOutStore
btnBatchInStore.Enabled = !dooIsOpen; btnBatchInStore.Enabled = !dooIsOpen;
btnGetOutTray.Enabled = !dooIsOpen; btnGetOutTray.Enabled = !dooIsOpen;
btnStartBatchInStore.Enabled = dooIsOpen; btnStartBatchInStore.Enabled = dooIsOpen;
btnBatchReset.Enabled = dooIsOpen; btnBatchReset.Enabled = !dooIsOpen;
} }
private void ReadPosistion() private void ReadPosistion()
......
...@@ -13,7 +13,7 @@ using OnlineStore.LoadCSVLibrary; ...@@ -13,7 +13,7 @@ using OnlineStore.LoadCSVLibrary;
namespace OnlineStore.DeviceLibrary namespace OnlineStore.DeviceLibrary
{ {
public class MasterTcpClient public class MasterTcpClient
{ {
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
...@@ -70,7 +70,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -70,7 +70,7 @@ namespace OnlineStore.DeviceLibrary
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/// <summary>Response data event. This event is called when new data arrives</summary> /// <summary>Response data event. This event is called when new data arrives</summary>
public delegate void ResponseData(string ip, ushort id, byte function, byte[] data,byte[] reviceData); public delegate void ResponseData(string ip, ushort id, byte function, byte[] data, byte[] reviceData);
/// <summary>Response data event. This event is called when new data arrives</summary> /// <summary>Response data event. This event is called when new data arrives</summary>
public event ResponseData OnResponseData; public event ResponseData OnResponseData;
/// <summary>Exception data event. This event is called when the data is incorrect</summary> /// <summary>Exception data event. This event is called when the data is incorrect</summary>
...@@ -84,33 +84,32 @@ namespace OnlineStore.DeviceLibrary ...@@ -84,33 +84,32 @@ namespace OnlineStore.DeviceLibrary
public bool autoConnectOfBreak public bool autoConnectOfBreak
{ {
get { return _autoConnectOfBreak; } get { return _autoConnectOfBreak; }
set { _autoConnectOfBreak = value; } set { _autoConnectOfBreak = value; }
} }
public static ushort timeout public static ushort timeout
{ {
get { return _timeout; } get { return _timeout; }
set { _timeout = value; } set { _timeout = value; }
} }
public ushort refresh public ushort refresh
{ {
get { return _refresh; } get { return _refresh; }
set { _refresh = value; } set { _refresh = value; }
} }
public bool connected public bool connected
{ {
get { return _connected; } get { return _connected; }
} }
public MasterTcpClient() public MasterTcpClient()
{ {
} }
private string IP = "";
public int TimeOutTime = 0; public int TimeOutTime = 0;
public MasterTcpClient(string ip, ushort port) public MasterTcpClient(string ip, ushort port)
{ {
this.IP = ip;
TimeOutTime = 2000; TimeOutTime = 2000;
connect(ip, port); connect(ip, port);
} }
...@@ -119,6 +118,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -119,6 +118,7 @@ namespace OnlineStore.DeviceLibrary
{ {
try try
{ {
OnResponseData = null;
// Connect asynchronous client // Connect asynchronous client
socketClient = new Socket(IPAddress.Parse(ip).AddressFamily, SocketType.Stream, ProtocolType.Tcp); socketClient = new Socket(IPAddress.Parse(ip).AddressFamily, SocketType.Stream, ProtocolType.Tcp);
if (TimeOutTime <= 0) if (TimeOutTime <= 0)
...@@ -126,7 +126,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -126,7 +126,8 @@ namespace OnlineStore.DeviceLibrary
socketClient.Connect(new IPEndPoint(IPAddress.Parse(ip), port)); socketClient.Connect(new IPEndPoint(IPAddress.Parse(ip), port));
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, _timeout); socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout); socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1); socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
} }
else else
{ {
...@@ -153,11 +154,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -153,11 +154,10 @@ namespace OnlineStore.DeviceLibrary
reviceTimer.Enabled = true; reviceTimer.Enabled = true;
_connected = true; _connected = true;
} }
catch (System.IO.IOException error) catch (Exception error)
{ {
LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " fail!"); LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " fail!");
_connected = false; _connected = false;
throw (error);
} }
} }
...@@ -166,12 +166,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -166,12 +166,12 @@ namespace OnlineStore.DeviceLibrary
try try
{ {
//socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient); //socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient);
ReviceDataProcess(); ReviceDataProcess();
Thread.Sleep(10); Thread.Sleep(10);
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error("IO模块["+IP+"]出错:" + ex.ToString()); LOGGER.Error("出错:" + ex.ToString());
} }
} }
...@@ -198,7 +198,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -198,7 +198,7 @@ namespace OnlineStore.DeviceLibrary
byte dataLength = rdata[lengthIndex]; byte dataLength = rdata[lengthIndex];
int allLength = lengthIndex + 1 + dataLength; int allLength = lengthIndex + 1 + dataLength;
if (rdata.Length > allLength) if (rdata.Length > allLength)
{ {
//LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str); //LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str);
...@@ -214,8 +214,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -214,8 +214,8 @@ namespace OnlineStore.DeviceLibrary
} }
dataLength = rdata[currStartIndex + lengthIndex]; dataLength = rdata[currStartIndex + lengthIndex];
allLength = lengthIndex + 1 + dataLength ; allLength = lengthIndex + 1 + dataLength;
byte[] thisData = new byte[allLength]; byte[] thisData = new byte[allLength];
Array.Copy(rdata, currStartIndex, thisData, 0, allLength); Array.Copy(rdata, currStartIndex, thisData, 0, allLength);
ushort id = BitConverter.ToUInt16(thisData, 0); ushort id = BitConverter.ToUInt16(thisData, 0);
...@@ -233,7 +233,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -233,7 +233,7 @@ namespace OnlineStore.DeviceLibrary
{ {
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString()); LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString());
} }
} }
} }
else else
...@@ -241,7 +241,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -241,7 +241,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.debug(LOGGER, clientipe.ToString() + "收到数据(无需分包):" + str); LogUtil.debug(LOGGER, clientipe.ToString() + "收到数据(无需分包):" + str);
ushort id = BitConverter.ToUInt16(rdata, 0); ushort id = BitConverter.ToUInt16(rdata, 0);
byte function = rdata[7]; byte function = rdata[7];
DataProcess(clientipe.ToString(),id,function,rdata); DataProcess(clientipe.ToString(), id, function, rdata);
} }
} }
} }
...@@ -273,11 +273,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -273,11 +273,11 @@ namespace OnlineStore.DeviceLibrary
// Response data is regular data // Response data is regular data
else if (OnResponseData != null) else if (OnResponseData != null)
{ //收到的数据打印出来 { //收到的数据打印出来
OnResponseData(clientIp, id, function, data, rdata); OnResponseData(clientIp, id, function, data, rdata);
} }
} }
private byte[] Receive() private byte[] Receive()
{ {
try try
...@@ -286,16 +286,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -286,16 +286,15 @@ namespace OnlineStore.DeviceLibrary
{ {
return null; return null;
} }
int size = socketClient.Available; int size = socketClient.Available;
byte[] rData = new byte[size]; byte[] rData = new byte[size];
socketClient.Receive(rData, size, SocketFlags.None); socketClient.Receive(rData, size, SocketFlags.None);
return rData; return rData;
} }
catch (SocketException e) catch (SocketException e)
{ {
LogUtil.error(LOGGER, "IO模块[" + IP + "]接收数据出现错误:" + e.ToString());
if (socketClient != null) if (socketClient != null)
{ {
socketClient.Close(); socketClient.Close();
...@@ -304,8 +303,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -304,8 +303,8 @@ namespace OnlineStore.DeviceLibrary
return null; return null;
} }
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/// <summary>Stop connection to slave.</summary> /// <summary>Stop connection to slave.</summary>
public void disconnect() public void disconnect()
...@@ -329,18 +328,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -329,18 +328,12 @@ namespace OnlineStore.DeviceLibrary
{ {
if (socketClient.Connected) if (socketClient.Connected)
{ {
try try { socketClient.Shutdown(SocketShutdown.Both); }
{ catch { }
socketClient.Shutdown(SocketShutdown.Both);
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "IO模块[" + IP + "]dispose出错:" + ex.ToString());
}
socketClient.Close(); socketClient.Close();
} }
socketClient = null; socketClient = null;
} }
} }
internal void CallException(ushort id, byte function, byte exception, byte[] rdata) internal void CallException(ushort id, byte function, byte exception, byte[] rdata)
...@@ -362,23 +355,23 @@ namespace OnlineStore.DeviceLibrary ...@@ -362,23 +355,23 @@ namespace OnlineStore.DeviceLibrary
OnException(socketClient.RemoteEndPoint.AddressFamily.ToString(), id, function, exception, rdata); OnException(socketClient.RemoteEndPoint.AddressFamily.ToString(), id, function, exception, rdata);
} }
} }
public void ReadCoils(ushort id, ushort startAddress, ushort numInputs, byte SlaveID) public void ReadCoils(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{ {
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadCoil, SlaveID), id); WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadCoil, SlaveID), id);
} }
public void ReadDiscreteInputs(ushort id, ushort startAddress, ushort numInputs, byte SlaveID) public void ReadDiscreteInputs(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{ {
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadDiscreteInputs, SlaveID), id); WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadDiscreteInputs, SlaveID), id);
} }
public void ReadHoldingRegister(ushort id, ushort startAddress, ushort numInputs, byte SlaveID) public void ReadHoldingRegister(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{ {
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadHoldingRegister, SlaveID), id); WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadHoldingRegister, SlaveID), id);
} }
public void ReadInputRegister(ushort id, ushort startAddress, ushort numInputs, byte SlaveID) public void ReadInputRegister(ushort id, ushort startAddress, ushort numInputs, byte SlaveID)
{ {
WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadInputRegister, SlaveID), id); WriteAsyncData(CreateReadHeader(id, startAddress, numInputs, fctReadInputRegister, SlaveID), id);
} }
public void WriteSingleCoils(ushort id, ushort startAddress, IO_VALUE ioValue, byte SlaveID) public void WriteSingleCoils(ushort id, ushort startAddress, IO_VALUE ioValue, byte SlaveID)
{ {
byte[] data; byte[] data;
...@@ -388,7 +381,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -388,7 +381,7 @@ namespace OnlineStore.DeviceLibrary
else data[10] = 0; else data[10] = 0;
WriteAsyncData(data, id); WriteAsyncData(data, id);
} }
public void WriteMultipleCoils(ushort id, ushort startAddress, ushort numBits, byte[] values, byte SlaveID) public void WriteMultipleCoils(ushort id, ushort startAddress, ushort numBits, byte[] values, byte SlaveID)
{ {
byte numBytes = Convert.ToByte(values.Length); byte numBytes = Convert.ToByte(values.Length);
...@@ -396,8 +389,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -396,8 +389,8 @@ namespace OnlineStore.DeviceLibrary
data = CreateWriteHeader(id, startAddress, numBits, (byte)(numBytes + 2), fctWriteMultipleCoils, SlaveID); data = CreateWriteHeader(id, startAddress, numBits, (byte)(numBytes + 2), fctWriteMultipleCoils, SlaveID);
Array.Copy(values, 0, data, 13, numBytes); Array.Copy(values, 0, data, 13, numBytes);
WriteAsyncData(data, id); WriteAsyncData(data, id);
} }
public void WriteSingleRegister(ushort id, ushort startAddress, byte[] values, byte SlaveID) public void WriteSingleRegister(ushort id, ushort startAddress, byte[] values, byte SlaveID)
{ {
byte[] data; byte[] data;
...@@ -405,8 +398,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -405,8 +398,8 @@ namespace OnlineStore.DeviceLibrary
data[10] = values[0]; data[10] = values[0];
data[11] = values[1]; data[11] = values[1];
WriteAsyncData(data, id); WriteAsyncData(data, id);
} }
public void WriteMultipleRegister(ushort id, ushort startAddress, byte[] values, byte SlaveID) public void WriteMultipleRegister(ushort id, ushort startAddress, byte[] values, byte SlaveID)
{ {
ushort numBytes = Convert.ToUInt16(values.Length); ushort numBytes = Convert.ToUInt16(values.Length);
...@@ -416,8 +409,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -416,8 +409,8 @@ namespace OnlineStore.DeviceLibrary
data = CreateWriteHeader(id, startAddress, Convert.ToUInt16(numBytes / 2), Convert.ToUInt16(numBytes + 2), fctWriteMultipleRegister, SlaveID); data = CreateWriteHeader(id, startAddress, Convert.ToUInt16(numBytes / 2), Convert.ToUInt16(numBytes + 2), fctWriteMultipleRegister, SlaveID);
Array.Copy(values, 0, data, 13, values.Length); Array.Copy(values, 0, data, 13, values.Length);
WriteAsyncData(data, id); WriteAsyncData(data, id);
} }
public void ReadWriteMultipleRegister(ushort id, ushort startReadAddress, ushort numInputs, ushort startWriteAddress, byte SlaveID, byte[] values) public void ReadWriteMultipleRegister(ushort id, ushort startReadAddress, ushort numInputs, ushort startWriteAddress, byte SlaveID, byte[] values)
{ {
ushort numBytes = Convert.ToUInt16(values.Length); ushort numBytes = Convert.ToUInt16(values.Length);
...@@ -429,7 +422,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -429,7 +422,7 @@ namespace OnlineStore.DeviceLibrary
WriteAsyncData(data, id); WriteAsyncData(data, id);
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Create modbus header for read action // Create modbus header for read action
private byte[] CreateReadHeader(ushort id, ushort startAddress, ushort length, byte function, byte SlaveID) private byte[] CreateReadHeader(ushort id, ushort startAddress, ushort length, byte function, byte SlaveID)
...@@ -511,39 +504,45 @@ namespace OnlineStore.DeviceLibrary ...@@ -511,39 +504,45 @@ namespace OnlineStore.DeviceLibrary
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Write asynchronous data // Write asynchronous data
private void WriteAsyncData(byte[] write_data, ushort id) public void WriteAsyncData(byte[] write_data, ushort id)
{ {
if (socketClient == null) try
{
LOGGER.Error("发送数据时发现socketClient=null");
return;
}
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
if ((socketClient != null) && (socketClient.Connected))
{ {
try if (socketClient == null)
{ {
//发送的数据打印出来 LOGGER.Error("发送数据时发现socketClient=null");
string str = ""; return;
foreach (byte by in write_data)
{
str = str +" "+ by;
}
//LogUtil.info( clientipe.ToString()+"发送数据:" + str);
socketClient.BeginSend(write_data, 0, write_data.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
//socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient);
ReviceDataProcess();
} }
catch (SystemException error) IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
if ((socketClient != null) && (socketClient.Connected))
{ {
LogUtil.error(LOGGER, "IO模块 WriteAsyncData出错:" + error.ToString()); try
CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer); {
//发送的数据打印出来
string str = "";
foreach (byte by in write_data)
{
str = str + " " + by;
}
//LogUtil.info( clientipe.ToString()+"发送数据:" + str);
socketClient.BeginSend(write_data, 0, write_data.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
//socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient);
ReviceDataProcess();
}
catch (SystemException error)
{
CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
}
} }
else CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
}
catch (Exception ex)
{
LOGGER.Error("出错:" + ex.ToString());
} }
else CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Write asynchronous data acknowledge // Write asynchronous data acknowledge
private void OnSend(System.IAsyncResult result) private void OnSend(System.IAsyncResult result)
...@@ -560,7 +559,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -560,7 +559,8 @@ namespace OnlineStore.DeviceLibrary
return; return;
} }
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint; IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
if (result.IsCompleted == false) { if (result.IsCompleted == false)
{
CallException(0xFF, 0xFF, excExceptionConnectionLost, tcpSocketReviceBuffer); CallException(0xFF, 0xFF, excExceptionConnectionLost, tcpSocketReviceBuffer);
} }
...@@ -587,7 +587,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -587,7 +587,7 @@ namespace OnlineStore.DeviceLibrary
if (function > excExceptionOffset) if (function > excExceptionOffset)
{ {
function -= excExceptionOffset; function -= excExceptionOffset;
CallException(id, function, tcpSocketReviceBuffer[8],tcpSocketReviceBuffer); CallException(id, function, tcpSocketReviceBuffer[8], tcpSocketReviceBuffer);
} }
// ------------------------------------------------------------ // ------------------------------------------------------------
// Response data is regular data // Response data is regular data
...@@ -602,13 +602,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -602,13 +602,13 @@ namespace OnlineStore.DeviceLibrary
break; break;
} }
} }
// LogUtil.info( clientipe.ToString()+"收到数据:" + str); // LogUtil.info( clientipe.ToString()+"收到数据:" + str);
OnResponseData(clientipe.ToString(), id, function, data, tcpSocketReviceBuffer); OnResponseData(clientipe.ToString(), id, function, data, tcpSocketReviceBuffer);
} }
} }
internal bool ISConnection() internal bool ISConnection()
{ {
if (socketClient == null) if (socketClient == null)
{ {
return false; return false;
......
...@@ -9,7 +9,7 @@ DI,吸盘气缸上升端,SuckingDisc_Up,206,192.168.200.11,0,吸盘气缸上升端,X07,DI-07,0 ...@@ -9,7 +9,7 @@ DI,吸盘气缸上升端,SuckingDisc_Up,206,192.168.200.11,0,吸盘气缸上升端,X07,DI-07,0
DI,吸盘气缸下降端,SuckingDisc_Down,207,192.168.200.11,0,吸盘气缸下降端,X08,DI-08,0, DI,吸盘气缸下降端,SuckingDisc_Down,207,192.168.200.11,0,吸盘气缸下降端,X08,DI-08,0,
DI,料盘宽度检测1,WidthCheck1,208,192.168.200.11,0,料盘宽度检测1,X09,DI-09,0, DI,料盘宽度检测1,WidthCheck1,208,192.168.200.11,0,料盘宽度检测1,X09,DI-09,0,
DI,料盘宽度检测2,WidthCheck2,209,192.168.200.11,0,料盘宽度检测2,X10,DI-10,0, DI,料盘宽度检测2,WidthCheck2,209,192.168.200.11,0,料盘宽度检测2,X10,DI-10,0,
DI,料盘检测1(上料机构),TrayCheck_LoadMaterial ,210,192.168.200.11,0,料盘检测1(上料机构),X11,DI-11,0, DI,料盘检测1(上料机构),TrayCheck_LoadMaterial,210,192.168.200.11,0,料盘检测1(上料机构),X11,DI-11,0,
DI,上料机构出料检测,OutCheck,211,192.168.200.11,0,上料机构出料检测,X12,DI-12,0, DI,上料机构出料检测,OutCheck,211,192.168.200.11,0,上料机构出料检测,X12,DI-12,0,
DI,门锁气缸打开端,BatchDoor_Open,212,192.168.200.11,0,门锁气缸打开端,X13,DI-13,0, DI,门锁气缸打开端,BatchDoor_Open,212,192.168.200.11,0,门锁气缸打开端,X13,DI-13,0,
DI,门锁气缸关闭端,BatchDoor_Close,213,192.168.200.11,0,门锁气缸关闭端,X14,DI-14,0, DI,门锁气缸关闭端,BatchDoor_Close,213,192.168.200.11,0,门锁气缸关闭端,X14,DI-14,0,
...@@ -31,10 +31,10 @@ DO,门锁气缸打开SOL,AutoDoor_Open,112,192.168.200.11,0,门锁气缸打开SOL,Y13,DO-13, ...@@ -31,10 +31,10 @@ DO,门锁气缸打开SOL,AutoDoor_Open,112,192.168.200.11,0,门锁气缸打开SOL,Y13,DO-13,
DO,门锁气缸关闭SOL,AutoDoor_Close,113,192.168.200.11,0,门锁气缸关闭SOL,Y14,DO-14,0, DO,门锁气缸关闭SOL,AutoDoor_Close,113,192.168.200.11,0,门锁气缸关闭SOL,Y14,DO-14,0,
,,,114,192.168.200.11,0,,Y15,DO-15,0, ,,,114,192.168.200.11,0,,Y15,DO-15,0,
,,,115,192.168.200.11,0,,Y16,DO-16,0, ,,,115,192.168.200.11,0,,Y16,DO-16,0,
DI,上料机构门关闭,DoorClose_LoadMaterial,200,192.168.200.12,0,上料机构门关闭,X17,DI-21,0, DI,上料机构门关闭,DoorClose_LoadMaterial,200,192.168.200.12,0,上料机构门关闭,X21,DI-21,0,
DI,气压检测,Airpressure_Check,201,192.168.200.12,0,气压检测,X18,DI-22,0, DI,气压检测,Airpressure_Check,201,192.168.200.12,0,气压检测,X22,DI-22,0,
DI,吸盘压力确认信号,SuckingDisc_Air,202,192.168.200.12,0,吸盘压力确认信号,X19,DI-23,0, DI,吸盘压力确认信号,SuckingDisc_Air,202,192.168.200.12,0,吸盘压力确认信号,X23,DI-23,0,
DI,左侧门关闭,DoorColse_Single,203,192.168.200.12,0,左侧门关闭,X20,DI-24,0, DI,左侧门关闭,DoorColse_Single,203,192.168.200.12,0,左侧门关闭,X24,DI-24,0,
,,,100,192.168.200.12,0,,Y17,DO-21,0, ,,,100,192.168.200.12,0,,Y17,DO-21,0,
,,,101,192.168.200.12,0,,Y18,DO-22,0, ,,,101,192.168.200.12,0,,Y18,DO-22,0,
,,,102,192.168.200.12,0,,Y19,DO-23,0, ,,,102,192.168.200.12,0,,Y19,DO-23,0,
...@@ -142,5 +142,5 @@ PRO,(轴五)上料轴最大限位,BatchAxis_PositionMax,0,,,,,,, ...@@ -142,5 +142,5 @@ PRO,(轴五)上料轴最大限位,BatchAxis_PositionMax,0,,,,,,,
PRO,(轴五)上料轴P1速度,BatchAxis_P1_Speed,50,,,,,,, PRO,(轴五)上料轴P1速度,BatchAxis_P1_Speed,50,,,,,,,
,,,,,,,,,, ,,,,,,,,,,
,,,,,,,,,, ,,,,,,,,,,
PRO,IO模块对应的DI数量,IO_DILength,192.168.200.11#16;192.168.200.11#4,,,,,, , PRO,IO模块对应的DI数量,IO_DILength,192.168.200.11#16;192.168.200.12#4,,,,,, ,
PRO,模块对应的DO数量,IO_DOLength,192.168.200.11#16;192.168.200.11#4,,,,,,, PRO,模块对应的DO数量,IO_DOLength,192.168.200.11#16;192.168.200.12#4,,,,,,,
...@@ -86,6 +86,7 @@ namespace OnlineStore.LoadCSVLibrary ...@@ -86,6 +86,7 @@ namespace OnlineStore.LoadCSVLibrary
Dictionary<string, string> proMap = CSVReaderBase.getConfigProAttributeMap(GetType()); Dictionary<string, string> proMap = CSVReaderBase.getConfigProAttributeMap(GetType());
List<string> checkProList = new List<string>(proMap.Keys);//用来检测attribute属性都应该要配置值 List<string> checkProList = new List<string>(proMap.Keys);//用来检测attribute属性都应该要配置值
List<string> IoTypeList = IO_Type.GetTypeList();
foreach (ConfigBase con in configList) foreach (ConfigBase con in configList)
{ {
if (con.ProType == ConfigItemType.AXIS || con.ProType == ConfigItemType.PRO) if (con.ProType == ConfigItemType.AXIS || con.ProType == ConfigItemType.PRO)
...@@ -120,7 +121,7 @@ namespace OnlineStore.LoadCSVLibrary ...@@ -120,7 +121,7 @@ namespace OnlineStore.LoadCSVLibrary
} }
else if (con.ProType == ConfigItemType.DI) else if (con.ProType == ConfigItemType.DI)
{ {
if (IO_Type.GetTypeList().Contains(con.ProName)) if (IoTypeList.Contains(con.ProName))
{ {
ConfigIO io = (ConfigIO)con; ConfigIO io = (ConfigIO)con;
if (!DIODeviceNameList.Contains(io.DeviceName) && io.GetIOAddr() >= 0) if (!DIODeviceNameList.Contains(io.DeviceName) && io.GetIOAddr() >= 0)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!