Commit 38d34e00 LN

1

1 个父辈 3547a0c6
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.Discovery;
using ABB.Robotics.Controllers.IOSystemDomain;
using ABB.Robotics.Controllers.RapidDomain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ABBRobotTest
{
public class ABBRobotManager
{
private NetworkScanner scanner = null;
// private Controller controller = null;
private Task[] tasks = null;
private NetworkWatcher networkwatcher = null;
private Dictionary<string, Controller> controllerMap = new Dictionary<string, Controller>();
public void LoadController()
{
this.scanner = new NetworkScanner();
this.scanner.Scan();
ControllerInfoCollection controllers = scanner.Controllers;
int i = 0;
foreach (ControllerInfo controllerInfo in controllers)
{
Controller con = ControllerFactory.CreateFrom(controllerInfo);
con.Logon(UserInfo.DefaultUser);
ControllerState state = con.State;
controllerMap.Add(con.IPAddress.ToString(), con);
// controller = con;
i++;
}
this.networkwatcher = new NetworkWatcher(scanner.Controllers);
this.networkwatcher.Found += new EventHandler<NetworkWatcherEventArgs>(HandleFoundEvent);
this.networkwatcher.Lost += new EventHandler<NetworkWatcherEventArgs>(HandleLostEvent);
this.networkwatcher.EnableRaisingEvents = true;
}
private void HandleLostEvent(object sender, NetworkWatcherEventArgs e)
{
}
private void HandleFoundEvent(object sender, NetworkWatcherEventArgs e)
{
this.Invoke(new
EventHandler<NetworkWatcherEventArgs>(AddControllerToListView),
new Object[] { this, e });
}
private void Invoke(EventHandler<NetworkWatcherEventArgs> eventHandler, object[] v)
{
throw new NotImplementedException();
}
private void AddControllerToListView(object sender, NetworkWatcherEventArgs e)
{
//ControllerInfo controllerInfo = e.Controller; ListViewItem item
// = new ListViewItem(controllerInfo.IPAddress.ToString());
//item.SubItems.Add(controllerInfo.Id); item.SubItems.Add(controllerInfo.Availability.ToString()); item.SubItems.Add(controllerInfo.IsVirtual.ToString()); item.SubItems.Add(controllerInfo.SystemName); item.SubItems.Add(controllerInfo.Version.ToString()); item.SubItems.Add(controllerInfo.ControllerName); this.listView1.Items.Add(item); item.Tag
// = controllerInfo;
}
private void StartRobot(string ip)
{
try
{
Controller controller = GetControllerByIP(ip);
if (controller != null && controller.OperatingMode == ControllerOperatingMode.Auto)
{
tasks = controller.Rapid.GetTasks();
using (Mastership m = Mastership.Request(controller.Rapid))
{
tasks[0].SetProgramPointer("aaa", "main");
controller.State = ControllerState.MotorsOn;
controller.Rapid.Start();
//Perform operation
//tasks[0].Start();
m.Dispose();
}
}
else
{
Console.WriteLine("Automatic mode is required to start execution from a remote client.");
}
}
catch (System.InvalidOperationException ex)
{
Console.WriteLine("Mastership is held by another client." + ex.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("Unexpected error occurred: " + ex.Message);
}
}
private void StopRobot(string ip)
{
try
{
Controller controller = GetControllerByIP(ip);
if (controller != null && controller.OperatingMode == ControllerOperatingMode.Auto)
{
tasks = controller.Rapid.GetTasks();
using (Mastership m = Mastership.Request(controller.Rapid))
{
//tasks[0].SetProgramPointer("aaa", "main");
//controller.State = ControllerState.MotorsOn;
//controller.Rapid.Start();
//Perform operation
//tasks[0].Start();
controller.Rapid.Stop();
m.Dispose();
}
}
else
{
Console.WriteLine("Automatic mode is required to start execution from a remote client.");
}
}
catch (System.InvalidOperationException ex)
{
Console.WriteLine("Mastership is held by another client." + ex.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("Unexpected error occurred: " + ex.Message);
}
}
private void SetRobotSignal(string ip, string name)
{
Controller controller = GetControllerByIP(ip);
if (controller != null)
{
// string name = comboBox1.Text;
Signal singalValue = controller.IOSystem.GetSignal(name);
DigitalSignal digitalSig = (DigitalSignal)singalValue;
digitalSig.Set();
}
}
private void ResetRobotSignal(string ip, string name)
{
Controller controller = GetControllerByIP(ip);
if (controller != null)
{
//string name = comboBox1.Text;
Signal singalValue = controller.IOSystem.GetSignal(name);
DigitalSignal digitalSig = (DigitalSignal)singalValue;
digitalSig.Reset();
}
}
public string GetRobotState(string ip)
{
Controller controller = GetControllerByIP(ip);
if (controller != null)
{
ControllerState state = controller.State;
return state.ToString();
}
return "";
}
private Controller GetControllerByIP(string ip)
{
if (controllerMap.ContainsKey(ip))
{
return controllerMap[ip];
}
return null;
}
private void DisposeControllers()
{
foreach (Controller con in controllerMap.Values)
{
con.Logoff();
con.Dispose();
}
controllerMap.Clear();
}
}
}
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ABBRobotTest
{
public class ABBRobotServer
{
private static TcpServer tcpserver = null;
public static bool IsStart = false;
private static int ClientKeepSecond = 10;
private static int ServerPort = 21;
public static string ErrorInfo = "";
private static string MoveOK = "point ok";
private static string FreeOK = "free ok";
private static string LockOK = "lock ok";
private static string MoveCMD_1 = "move";
private static string MoveCMD_2 = "move2";
public static Dictionary<string, Client> ClientMap = new Dictionary<string, Client>();
//最后一次软件控制移动到的位置
public static string LastSendPoint = "";
public delegate void OpEnd(string result);
private static event OpEnd OnMoveEnd;
private static object LockObj = new object();
public static void StartServer(int port)
{
if (!IsStart)
{
ClientMap = new Dictionary<string, Client>();
if (tcpserver == null)
{
tcpserver = new TcpServer();
}
IsStart = true;
tcpserver.Start(port);
LogUtil.info( "ABBRobotServer在端口[" + port + "]监听!");
tcpserver.ReviceMsgEvent += tcp_ReviceMsgEvent;
}
}
public static void StopServer()
{
try
{
if (IsStart)
{
IsStart = false;
tcpserver.Stop();
}
}
catch (Exception ex)
{
LogUtil.error("关闭 监听出错:" + ex.ToString());
}
}
private static void tcp_ReviceMsgEvent(Client client, string msg)
{
try
{
if (String.IsNullOrEmpty(msg))
{
return;
}
ProcessMsg(client, msg);
}
catch (Exception ex)
{
LogUtil.error("处理料仓消息【" + msg + "】出错:" + ex.ToString());
}
}
private static bool ProcessMsg(Client client, string msg)
{
IPEndPoint clientipe = (IPEndPoint)client.ClientSocket.RemoteEndPoint;
string add = clientipe.Address.ToString();
// string[] msgArray = msg.Split(cmd_spilt);
msg = msg.Replace("\r", "");
LogUtil.debug("收到【" + add + "】的消息【" + msg + "】");
if (msg.ToUpper().Contains("ERROR"))
{
}else if(msg.ToUpper().Contains("MOVE")&& msg.ToUpper().Contains("OK"))
{
OnMoveEnd?.Invoke(msg);
}
else if (msg.ToUpper().Contains("MOVE2") && msg.ToUpper().Contains("OK"))
{
OnMoveEnd?.Invoke(msg);
}
return false;
}
public static void MoveTo(string robotIp, string PointName, string moveType="L" , double targetSpeed = 100, OpEnd AfterMove = null)
{
ABBRobotServer.OnMoveEnd = AfterMove;
SendMovePoint(robotIp, MoveCMD_1,PointName,moveType,targetSpeed.ToString());
}
public static void Move2To(string robotIp, string PointName, string moveType = "L", double targetSpeed = 100, OpEnd AfterMove = null)
{
ABBRobotServer.OnMoveEnd = AfterMove;
SendMovePoint(robotIp, MoveCMD_2, PointName, moveType, targetSpeed.ToString());
}
private static void SendMovePoint(string robotIp, string param1,string param2,string param3,string param4)
{
lock (LockObj)
{
if (ClientMap.ContainsKey(robotIp))
{
Client client = ClientMap[robotIp];
string str = param1 + "," + param2 + "," + param3 + "," + param4+"\r\n";
LastSendPoint = param2;
SendStrToClient(client, str);
}
}
}
private static bool SendStrToClient(Client client, string sendMsg)
{
if (client != null && client.ClientSocket.Connected)
{
byte[] sendBuffer = new byte[1024];
sendBuffer = Encoding.UTF8.GetBytes(sendMsg);
client.ClientSocket.Send(sendBuffer);
return true;
}
return false;
}
}
}
......@@ -55,6 +55,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ABBRobotServer.cs" />
<Compile Include="ABBRobotManager.cs" />
<Compile Include="FrmRobotTest.cs">
<SubType>Form</SubType>
</Compile>
......@@ -88,5 +90,11 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\source\Common\Common.csproj">
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
此文件类型无法预览
此文件类型无法预览
......@@ -174,26 +174,20 @@ namespace OnlineStore.AssemblyLine
private void FrmStoreIOStatus_Load(object sender, EventArgs e)
{
chbDebug.Checked = feedEquip.IsDebug;
if (feedEquip.UpdownUseAxis)
{
portName = feedEquip.Config.Batch_Axis.DeviceName;
SlvAddr = feedEquip.Config.Batch_Axis.GetAxisValue();
txtAxisDeviceName.Text = portName;
txtSlaveId.Text = SlvAddr.ToString();
comboBox1.Items.Clear();
comboBox1.Items.Add(feedEquip.Config.Batch_Axis.Explain);
comboBox1.SelectedIndex = 0;
txtAxisValue.Text = SlvAddr.ToString();
}
else
{
tabControl1.TabPages.Remove(tabPage2);
}
portName = feedEquip.Config.Batch_Axis.DeviceName;
SlvAddr = feedEquip.Config.Batch_Axis.GetAxisValue();
txtAxisDeviceName.Text = portName;
txtSlaveId.Text = SlvAddr.ToString();
comboBox1.Items.Clear();
comboBox1.Items.Add(feedEquip.Config.Batch_Axis.Explain);
comboBox1.SelectedIndex = 0;
txtAxisValue.Text = SlvAddr.ToString();
cmbSizeList.Items.Clear();
cmbSizeList.Items.Add("0=默认位置");
for(int i = 8; i <= 48; i = i + 4)
for (int i = 8; i <= 48; i = i + 4)
{
cmbSizeList.Items.Add(i.ToString());
}
......@@ -593,7 +587,7 @@ namespace OnlineStore.AssemblyLine
private void btnAxisOn_Click(object sender, EventArgs e)
{
this.Enabled = false;
feedEquip.RunAxis(false);
feedEquip.RunAxis(false,feedEquip.Config.Batch_Axis);
this.Enabled = true;
LogUtil.info("伺服运转ON完成");
}
......
......@@ -186,7 +186,7 @@ namespace OnlineStore.AssemblyLine
private void FrmStoreIOStatus_Load(object sender, EventArgs e)
{
chbDebug.Checked = moveEquip.IsDebug;
if (moveEquip.UpdownUseAxis)
if (moveEquip.UseAxis)
{
portName = moveEquip.Config.UpDown_Axis.DeviceName;
SlvAddr = moveEquip.Config.UpDown_Axis.GetAxisValue();
......@@ -605,7 +605,7 @@ namespace OnlineStore.AssemblyLine
private void btnAxisOn_Click(object sender, EventArgs e)
{
this.Enabled = false;
moveEquip.RunAxis(false);
moveEquip.RunAxis(false,moveEquip.Config.UpDown_Axis);
this.Enabled = true;
LogUtil.info("伺服运转ON完成");
}
......
......@@ -25,11 +25,11 @@ namespace OnlineStore.AssemblyLine
private bool IsLoad = false;
private string portName = "";
private short SlvAddr = 0;
private ProvidingEquip moveEquip;
private ProvidingEquip providingEquip;
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public FrmProvidingEquip(ProvidingEquip moveEquip)
{
this.moveEquip = moveEquip;
this.providingEquip = moveEquip;
Control.CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
LoadIOList();
......@@ -40,8 +40,8 @@ namespace OnlineStore.AssemblyLine
{
int roleindex = 0;
this.tableLayoutPanel1.RowStyles.Clear();
this.tableLayoutPanel1.RowCount = moveEquip.Config.DIList.Count;
foreach (ConfigIO ioValue in moveEquip.Config.DIList.Values)
this.tableLayoutPanel1.RowCount = providingEquip.Config.DIList.Count;
foreach (ConfigIO ioValue in providingEquip.Config.DIList.Values)
{
this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 28));
IOTextControl control = new IOTextControl(ioValue.ElectricalDefinition + "_" + ioValue.Explain, ioValue.ProName);
......@@ -51,9 +51,9 @@ namespace OnlineStore.AssemblyLine
}
tableLayoutPanel2.RowStyles.Clear();
this.tableLayoutPanel2.RowCount = moveEquip.Config.DOList.Count;
this.tableLayoutPanel2.RowCount = providingEquip.Config.DOList.Count;
roleindex = 0;
foreach (ConfigIO ioValue in moveEquip.Config.DOList.Values)
foreach (ConfigIO ioValue in providingEquip.Config.DOList.Values)
{
this.tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Absolute, 28));
IOTextControl control = new IOTextControl(ioValue.ElectricalDefinition + "_" + ioValue.Explain, ioValue.ProName);
......@@ -63,7 +63,7 @@ namespace OnlineStore.AssemblyLine
}
this.SuspendLayout(); //此处为不闪屏,一定要有的!
cmbWriteIO.DataSource = new List<ConfigIO>(moveEquip.Config.DOList.Values);
cmbWriteIO.DataSource = new List<ConfigIO>(providingEquip.Config.DOList.Values);
cmbWriteIO.ValueMember = "ProName";
cmbWriteIO.DisplayMember = "DisplayStr";
......@@ -80,14 +80,14 @@ namespace OnlineStore.AssemblyLine
if (chbAutoRead.Checked && this.Visible)
{
ReadIOList();
lblTrayNum.Text = "托盘编码:" + TrayManager.GetNum(moveEquip.DeviceID);
lblTrayNum.Text = "托盘编码:" + TrayManager.GetNum(providingEquip.DeviceID);
}
string canOut = LineManager.Line.CanOutStore(moveEquip.DeviceID) ? "可出库":"不可出库" ;
lblStoreStatus.Text = KTK_Store.GetRunStr(moveEquip.lineStatus, moveEquip.runStatus)+"("+canOut+")";
lblThisSta.Text = moveEquip.WarnMsg;
string canOut = LineManager.Line.CanOutStore(providingEquip.DeviceID) ? "可出库":"不可出库" ;
lblStoreStatus.Text = KTK_Store.GetRunStr(providingEquip.lineStatus, providingEquip.runStatus)+"("+canOut+")";
lblThisSta.Text = providingEquip.WarnMsg;
string text = "";
List<InOutParam> ps = new List<InOutParam>(moveEquip.waitInStoreList);
List<InOutParam> ps = new List<InOutParam>(providingEquip.waitInStoreList);
if (ps.Count > 0)
{
text = "等待入库列表:\r";
......@@ -102,7 +102,7 @@ namespace OnlineStore.AssemblyLine
}
}catch(Exception ex)
{
LogUtil.error(moveEquip.Name+ "界面定时器出错:"+ex.ToString());
LogUtil.error(providingEquip.Name+ "界面定时器出错:"+ex.ToString());
}
}
......@@ -143,9 +143,9 @@ namespace OnlineStore.AssemblyLine
private ConfigIO GetSelectDO()
{
string text = cmbWriteIO.SelectedValue.ToString();
if (moveEquip.Config.DOList.ContainsKey(text))
if (providingEquip.Config.DOList.ContainsKey(text))
{
ConfigIO io = moveEquip.Config.DOList[text];
ConfigIO io = providingEquip.Config.DOList[text];
return io;
}
return null;
......@@ -173,15 +173,15 @@ namespace OnlineStore.AssemblyLine
private void FrmStoreIOStatus_Load(object sender, EventArgs e)
{
chbDebug.Checked = moveEquip.IsDebug;
if (moveEquip.UpdownUseAxis)
chbDebug.Checked = providingEquip.IsDebug;
if (providingEquip.UseAxis)
{
portName = moveEquip.Config.UpDown_Axis.DeviceName;
SlvAddr = moveEquip.Config.UpDown_Axis.GetAxisValue();
portName = providingEquip.Config.UpDown_Axis.DeviceName;
SlvAddr = providingEquip.Config.UpDown_Axis.GetAxisValue();
txtAxisDeviceName.Text = portName;
txtSlaveId.Text = SlvAddr.ToString();
comboBox1.Items.Clear();
comboBox1.Items.Add(moveEquip.Config.UpDown_Axis.Explain);
comboBox1.Items.Add(providingEquip.Config.UpDown_Axis.Explain);
comboBox1.SelectedIndex = 0;
txtAxisValue.Text = SlvAddr.ToString();
......@@ -198,9 +198,9 @@ namespace OnlineStore.AssemblyLine
cmbSizeList.Items.Add(i.ToString());
}
cmbSizeList.SelectedIndex = 0;
lblStoreStatus.Text = KTK_Store.GetRunStr(moveEquip.lineStatus, moveEquip.runStatus);
lblThisSta.Text = moveEquip.WarnMsg;
txtP1.Text = moveEquip.Config.UpDownAxisP1.ToString();
lblStoreStatus.Text = KTK_Store.GetRunStr(providingEquip.lineStatus, providingEquip.runStatus);
lblThisSta.Text = providingEquip.WarnMsg;
txtP1.Text = providingEquip.Config.UpDownAxisP1.ToString();
IsLoad = true;
}
......@@ -231,7 +231,7 @@ namespace OnlineStore.AssemblyLine
foreach (string key in DIControlList.Keys)
{
IOTextControl control = DIControlList[key];
int iov = (int)IOManager.IOValue(key, moveEquip.DeviceID);
int iov = (int)IOManager.IOValue(key, providingEquip.DeviceID);
if (iov != control.IOValue)
{
control.IOValue = iov;
......@@ -241,7 +241,7 @@ namespace OnlineStore.AssemblyLine
foreach (string key in this.DOControlList.Keys)
{
IOTextControl control = DOControlList[key];
int iov = (int)IOManager.DOValue(key, moveEquip.DeviceID);
int iov = (int)IOManager.DOValue(key, providingEquip.DeviceID);
if (iov != control.IOValue)
{
control.IOValue = iov;
......@@ -287,9 +287,9 @@ namespace OnlineStore.AssemblyLine
private void btnStart_Click(object sender, EventArgs e)
{
if (moveEquip.runStatus.Equals(LineRunStatus.Wait))
if (providingEquip.runStatus.Equals(LineRunStatus.Wait))
{
bool result = moveEquip.StartDebugRun();
bool result = providingEquip.StartDebugRun();
if (result)
{
FormStatus(true);
......@@ -306,31 +306,31 @@ namespace OnlineStore.AssemblyLine
if (chbDebug.Checked)
{
if (!moveEquip.IsDebug)
if (!providingEquip.IsDebug)
{
DialogResult result = MessageBox.Show("是否切换到调试状态?", "是否确认切换", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result.Equals(DialogResult.Yes))
{
moveEquip.IsDebug = true;
moveEquip.Config.IsDebug = 1;
LineManager.SaveProvidingEquipConfig(moveEquip.Config);
moveEquip.ChangeDebug();
LogUtil.info(moveEquip.Name+ "用户切换到调试状态 ");
providingEquip.IsDebug = true;
providingEquip.Config.IsDebug = 1;
LineManager.SaveProvidingEquipConfig(providingEquip.Config);
providingEquip.ChangeDebug();
LogUtil.info(providingEquip.Name+ "用户切换到调试状态 ");
}
}
}
else
{
if (moveEquip.IsDebug)
if (providingEquip.IsDebug)
{
DialogResult result = MessageBox.Show("是否切换到正常工作状态?", "是否确认切换", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result.Equals(DialogResult.Yes))
{
moveEquip.IsDebug = false;
moveEquip.Config.IsDebug = 0;
LineManager.SaveProvidingEquipConfig(moveEquip.Config);
moveEquip.ChangeDebug();
LogUtil.info(moveEquip.Name + "用户切换到正常工作状态 ");
providingEquip.IsDebug = false;
providingEquip.Config.IsDebug = 0;
LineManager.SaveProvidingEquipConfig(providingEquip.Config);
providingEquip.ChangeDebug();
LogUtil.info(providingEquip.Name + "用户切换到正常工作状态 ");
}
}
}
......@@ -338,9 +338,9 @@ namespace OnlineStore.AssemblyLine
private void btnOutStore_Click(object sender, EventArgs e)
{
if (moveEquip.runStatus .Equals(LineRunStatus.Runing))
if (providingEquip.runStatus .Equals(LineRunStatus.Runing))
{
moveEquip.StartOutStoreMove(new InOutParam( ));
providingEquip.StartOutStoreMove(new InOutParam( ));
}
else
{
......@@ -350,9 +350,9 @@ namespace OnlineStore.AssemblyLine
private void btnInStore_Click(object sender, EventArgs e)
{
if (moveEquip.runStatus.Equals(LineRunStatus.Runing))
if (providingEquip.runStatus.Equals(LineRunStatus.Runing))
{
moveEquip.StartInStoreMove(new InOutParam());
providingEquip.StartInStoreMove(new InOutParam());
}
else
{
......@@ -364,7 +364,7 @@ namespace OnlineStore.AssemblyLine
{
try
{
moveEquip.StopMove();
providingEquip.StopMove();
}
catch (Exception ex)
{
......@@ -374,22 +374,22 @@ namespace OnlineStore.AssemblyLine
private void btnReset_Click(object sender, EventArgs e)
{
if (moveEquip.runStatus>(LineRunStatus.Wait))
if (providingEquip.runStatus>(LineRunStatus.Wait))
{
moveEquip.Reset();
providingEquip.Reset();
}
}
private void btnStop1Up_Click(object sender, EventArgs e)
{
if (btnStop1Up.Text.Equals("阻挡气缸1下降"))
{
moveEquip.IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
providingEquip.IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
btnStop1Up.Text = "阻挡气缸1上升";
btnStop1Up.BackColor = Color.Aqua;
}
else
{
moveEquip.IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
providingEquip.IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
btnStop1Up.Text = "阻挡气缸1下降";
btnStop1Up.BackColor = Color.White;
}
......@@ -398,13 +398,13 @@ namespace OnlineStore.AssemblyLine
{
if (btnStop2Up.Text.Equals("阻挡气缸2下降"))
{
moveEquip.IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
providingEquip.IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
btnStop2Up.Text = "阻挡气缸2上升";
btnStop2Up.BackColor = Color.Aqua;
}
else
{
moveEquip.IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
providingEquip.IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
btnStop2Up.Text = "阻挡气缸2下降";
btnStop2Up.BackColor = Color.White;
}
......@@ -413,13 +413,13 @@ namespace OnlineStore.AssemblyLine
{
if (btnTopUp.Text.Equals("顶升气缸上升"))
{
moveEquip.CylinderMove(null, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP);
providingEquip.CylinderMove(null, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP);
btnTopUp.Text = "顶升气缸下降";
btnTopUp.BackColor = Color.Aqua;
}
else
{
moveEquip.CylinderMove(null, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
providingEquip.CylinderMove(null, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
btnTopUp.Text = "顶升气缸上升";
btnTopUp.BackColor = Color.SkyBlue;
}
......@@ -429,13 +429,13 @@ namespace OnlineStore.AssemblyLine
{
if (btnBeforeAfterBefore.Text.Equals("前后气缸前进"))
{
moveEquip.CylinderMove(null, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
providingEquip.CylinderMove(null, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
btnBeforeAfterBefore.Text = "前后气缸后退";
btnBeforeAfterBefore.BackColor = Color.Aqua;
}
else
{
moveEquip.CylinderMove(null, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
providingEquip.CylinderMove(null, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
btnBeforeAfterBefore.Text = "前后气缸前进";
btnBeforeAfterBefore.BackColor = Color.SkyBlue;
}
......@@ -444,13 +444,13 @@ namespace OnlineStore.AssemblyLine
{
if (btnUpDownUp.Text.Equals("上下气缸上升"))
{
moveEquip.CylinderMove(null, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
providingEquip.CylinderMove(null, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
btnUpDownUp.Text = "上下气缸下降";
btnUpDownUp.BackColor = Color.Aqua;
}
else
{
moveEquip.CylinderMove(null, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
providingEquip.CylinderMove(null, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
btnUpDownUp.Text = "上下气缸上升";
btnUpDownUp.BackColor = Color.SkyBlue;
}
......@@ -459,13 +459,13 @@ namespace OnlineStore.AssemblyLine
{
if (btnClampSlack.Text.Equals("夹料气缸夹紧"))
{
moveEquip.CylinderMove(null, IO_Type.ClampCylinder_Tighten, IO_Type.ClampCylinder_Slack);
providingEquip.CylinderMove(null, IO_Type.ClampCylinder_Tighten, IO_Type.ClampCylinder_Slack);
btnClampSlack.Text = "夹料气缸放松";
btnClampSlack.BackColor = Color.Aqua;
}
else
{
moveEquip.CylinderMove(null, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
providingEquip.CylinderMove(null, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
btnClampSlack.Text = "夹料气缸夹紧";
btnClampSlack.BackColor = Color.SkyBlue;
}
......@@ -572,8 +572,8 @@ namespace OnlineStore.AssemblyLine
int size = 0;
try {size= Convert.ToInt32(cmbSizeList.Text); } catch (Exception ex) { }
txtSizePosition.Text = moveEquip.Config.GetUpdownPosition(size).ToString();
txtBoxP.Text = moveEquip.Config.GetUpdownBoxPosition(size).ToString();
txtSizePosition.Text = providingEquip.Config.GetUpdownPosition(size).ToString();
txtBoxP.Text = providingEquip.Config.GetUpdownBoxPosition(size).ToString();
btnMoveto.Text = size + "寸移栽位置 :";
btnBoxP.Text= size + "寸料仓门口位置 :";
// btnMoveto.Text = "尺寸" + size + "对应位置:";
......@@ -584,7 +584,7 @@ namespace OnlineStore.AssemblyLine
int position = FormUtil.GetIntValue(txtSizePosition);
if (position != -1)
{
int speed = moveEquip.Config.UpdownAxis_DownSpeed;
int speed = providingEquip.Config.UpdownAxis_DownSpeed;
LogUtil.info("点击【移栽位置】,料盘高度【" + cmbSizeList.Text + "】 位置【" + position + "】速度【" + speed + "】");
ACServerManager.AbsMove(portName, SlvAddr, position, speed);
}
......@@ -593,14 +593,14 @@ namespace OnlineStore.AssemblyLine
private void btnAxisOn_Click(object sender, EventArgs e)
{
this.Enabled = false;
moveEquip.RunAxis(false);
providingEquip.RunAxis(false,providingEquip.Config.UpDown_Axis);
this.Enabled = true;
LogUtil.info("伺服运转ON完成");
}
private void btnAxisOff_Click(object sender, EventArgs e)
{
moveEquip.CloseAxis();
providingEquip.CloseAxis();
LogUtil.info("伺服运转OFF完成");
}
......@@ -614,7 +614,7 @@ namespace OnlineStore.AssemblyLine
int position = FormUtil.GetIntValue(txtP1);
if (position != -1)
{
int speed =moveEquip.Config.UpdownAxis_P1Speed;
int speed =providingEquip.Config.UpdownAxis_P1Speed;
LogUtil.info("点击【P1点测试】, 位置【" + position + "】速度【" + speed + "】");
ACServerManager.AbsMove(portName, SlvAddr, position, speed);
}
......@@ -623,15 +623,15 @@ namespace OnlineStore.AssemblyLine
private void btnSave_Click(object sender, EventArgs e)
{
int p1Position = FormUtil.GetIntValue(txtP1);
moveEquip.Config.UpDownAxisP1 = p1Position;
providingEquip.Config.UpDownAxisP1 = p1Position;
int size = 0;
try { size = Convert.ToInt32(cmbSizeList.Text); } catch (Exception ex) { }
int sizePosition = FormUtil.GetIntValue(txtSizePosition);
int sizeBoxP = FormUtil.GetIntValue(txtBoxP);
moveEquip.Config.UpdateUpdownPositon(size, sizePosition);
moveEquip.Config.UpdateUpdownBoxPositon(size, sizeBoxP);
LineManager.SaveProvidingEquipConfig(moveEquip.Config);
providingEquip.Config.UpdateUpdownPositon(size, sizePosition);
providingEquip.Config.UpdateUpdownBoxPositon(size, sizeBoxP);
LineManager.SaveProvidingEquipConfig(providingEquip.Config);
MessageBox.Show("保存成功!");
}
......@@ -640,7 +640,7 @@ namespace OnlineStore.AssemblyLine
int position = FormUtil.GetIntValue(txtBoxP);
if (position != -1)
{
int speed = moveEquip.Config.UpdownAxis_DownSpeed;
int speed = providingEquip.Config.UpdownAxis_DownSpeed;
LogUtil.info("点击【料仓门口下降位置】,料盘高度【" + cmbSizeList.Text + "】 位置【" + position + "】速度【" + speed + "】");
ACServerManager.AbsMove(portName, SlvAddr, position, speed);
}
......
......@@ -7,6 +7,7 @@ using System.Net;
using System.Net.Sockets;
using log4net;
using System.Reflection;
using System.Threading;
namespace OnlineStore.Common
{
......@@ -15,10 +16,11 @@ namespace OnlineStore.Common
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public delegate void HandleMessage(string message);
private Socket m_clientSocket;
private Socket m_clientSocket = null;
private byte[] m_receiveBuffer = new byte[1024];
private HandleMessage onReceived;
public int TimeOutTime = 0;
/// <summary>
/// 当前连接状态
......@@ -41,68 +43,109 @@ namespace OnlineStore.Common
* Depending on http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.connected.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
********************************************************************************************/
#endregion
#region 过程
// This is how you can determine whether a socket is still connected.
bool connectState = true;
bool blockingState = m_clientSocket.Blocking;
try
{
byte[] tmp = new byte[1];
#region 过程
// This is how you can determine whether a socket is still connected.
bool connectState = true;
bool blockingState = m_clientSocket.Blocking;
try
{
byte[] tmp = new byte[1];
m_clientSocket.Blocking = false;
m_clientSocket.Send(tmp, 0, 0);
//Console.WriteLine("Connected!");
connectState = true; //若Send错误会跳去执行catch体,而不会执行其try体里其之后的代码
}
catch (SocketException e)
{
// 10035 == WSAEWOULDBLOCK
if (e.NativeErrorCode.Equals(10035))
m_clientSocket.Blocking = false;
m_clientSocket.Send(tmp, 0, 0);
//Console.WriteLine("Connected!");
connectState = true; //若Send错误会跳去执行catch体,而不会执行其try体里其之后的代码
}
catch (SocketException e)
{
connectState = true;
// 10035 == WSAEWOULDBLOCK
if (e.NativeErrorCode.Equals(10035))
{
connectState = true;
}
else
{
connectState = false;
}
}
else
finally
{
connectState = false;
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Blocking = blockingState;
}
}
//Console.WriteLine("Connected: {0}", client.Connected);
return connectState;
#endregion
}
finally
catch (Exception ex)
{
m_clientSocket.Blocking = blockingState;
LogUtil.error(LOGGER, "出错啦" + ex.ToString());
return false;
}
//Console.WriteLine("Connected: {0}", client.Connected);
return connectState;
#endregion
}
/// <summary>
/// 连接服务器
/// </summary>
public bool connect(string serverIP, int serverPort, HandleMessage HandleMessage)
{
m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
try
m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
if (TimeOutTime <= 0)
{
m_clientSocket.Connect(remoteEndPoint);
if (m_clientSocket.Connected)
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
m_clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
try
{
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage;
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
if (!m_clientSocket.Connected)
{
m_clientSocket.Connect(remoteEndPoint);
}
if (m_clientSocket.Connected)
{
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage;
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
else
{
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " fail!");
}
}
else
catch (Exception ex)
{
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " fail!");
LogUtil.error( "Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(), 3);
//m_clientSocket = null;
}
}
catch (Exception ex)
else
{
LogUtil.error("Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(),1003);
m_clientSocket = null;
m_clientSocket.ReceiveTimeout = TimeOutTime;
m_clientSocket.SendTimeout = TimeOutTime;
IAsyncResult connResult = m_clientSocket.BeginConnect(serverIP, serverPort, null, null);
connResult.AsyncWaitHandle.WaitOne(this.TimeOutTime, true); //等待2秒
if (!connResult.IsCompleted || (!m_clientSocket.Connected))
{
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " fail!");
m_clientSocket.Close();
//处理连接不成功的动作
return false;
}
else
{
//处理连接成功的动作
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage;
LogUtil.info(LOGGER, "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
}
return false;
}
......@@ -112,14 +155,27 @@ namespace OnlineStore.Common
/// </summary>
public void close()
{
if (m_clientSocket != null)
try
{
m_clientSocket.Close();
LogUtil.info(LOGGER,"Socket closed!");
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Shutdown(SocketShutdown.Both);
//Thread.Sleep(300);
//m_clientSocket.Disconnect(true);
//Thread.Sleep(300);
m_clientSocket.Close();
//m_clientSocket = null;
LogUtil.info(LOGGER, "Socket closed!");
}
else
{
LogUtil.error(LOGGER, "No socket is running!");
}
}
else
catch (Exception ex)
{
LogUtil.error(LOGGER,"No socket is running!");
LogUtil.error(LOGGER, "close error :" + ex.ToString());
}
}
......@@ -133,12 +189,34 @@ namespace OnlineStore.Common
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug(LOGGER,"Send >> " + strSendData);
LogUtil.debug(LOGGER, "Send >> " + strSendData);
}
}
/// <summary>
/// 发送信息
/// </summary>
public void sendLine(string strSendData)
{
if (strSendData.StartsWith("save"))
{
LogUtil.debug(LOGGER, "发送数据:" + strSendData);
}
else
{
LogUtil.info(LOGGER, "发送数据:" + strSendData);
}
strSendData = strSendData + "\r\n";
byte[] sendBuffer = new byte[1024];
sendBuffer = Encoding.UTF8.GetBytes(strSendData);
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug(LOGGER, "Send >> " + strSendData);
}
}
private void ReceiveCallBack(IAsyncResult ar)
{
try
......@@ -146,14 +224,16 @@ namespace OnlineStore.Common
if (m_clientSocket != null && m_clientSocket.Connected)
{
int REnd = m_clientSocket.EndReceive(ar);
string strReceiveData = Encoding.UTF8.GetString(m_receiveBuffer, 0, REnd);
string strReceiveData = Encoding.Default.GetString(m_receiveBuffer, 0, REnd);
onReceived(strReceiveData);
Thread.Sleep(100);
//LOGGER.Debug("m_clientSocket:" + m_clientSocket + "\n m_receiveBuffer" + m_receiveBuffer);
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
}
}
catch (Exception ex)
{
LogUtil.error("socket received error:" + ex.ToString(),1004);
LogUtil.error( "socket received error:" + ex.ToString(), 4);
}
}
}
......
......@@ -78,6 +78,7 @@
<Compile Include="deviceLibrary\PanasonicServo\ACCMDManager.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="model\EquipBase.cs" />
<Compile Include="model\LineAlarm.cs">
<SubType>Code</SubType>
</Compile>
......
......@@ -13,13 +13,5 @@ PRO,0,批量上料轴原点低速度,BatchAxis_HomeLowSpeed,100,,,,,
PRO,0,批量上料轴原点高速,BatchAxis_HomeHighSpeed,200,,,,,
PRO,0,批量上料轴原点加速度,BatchAxis_HomeAddSpeed,200,,,,,
,,,,,,,,,
AXIS,0,移栽上下轴,UpDown_Axis,2,COM1,0,,,
PRO,0,移栽上下轴待机点 P1,UpDownAxisP1,2000,,,,,
PRO,0,移栽上下轴目标速度,UpdownAxis_TargetSpeed,150,,,,,
PRO,0,移栽上下轴加速度,UpdownAxis_AddSpeed,400,,,,,
PRO,0,移栽上下轴减速度,UpdownAxis_DelSpeed,400,,,,,
PRO,0,移栽上下轴原点低速度,UpdownAxis_HomeLowSpeed,100,,,,,
PRO,0,移栽上下轴原点高速,UpdownAxis_HomeHighSpeed,200,,,,,
PRO,0,移栽上下轴原点加速度,UpdownAxis_HomeAddSpeed,200,,,,,
,,,,,,,,,
PRO,0,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,,
类型,分类编号,说明,名称,属性值,设备名称,默认值,描述,电器定义,代码定义
PRO,0,设备是否处于调试状态(1=调试,0=正常),IsDebug,1,,,,,
PRO,0,阻挡气缸控制信号(1-4分别对应夹具检测1-4),StopCylinderIOType,1,,,,,
,,,,,,,,,
PRO,0,移栽上下运动是否使用伺服,UpDownUseAxis,0,,,,,
PRO,0,移栽上下移动料盘高度对应的上升位置,UpDownPositions,12=1000;16=1300;20=2000;24=2000;36=3000;,,,,,,
AXIS,0,移栽上下轴,UpDown_Axis,2,COM1,0,,,
PRO,0,移栽上下轴待机点 P1,UpDownAxisP1,2000,,,,,
PRO,0,移栽上下轴目标速度,UpdownAxis_TargetSpeed,150,,,,,
PRO,0,移栽上下轴加速度,UpdownAxis_AddSpeed,400,,,,,
PRO,0,移栽上下轴减速度,UpdownAxis_DelSpeed,400,,,,,
PRO,0,移栽上下轴原点低速度,UpdownAxis_HomeLowSpeed,100,,,,,
PRO,0,移栽上下轴原点高速,UpdownAxis_HomeHighSpeed,200,,,,,
PRO,0,移栽上下轴原点加速度,UpdownAxis_HomeAddSpeed,200,,,,,
PRO,0,移栽上下移动料盘高度对应的上升位置,UpDownPositions,12=1000;16=1300;20=2000;24=2000;36=3000;,,,,,
,,,,,,,,,
AXIS,0,批量上料轴,Batch_Axis,2,COM1,0,,,
PRO,0,批量上料轴待机点 P1,BatchAxisP1,2000,,,,,
PRO,0,批量上料轴目标速度,BatchAxis_TargetSpeed,150,,,,,
PRO,0,批量上料轴加速度,BatchAxis_AddSpeed,400,,,,,
PRO,0,批量上料轴减速度,BatchAxis_DelSpeed,400,,,,,
PRO,0,批量上料轴原点低速度,BatchAxis_HomeLowSpeed,100,,,,,
PRO,0,批量上料轴原点高速,BatchAxis_HomeHighSpeed,200,,,,,
PRO,0,批量上料轴原点加速度,BatchAxis_HomeAddSpeed,200,,,,,
,,,,,,,,,
,,,,,,,,,
PRO,0,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,,
类型,分类编号,说明,名称,属性值,设备名称,默认值,描述,电器定义,代码定义
PRO,0,设备是否处于调试状态(1=调试,0=正常),IsDebug,1,,,,,
PRO,0,阻挡气缸控制信号(1-4分别对应夹具检测1-4),StopCylinderIOType,1,,,,,
,,,,,,,,,
PRO,0,移栽上下运动是否使用伺服,UpDownUseAxis,0,,,,,
PRO,0,移栽上下移动料盘高度对应的上升位置,UpDownPositions,12=1000;16=1300;20=2000;24=2000;36=3000;,,,,,,
AXIS,0,移栽上下轴,UpDown_Axis,2,COM1,0,,,
PRO,0,移栽上下轴待机点 P1,UpDownAxisP1,2000,,,,,
PRO,0,移栽上下轴目标速度,UpdownAxis_TargetSpeed,150,,,,,
PRO,0,移栽上下轴加速度,UpdownAxis_AddSpeed,400,,,,,
PRO,0,移栽上下轴减速度,UpdownAxis_DelSpeed,400,,,,,
PRO,0,移栽上下轴原点低速度,UpdownAxis_HomeLowSpeed,100,,,,,
PRO,0,移栽上下轴原点高速,UpdownAxis_HomeHighSpeed,200,,,,,
PRO,0,移栽上下轴原点加速度,UpdownAxis_HomeAddSpeed,200,,,,,
PRO,0,移栽上下移动料盘高度对应的上升位置,UpDownPositions,12=1000;16=1300;20=2000;24=2000;36=3000;,,,,,
,,,,,,,,,
AXIS,0,批量上料轴,Batch_Axis,2,COM1,0,,,
PRO,0,批量上料轴待机点 P1,BatchAxisP1,2000,,,,,
PRO,0,批量上料轴目标速度,BatchAxis_TargetSpeed,150,,,,,
PRO,0,批量上料轴加速度,BatchAxis_AddSpeed,400,,,,,
PRO,0,批量上料轴减速度,BatchAxis_DelSpeed,400,,,,,
PRO,0,批量上料轴原点低速度,BatchAxis_HomeLowSpeed,100,,,,,
PRO,0,批量上料轴原点高速,BatchAxis_HomeHighSpeed,200,,,,,
PRO,0,批量上料轴原点加速度,BatchAxis_HomeAddSpeed,200,,,,,
,,,,,,,,,
,,,,,,,,,
PRO,0,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,,
类型,分类编号,说明,名称,属性值,设备名称,默认值,描述,电器定义,代码定义
PRO,0,设备是否处于调试状态(1=调试,0=正常),IsDebug,1,,,,,
PRO,0,阻挡气缸控制信号(1-4分别对应夹具检测1-4),StopCylinderIOType,1,,,,,
PRO,0,移栽上下运动是否使用伺服,UpDownUseAxis,1,,,,,
PRO,0,移栽上下轴在移栽上下降的位置,UpDownPositions,0=180000;,,,,,,
PRO,0,移栽上下轴在料仓门口下降的位置,UpDownBoxPositions,0=116000;,,,,,,
AXIS,0,移栽上下轴,UpDown_Axis,1,COM1,1,,,
PRO,0,移栽上下轴待机点 P1,UpDownAxisP1,20000,,,,,
PRO,0,移栽上下轴目标速度,UpdownAxis_TargetSpeed,150,,,,,
PRO,0,移栽上下轴加速度,UpdownAxis_AddSpeed,400,,,,,
PRO,0,移栽上下轴减速度,UpdownAxis_DelSpeed,400,,,,,
PRO,0,移栽上下轴原点低速度,UpdownAxis_HomeLowSpeed,100,,,,,
PRO,0,移栽上下轴原点高速,UpdownAxis_HomeHighSpeed,200,,,,,
PRO,0,移栽上下轴原点加速度,UpdownAxis_HomeAddSpeed,200,,,,,
PRO,0,移栽上下轴下降速度,UpdownAxis_DownSpeed,500,,,,,
PRO,0,移栽上下轴走到待机点速度,UpdownAxis_P1Speed,400,,,,,
,,,,,,,,,
PRO,0,移栽上下运动是否使用伺服,UpDownUseAxis,0,,,,,
PRO,0,移栽上下移动料盘高度对应的上升位置,UpDownPositions,12=1000;16=1300;20=2000;24=2000;36=3000;,,,,,
,,,,,,,,,
AXIS,0,批量上料轴,Batch_Axis,2,COM1,0,,,
PRO,0,批量上料轴待机点 P1,BatchAxisP1,2000,,,,,
PRO,0,批量上料轴目标速度,BatchAxis_TargetSpeed,150,,,,,
PRO,0,批量上料轴加速度,BatchAxis_AddSpeed,400,,,,,
PRO,0,批量上料轴减速度,BatchAxis_DelSpeed,400,,,,,
PRO,0,批量上料轴原点低速度,BatchAxis_HomeLowSpeed,100,,,,,
PRO,0,批量上料轴原点高速,BatchAxis_HomeHighSpeed,200,,,,,
PRO,0,批量上料轴原点加速度,BatchAxis_HomeAddSpeed,200,,,,,
,,,,,,,,,
,,,,,,,,,
PRO,0,扫码的相机名称(多个用#分隔),CameraNameList,Name1#Name1,,,,,
......@@ -13,12 +13,9 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 流水线自动料仓-入料装置类
/// </summary>
public partial class FeedingEquip : KTK_Store
public partial class FeedingEquip : EquipBase
{
private bool IsIntSlvBlock = false;
public bool IsDebug = false;
public bool UpdownUseAxis = false;
public AxisAlarmInfo AxisAlarm = new AxisAlarmInfo();
public FeedingEquip_Config Config;
......@@ -44,8 +41,8 @@ namespace OnlineStore.DeviceLibrary
MoveInfo = new LineMoveInfo(DeviceID,"入料-"+DeviceID+"-MoveInfo");
IsDebug = config.IsDebug.Equals(1);
UpdownUseAxis = config.UpDownUseAxis.Equals(1);
if (UpdownUseAxis)
UseAxis = config.UpDownUseAxis.Equals(1);
if (UseAxis)
{
Config.Batch_Axis.TargetSpeed = Config.BatchAxis_TargetSpeed;
Config.Batch_Axis.AddSpeed = Config.BatchAxis_AddSpeed;
......@@ -69,17 +66,17 @@ namespace OnlineStore.DeviceLibrary
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
return MoveEquipMentHome();
return ReturnHome();
}
public bool StartDebugRun()
{
public bool StartDebugRun()
{
mainTimer.Enabled = false;
MoveInfo.EndMove();
MoveInfo.EndMove();
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
bool result= MoveEquipMentHome();
bool result = ReturnHome();
if (result)
{
mainTimer.Enabled = true;
......@@ -231,10 +228,10 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 入料装置原点返回
/// </summary>
public bool MoveEquipMentHome()
public bool ReturnHome()
{
mainTimer.Stop();
if (!RunAxis(true))
if (!RunAxis(true,Config.Batch_Axis))
{
return false;
}
......@@ -273,7 +270,7 @@ namespace OnlineStore.DeviceLibrary
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
if (!RunAxis(true))
if (!RunAxis(true,Config.Batch_Axis))
{
return false;
}
......@@ -421,7 +418,7 @@ namespace OnlineStore.DeviceLibrary
LogInfo("停止运行完成,停止伺服!");
CloseAxis();
if (UpdownUseAxis)
if (UseAxis)
{
LogInfo("停止运动:停止伺服");
ACServerManager.SuddenStop(Config.Batch_Axis);
......@@ -491,7 +488,7 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
//上下气缸上升
if (UpdownUseAxis.Equals(false))
if (UseAxis.Equals(false))
{
IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.HIGH);
......@@ -513,188 +510,14 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.TopCylinder_Down, IO_VALUE.LOW);
}
#region 上下气缸伺服运动
private string portName;
private short slvAddr;
public bool RunAxis(bool isCheck)
{
if (!UpdownUseAxis)
{
return true;
}
IOMove(IO_Type.BatchAxis_ServoOn, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
ACServerManager.OpenPort(portName);
Thread.Sleep(50);
//初始化
if (!IsIntSlvBlock)
{
ACServerManager.InitSlvAddr(portName, slvAddr, Config.Batch_Axis.TargetSpeed, Config.Batch_Axis.AddSpeed, Config.Batch_Axis.DelSpeed);
Thread.Sleep(100);
}
ACServerManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
ACServerManager.ServoOn(portName, slvAddr);
Thread.Sleep(1000);
//打开所有轴
if (isCheck)
{
if (!OpenAxis())
{
return false;
}
}
IsIntSlvBlock = true;
IOMove(IO_Type.BatchAxis_BreakOn, IO_VALUE.HIGH);
return true;
}
private void IOMove(object batchAxis_ServoOn, IO_VALUE hIGH)
{
throw new NotImplementedException();
}
/// <summary>
/// 打开所有轴
/// </summary>
/// <returns></returns>
private bool OpenAxis()
{
//判断轴是否正常
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info( Name + "成功打开轴:" + Config.Batch_Axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogUtil.info( Name + "第一次打开轴" + Config.Batch_Axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(portName, slvAddr);
System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(portName, slvAddr);
System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info( Name + "清理报警后重新打卡轴成功:" + Config.Batch_Axis.Explain);
}
else
{
ACServerManager.ServoOff(portName, slvAddr);
WarnMsg = Name + "打开轴" + Config.Batch_Axis.Explain + "失败 ";
LogUtil.info( Name + WarnMsg);
Alarm(LineAlarmType.AxisAlarm, 5.ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
return true;
}
public void CloseAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(IO_Type.BatchAxis_BreakOn, IO_VALUE.LOW);
ACServerManager.ServoOff(portName, slvAddr);
//关闭串口,等下次重新打开
ACServerManager.ColsePort(portName);
Thread.Sleep(100);
IOMove(IO_Type.BatchAxis_ServoOn, IO_VALUE.LOW);
}
private void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.info( moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
/// <summary>
/// 松下伺服电机运动
/// </summary>
private void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
private bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue();
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error( moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
+ "],误差过大,需要报警";
LogUtil.error( msg);
}
}
return false;
}
private bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
{
msg = "";
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
{
//原点完成并且位置=0
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error( moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
//LogUtil.error( StoreName + moveAxis.DisplayStr + "重新回原点");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error( msg);
}
}
return false;
}
/// <summary>
/// 上下气缸移动到上升端
/// </summary>
/// <summary>
/// 上下气缸移动到上升端
/// </summary>
private void UpdownUpMove()
{
if (UpdownUseAxis)
if (UseAxis)
{
ACAxisMove(Config.Batch_Axis, Config.BatchAxisP1, Config.BatchAxis_P1Speed);
}
......@@ -703,10 +526,10 @@ namespace OnlineStore.DeviceLibrary
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
}
private void UpdownDownMove(int trayHeight)
{
if (UpdownUseAxis)
if (UseAxis)
{
int position = Config.GetUpdownPosition(trayHeight);
ACAxisMove(Config.Batch_Axis, position, Config.BatchAxis_DownSpeed);
......@@ -718,10 +541,10 @@ namespace OnlineStore.DeviceLibrary
}
private void UpdownDownBoxMove(int trayHeight)
{
if (UpdownUseAxis)
if (UseAxis)
{
int position = Config.GetUpdownBoxPosition(trayHeight);
ACAxisMove(Config.Batch_Axis, position,Config.BatchAxis_DownSpeed);
ACAxisMove(Config.Batch_Axis, position, Config.BatchAxis_DownSpeed);
}
else
{
......@@ -730,7 +553,7 @@ namespace OnlineStore.DeviceLibrary
}
private void UpdownHomeMove()
{
if (UpdownUseAxis)
if (UseAxis)
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownHomeMove);
ACAxisHomeMove(Config.Batch_Axis);
......@@ -742,10 +565,7 @@ namespace OnlineStore.DeviceLibrary
}
}
public override void Alarm(LineAlarmType alarmType, string alarmDetial, string alarmMsg, LineMoveType storeMoveType)
{
throw new NotImplementedException();
}
public override bool StartOutStoreMove(InOutParam param)
{
......@@ -757,153 +577,6 @@ namespace OnlineStore.DeviceLibrary
throw new NotImplementedException();
}
public override void StartInStoreMove(InOutParam param)
{
throw new NotImplementedException();
}
protected override void InStoreProcess()
{
throw new NotImplementedException();
}
#endregion
private DateTime preRWTime = DateTime.Now;
private void CheckWait(LineMoveInfo moveInfo)
{
List<WaitResultInfo> list = moveInfo.WaitList;
if (list.Count <= 0)
{
moveInfo.EndStepWait();
return;
}
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - moveInfo.LastSetpTime;
string NotOkMsg = "";
bool isOk = true;
if (moveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(1))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(LineAlarmType.AxisMoveError, 5.ToString(), WarnMsg, moveInfo.MoveType);
break;
}
}
else if (wait.WaitType.Equals(2))
{
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
//屏蔽料盘检测信号
if (wait.IoType.Equals(IO_Type.TrayCheck) && wait.IoValue.Equals(IO_VALUE.HIGH) && LineManager.Config.IsUse_Tray_Check.Equals(0))
{
LogUtil.debug(moveInfo.Name + "未检测到:IsUse_Tray_Check= " + wait.IoValue + ",直接跳过检测继续下一步");
}
//夹紧按钮若果超过一秒钟还未收到,默认成功
else if (wait.IoType.Equals(IO_Type.ClampCylinder_Slack) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 3000)
{
LogInfo("未检测到:ClampCylinder_Slack=HIGH,超过2秒钟,默认下一步骤");
wait.IsEnd = true;
}
else
{
TimeSpan rwSpan = DateTime.Now - preRWTime;
//一分钟还未检测到
if (span.TotalMilliseconds > LineManager.Config.IOSingle_TimerOut)
{
//把IO重置位0
LogUtil.error(moveInfo.Name + " : " + wait.IoType + "=" + wait.IoValue + " 已等待" + Math.Abs(span.TotalMilliseconds) + ",将DO写0", 17);
ConfigIO io = Config.getWaitIO(wait.IoType);
WarnMsg = Name + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时";
Alarm(LineAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(MoveInfo.Name + " : " + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 13);
foreach (WaitResultInfo ww in list)
{
if (ww != null && ww.WaitType.Equals(2))
{
if (Config.DOList.ContainsKey(ww.IoType))
{
IOMove(wait.IoType, IO_VALUE.LOW);
}
}
}
}
//else if (rwSpan.TotalSeconds > 3)
//{
// preRWTime = DateTime.Now;
// //把IO重置位0
// string msg = moveInfo.Name + " : " + wait.IoType + " = " + wait.IoValue + " 已等待" + Math.Abs(span.TotalMilliseconds) + ",重写DO信号:";
// foreach (WaitResultInfo ww in list)
// {
// if (ww != null && ww.WaitType.Equals(2))
// {
// if (Config.DOList.ContainsKey(ww.IoType))
// {
// IOMove(wait.IoType, ww.IoValue);
// msg += wait.ToStr()+",";
// }
// }
// }
// LogUtil.error(msg);
//}
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(3))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
if (wait.IsEnd && moveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
else if (!moveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
if (isOk)
{
moveInfo.EndStepWait();
}
else if (span.TotalSeconds > moveInfo.TimeOutSeconds)
{
WarnMsg = moveInfo.Name + "【" + moveInfo.MoveType + "】【" + moveInfo.MoveStep + "】等待[" + NotOkMsg
+ "]超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, 18);
Alarm(LineAlarmType.IoSingleTimeOut, "", WarnMsg, moveInfo.MoveType);
}
}
}
}
using System;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -6,7 +8,263 @@ using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
partial class FeedingEquip
partial class FeedingEquip
{
public override void StartInStoreMove(InOutParam param)
{
throw new NotImplementedException();
}
protected override void InStoreProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (MoveInfo.IsInWait)
{
return;
}
}
// if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I01_Wait))
// {
// MoveInfo.NextMoveStep(LineMoveStep.AUTO_I02_MoveToUp);
// if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.HIGH))
// {
// LogUtil.info(Name + " 入料 ,已检测到料盘,轴不需要上升");
// }
// else
// {
// LogUtil.info(Name + " 入料 ,轴上升到检测到料盘,速度【" + Config.Batch_Axis.TargetSpeed + "】");
// ACAxisSpeedMove(Config.Batch_Axis, Config.Batch_Axis.TargetSpeed, IO_Type.TrayCheck_LoadMaterial);
// }
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I02_MoveToUp))
// {
// IsNeedScanCode();
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I03_ScanCode))
// {
// MoveInfo.NextMoveStep(LineMoveStep.AUTO_I04_SuckingDisc_Down);
// LogUtil.info(Name + "入料: 扫码结束,二维码【" + LastCode + "】 吸盘开始下降");
// CylinderMove(IO_Type.ClampingDisc_Down, IO_Type.ClampingDisc_Up, true);
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I04_SuckingDisc_Down))
// {
// SuckingDiscWork();
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I05_SuckingDisc_Work))
// {
// // if (IOManager.IOValue(IO_Type.SuckingDisc_Air).Equals(IO_VALUE.HIGH))
// if (IOManager.IOValue(IO_Type.Clamping_Work).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.Clamping_Relax).Equals(IO_VALUE.LOW))
// {
// MoveInfo.NextMoveStep(LineMoveStep.AUTO_I06_SuckingDisc_Up);
// LogUtil.info(Name + "入料: 吸盘上升");
// CylinderMove(IO_Type.ClampingDisc_Up, IO_Type.ClampingDisc_Down, false);
// MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampingDisc_Down, IO_VALUE.LOW));
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1500));
// }
// else if (SuckingDisc_WorkCount < 3)
// {
// SuckingDiscWork();
// }
// else
// {
// //TODO 报警
// //WarnMsg = ResourceControl.GetString(ResourceControl.XiLiaoError, "吸盘吸料失败");
// SetWarnMsg(ResourceControl.XiLiaoError);
// StoreManager.Store.Alarm(StoreAlarmType.BatchAlarm, WarnObj.WarnMsg, WarnObj.WarnMsg, StoreMoveType.InStore);
// LogUtil.error(WarnObj.WarnMsg, 103);
// }
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I06_SuckingDisc_Up))
// {
// if (IOManager.IOValue(IO_Type.Clamping_Work).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.Clamping_Relax).Equals(IO_VALUE.LOW))
// // if (IOManager.IOValue(IO_Type.SuckingDisc_Air).Equals(IO_VALUE.HIGH))
// {
// MoveInfo.NextMoveStep(LineMoveStep.AUTO_I07_BatchAxisUp);
// LogUtil.info(Name + "入料: 批量轴匀速上升【" + Config.BatchAxis_SlowSpeed + "】");
// ACAxisSpeedMove(Config.Batch_Axis, Config.BatchAxis_SlowSpeed, IO_Type.TrayCheck_LoadMaterial);
// CylinderMove(IO_Type.ClampingDisc_Up, IO_Type.ClampingDisc_Down, true);
// if (Config.Default_TrayWidth.Equals(7))
// {
// MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck1, IO_VALUE.HIGH));
// MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck2, IO_VALUE.LOW));
// }
// else if (Config.Default_TrayWidth.Equals(13))
// {
// MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck1, IO_VALUE.HIGH));
// MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.WidthCheck2, IO_VALUE.HIGH));
// }
// else if (Config.Default_TrayWidth.Equals(0))
// {
// }
// }
// else
// {
// // WarnMsg = ResourceControl.GetString(ResourceControl.XiLiaoError, "吸盘吸料失败");
// SetWarnMsg(ResourceControl.XiLiaoError);
// StoreManager.Store.Alarm(StoreAlarmType.BatchAlarm, WarnObj.WarnMsg, WarnObj.WarnMsg, StoreMoveType.InStore);
// LogUtil.error(Name + "入料: 吸盘上升后未检测到吸盘压力信号,吸取料盘失败", 105);
// }
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I07_BatchAxisUp))
// {
// // if (IOManager.IOValue(IO_Type.SuckingDisc_Air).Equals(IO_VALUE.HIGH))
// if (IOManager.IOValue(IO_Type.Clamping_Work).Equals(IO_VALUE.HIGH) && IOManager.IOValue(IO_Type.Clamping_Relax).Equals(IO_VALUE.LOW))
// {
// TimeSpan span = DateTime.Now - MoveInfo.LastSetpTime;
// //需要判断入库超时
// if (StoreManager.Store.CanStarInOut())
// {
// LastWidth = Config.Default_TrayWidth;
// if (LastWidth.Equals(0))
// {
// //料盘检测2亮为13寸盘,其他都认为是7寸盘
// if (IOManager.IOValue(IO_Type.WidthCheck2).Equals(IO_VALUE.HIGH))
// {
// LastWidth = 13;
// }
// else
// {
// LastWidth = 7;
// }
// }
// LastHeight = GetHeight();
// BatchInStoreCount++;
// BatchInStoreHeight += LastHeight;
// if (LastCode.Equals(""))
// {
// LogUtil.info(Name + "入料: 未扫到二维码尺寸:【" + LastWidth + "*" + LastHeight + "】,将料盘送出,等待料盘拿走");
// SendTrayOut();
// }
// else
// {
// MoveInfo.NextMoveStep(LineMoveStep.AUTO_I08_GetPosId);
// LogUtil.debug(Name + "入料: 从服务器获取入库PosId,尺寸:【" + LastWidth + "*" + LastHeight + "】二维码【" + LastCode + "】");
// GetInStorePosId(ProcessMsg());
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
// }
// }
// else if (span.TotalSeconds > 60)
// {
// StoreManager.Store.LoguStatus();
// //一分钟还未开始,报警超时
// // WarnMsg = "[" + MoveInfo.MoveStep + "]" + ResourceControl.GetString(ResourceControl.TimeOut, "超时") + "[等待可以入库][" + Math.Round(span.TotalSeconds, 0) + "秒]";
// SetWarnMsg(ResourceControl.WaitInstoreTimeOut, MoveInfo.MoveStep + "", Math.Round(span.TotalSeconds, 0) + "");
// LogUtil.error(WarnObj.WarnMsg, 105);
// StoreManager.Store.Alarm(StoreAlarmType.BatchIoTimeOut, "", WarnObj.WarnMsg, MoveInfo.MoveType);
// }
// }
// else
// {
// //WarnMsg = ResourceControl.GetString(ResourceControl.XiLiaoError, "吸盘吸料失败");
// SetWarnMsg(ResourceControl.XiLiaoError);
// StoreManager.Store.Alarm(StoreAlarmType.BatchAlarm, ResourceControl.GetString(ResourceControl.XiLiaoError, "吸盘吸料失败"), WarnObj.WarnMsg, StoreMoveType.InStore);
// LogUtil.error(Name + "入料: 吸盘上升后未检测到吸盘压力信号,吸取料盘失败", 105);
// }
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I08_GetPosId))
// {
// //判断是否开始入库
// if (StoreManager.Store.MoveInfo.MoveType.Equals(StoreMoveType.InStore) || (!LastPosId.Equals("")))
// {
// MoveInfo.NextMoveStep(LineMoveStep.AUTO_I09_WaitTrayLeave);
// LogUtil.info(Name + "入料: 开始入库【" + LastPosId + "】,等待料盘拿走");
// //MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SuckingDisc_Air, IO_VALUE.LOW));
// MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Clamping_Relax, IO_VALUE.HIGH));
// MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Clamping_Work, IO_VALUE.LOW));
// }
// else
// {
// LogUtil.info(Name + "入料: 入库失败,尺寸:【" + LastWidth + "*" + LastHeight + "】将料盘送出,等待料盘拿走");
// SendTrayOut();
// }
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I09_WaitTrayLeave))
// {
// if (StoreManager.Store.MoveInfo.MoveType.Equals(StoreMoveType.None) ||
// (StoreManager.Store.MoveInfo.IsNeedInStore && StoreManager.Store.MoveInfo.MoveStep >= LineMoveStep.SI_09_MoveToBag))
// {
// IsNeedScanCode();
// }
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I10_WaitTrayGo))
// {
// if (StoreManager.Store.CanStarInOut())
// {
// IsNeedScanCode();
// }
// }
// else if (MoveInfo.MoveStep.Equals(LineMoveStep.AUTO_I11_BatchAxisHome))
// {
// //TODO
// LogUtil.info(Name + "入料:已经没有料盘,批量上料结束");
// MoveInfo.EndMove();
// AutoBaitingStatus = StoreRunStatus.Runing;
// }
// else
// {
// LogUtil.error(Name + "未找到步骤:" + MoveInfo.MoveType);
// }
// } }
// private static int GetHeight()
//{
// //计算高度
// EndMovePosition = ACServerManager.GetActualtPosition(Config.Batch_Axis);
// if (EndMovePosition.Equals(-1))
// {
// EndMovePosition = ACServerManager.GetActualtPosition(Config.Batch_Axis);
// }
// LastHeight = (int)Math.Ceiling(1F * (EndMovePosition - StartMovePosition) / AxisChangeValue);
// int addHeight = 0;
// //如果检测信号未亮,极限亮了,需要补充高
// if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.LOW))
// {
// addHeight = Config.LastTrayAddHeight;
// }
// LastHeight += addHeight;
// string msg = Name + " 计算盘高:上升前【" + StartMovePosition + "】实时【" + EndMovePosition + "】补充【" + addHeight + "】计算后【" + LastHeight + "】";
// if (LastHeight < 0)
// {
// LastHeight = Config.GetDefaultHeight();
// }
// if (Config.Default_TrayWidth.Equals(7))
// {
// //高度=8的料盘容易被测成12的,判断如果计算的高度<12都认为是8mm,
// if (LastHeight >= 20)
// {
// LastHeight = 24;
// }
// else if (LastHeight >= 12)
// {
// LastHeight = 12;
// }
// else
// {
// LastHeight = 8;
// }
// }
// else
// {
// if (LastHeight <= 8) { LastHeight = 8; }
// else
// {
// LastHeight = (int)Math.Ceiling(1F * LastHeight / 4) * 4;
// }
// }
// LogUtil.info(msg + ",归类为" + LastHeight);
// return LastHeight;
// }
}
}
......@@ -13,12 +13,12 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 流水线自动料仓-移栽装置类
/// </summary>
public partial class MoveEquip : KTK_Store
public partial class MoveEquip : EquipBase
{
private bool IsIntSlvBlock = false;
public bool IsDebug = false;
public bool UpdownUseAxis = false;
public AxisAlarmInfo AxisAlarm = new AxisAlarmInfo();
// public bool IsDebug = false;
// public bool UseAxis = false;
// public AxisAlarmInfo AxisAlarm = new AxisAlarmInfo();
public MoveEquip_Config Config;
/// <summary>
......@@ -48,8 +48,8 @@ namespace OnlineStore.DeviceLibrary
MoveInfo = new LineMoveInfo(DeviceID, "移栽-" + DeviceID + "-MoveInfo");
SecondMoveInfo = new LineMoveInfo(DeviceID, "移栽-" + DeviceID + "-SecondMoveInfo");
IsDebug = config.IsDebug.Equals(1);
UpdownUseAxis = config.UpDownUseAxis.Equals(1);
if (UpdownUseAxis)
UseAxis = config.UpDownUseAxis.Equals(1);
if (UseAxis)
{
Config.UpDown_Axis.TargetSpeed = Config.UpdownAxis_TargetSpeed;
Config.UpDown_Axis.AddSpeed = Config.UpdownAxis_AddSpeed;
......@@ -76,7 +76,7 @@ namespace OnlineStore.DeviceLibrary
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
return MoveEquipMentHome();
return ReturnHome();
}
public bool StartDebugRun()
......@@ -89,7 +89,7 @@ namespace OnlineStore.DeviceLibrary
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
bool result = MoveEquipMentHome();
bool result = ReturnHome();
if (result)
{
mainTimer.Enabled = true;
......@@ -297,10 +297,10 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 移栽装置原点返回
/// </summary>
public bool MoveEquipMentHome()
public bool ReturnHome()
{
mainTimer.Stop();
if (!RunAxis(true))
if (!RunAxis(true,Config.UpDown_Axis))
{
return false;
}
......@@ -339,7 +339,7 @@ namespace OnlineStore.DeviceLibrary
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
if (!RunAxis(true))
if (!RunAxis(true, Config.UpDown_Axis))
{
return false;
}
......@@ -500,7 +500,7 @@ namespace OnlineStore.DeviceLibrary
{
LogInfo("停止运行完成!");
if (UpdownUseAxis)
if (UseAxis)
{
LogInfo("停止运动:停止伺服");
ACServerManager.SuddenStop(Config.UpDown_Axis);
......@@ -572,7 +572,7 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
//上下气缸上升
if (UpdownUseAxis.Equals(false))
if (UseAxis.Equals(false))
{
IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.HIGH);
......@@ -595,181 +595,181 @@ namespace OnlineStore.DeviceLibrary
}
#region 上下气缸伺服运动
private string portName;
private short slvAddr;
public bool RunAxis(bool isCheck)
{
if (!UpdownUseAxis)
{
return true;
}
IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
ACServerManager.OpenPort(portName);
Thread.Sleep(50);
//初始化
if (!IsIntSlvBlock)
{
ACServerManager.InitSlvAddr(portName, slvAddr, Config.UpDown_Axis.TargetSpeed, Config.UpDown_Axis.AddSpeed, Config.UpDown_Axis.DelSpeed);
Thread.Sleep(100);
}
ACServerManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
ACServerManager.ServoOn(portName, slvAddr);
Thread.Sleep(1000);
//打开所有轴
if (isCheck)
{
if (!OpenAxis())
{
return false;
}
}
IsIntSlvBlock = true;
IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.HIGH);
return true;
}
/// <summary>
/// 打开所有轴
/// </summary>
/// <returns></returns>
private bool OpenAxis()
{
//判断轴是否正常
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info(Name + "成功打开轴:" + Config.UpDown_Axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogUtil.info(Name + "第一次打开轴" + Config.UpDown_Axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(portName, slvAddr);
System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(portName, slvAddr);
System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info(Name + "清理报警后重新打卡轴成功:" + Config.UpDown_Axis.Explain);
}
else
{
ACServerManager.ServoOff(portName, slvAddr);
WarnMsg = Name + "打开轴" + Config.UpDown_Axis.Explain + "失败 ";
LogUtil.info(Name + WarnMsg);
Alarm(LineAlarmType.AxisAlarm, 5.ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
return true;
}
public void CloseAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.LOW);
ACServerManager.ServoOff(portName, slvAddr);
//关闭串口,等下次重新打开
// ACServerManager.ColsePort(portName);
Thread.Sleep(100);
IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.LOW);
}
private void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.info(moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
/// <summary>
/// 松下伺服电机运动
/// </summary>
private void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
private bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue();
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error(moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
+ "],误差过大,需要报警";
LogUtil.error(msg);
}
}
return false;
}
private bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
{
msg = "";
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
{
//原点完成并且位置=0
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error(moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
//LogUtil.error( StoreName + moveAxis.DisplayStr + "重新回原点");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error(msg);
}
}
return false;
}
//private string portName;
//private short slvAddr;
//public bool RunAxis(bool isCheck)
//{
// if (!UseAxis)
// {
// return true;
// }
// IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.HIGH);
// Thread.Sleep(1000);
// //打开所有轴
// ACServerManager.OpenPort(portName);
// Thread.Sleep(50);
// //初始化
// if (!IsIntSlvBlock)
// {
// ACServerManager.InitSlvAddr(portName, slvAddr, Config.UpDown_Axis.TargetSpeed, Config.UpDown_Axis.AddSpeed, Config.UpDown_Axis.DelSpeed);
// Thread.Sleep(100);
// }
// ACServerManager.AlarmClear(portName, slvAddr);
// Thread.Sleep(50);
// ACServerManager.ServoOn(portName, slvAddr);
// Thread.Sleep(1000);
// //打开所有轴
// if (isCheck)
// {
// if (!OpenAxis())
// {
// return false;
// }
// }
// IsIntSlvBlock = true;
// IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.HIGH);
// return true;
//}
///// <summary>
///// 打开所有轴
///// </summary>
///// <returns></returns>
//private bool OpenAxis()
//{
// //判断轴是否正常
// if (ACServerManager.ServerOnStatus(portName, slvAddr))
// {
// LogUtil.info(Name + "成功打开轴:" + Config.UpDown_Axis.Explain);
// }
// else
// {
// //清理报警,再重新打开一次
// LogUtil.info(Name + "第一次打开轴" + Config.UpDown_Axis.Explain + "失败,先清理一下报警,再重新打开一次");
// ACServerManager.AlarmClear(portName, slvAddr);
// System.Threading.Thread.Sleep(1200);
// ACServerManager.ServoOn(portName, slvAddr);
// System.Threading.Thread.Sleep(100);
// if (ACServerManager.ServerOnStatus(portName, slvAddr))
// {
// LogUtil.info(Name + "清理报警后重新打卡轴成功:" + Config.UpDown_Axis.Explain);
// }
// else
// {
// ACServerManager.ServoOff(portName, slvAddr);
// WarnMsg = Name + "打开轴" + Config.UpDown_Axis.Explain + "失败 ";
// LogUtil.info(Name + WarnMsg);
// Alarm(LineAlarmType.AxisAlarm, 5.ToString(), WarnMsg, MoveInfo.MoveType);
// return false;
// }
// }
// return true;
//}
//public void CloseAxis()
//{
// LogUtil.info(Name + "关闭刹车,关闭伺服");
// IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.LOW);
// ACServerManager.ServoOff(portName, slvAddr);
// //关闭串口,等下次重新打开
// // ACServerManager.ColsePort(portName);
// Thread.Sleep(100);
// IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.LOW);
//}
//private void ACAxisHomeMove(ConfigMoveAxis moveAxis)
//{
// moveAxis.TargetPosition = 0;
// LogUtil.info(moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
// MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
// ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
//}
///// <summary>
///// 松下伺服电机运动
///// </summary>
//private void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
//{
// MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
// moveAxis.TargetPosition = targetPosition;
// ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
//}
///// <summary>
///// 判断AC伺服电机轴是否运动完成
///// </summary>
//private bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
//{
// msg = "";
// string deviceName = moveAxis.DeviceName;
// short axisNo = moveAxis.GetAxisValue();
// bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
// int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
// int errorCount = Math.Abs(outCount - targetPosition);
// if (isOk)
// {
// if (errorCount <= moveAxis.CanErrorCountMax)
// {
// return true;
// }
// //判断是否需要重新运动
// if (MoveInfo.CanWhileCount > 0)
// {
// LogUtil.error(moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
// "],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
// ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
// MoveInfo.CanWhileCount--;
// }
// else
// {
// msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
// + "],误差过大,需要报警";
// LogUtil.error(msg);
// }
// }
// return false;
//}
//private bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
//{
// msg = "";
// if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
// {
// //原点完成并且位置=0
// int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
// int errorCount = Math.Abs(outCount);
// if (errorCount <= moveAxis.CanErrorCountMax)
// {
// return true;
// }
// //判断是否需要重新运动
// if (MoveInfo.CanWhileCount > 0)
// {
// LogUtil.error(moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
// //LogUtil.error( StoreName + moveAxis.DisplayStr + "重新回原点");
// ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
// MoveInfo.CanWhileCount--;
// }
// else
// {
// msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
// LogUtil.error(msg);
// }
// }
// return false;
//}
/// <summary>
/// 上下气缸移动到上升端
/// </summary>
private void UpdownUpMove()
{
if (UpdownUseAxis)
if (UseAxis)
{
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
}
......@@ -781,7 +781,7 @@ namespace OnlineStore.DeviceLibrary
private void UpdownDownMove(int trayHeight)
{
if (UpdownUseAxis)
if (UseAxis)
{
int position = Config.GetUpdownPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position, Config.UpdownAxis_DownSpeed);
......@@ -793,7 +793,7 @@ namespace OnlineStore.DeviceLibrary
}
private void UpdownDownBoxMove(int trayHeight)
{
if (UpdownUseAxis)
if (UseAxis)
{
int position = Config.GetUpdownBoxPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position, Config.UpdownAxis_DownSpeed);
......@@ -805,7 +805,7 @@ namespace OnlineStore.DeviceLibrary
}
private void UpdownHomeMove()
{
if (UpdownUseAxis)
if (UseAxis)
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownHomeMove);
ACAxisHomeMove(Config.UpDown_Axis);
......
......@@ -11,158 +11,10 @@ namespace OnlineStore.DeviceLibrary
{
partial class MoveEquip
{
/// <summary>
/// 上一个盘号
/// </summary>
internal int preTrayNum = 0;
/// <summary>
/// 当前正在通过的托盘号
/// </summary>
private int currMoveTrayNum = 0;
private DateTime preRWTime = DateTime.Now;
private void CheckWait(LineMoveInfo moveInfo)
{
List<WaitResultInfo> list = moveInfo.WaitList;
if (list.Count <= 0)
{
moveInfo.EndStepWait();
return;
}
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - moveInfo.LastSetpTime;
string NotOkMsg = "";
bool isOk = true;
if (moveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(1))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(LineAlarmType.AxisMoveError, 5.ToString(), WarnMsg, moveInfo.MoveType);
break;
}
}
else if (wait.WaitType.Equals(2))
{
NotOkMsg = " (" + Config.GetDisplayName(wait.IoType) + "=" + wait.IoValue + ") ";
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
//屏蔽料盘检测信号
if (wait.IoType.Equals(IO_Type.TrayCheck) && wait.IoValue.Equals(IO_VALUE.HIGH) && LineManager.Config.IsUse_Tray_Check.Equals(0))
{
LogUtil.debug(moveInfo.Name + "未检测到:IsUse_Tray_Check= " + wait.IoValue + ",直接跳过检测继续下一步");
}
//夹紧按钮若果超过一秒钟还未收到,默认成功
else if (wait.IoType.Equals(IO_Type.ClampCylinder_Slack) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 4000)
{
LogInfo("未检测到:ClampCylinder_Slack=HIGH,超过4秒钟,默认下一步骤");
wait.IsEnd = true;
}
else
{
TimeSpan rwSpan = DateTime.Now - preRWTime;
//一分钟还未检测到
if (span.TotalMilliseconds > LineManager.Config.IOSingle_TimerOut)
{
ConfigIO io = Config.getWaitIO(wait.IoType);
WarnMsg = Name + "等待" + NotOkMsg + " 超时";
Alarm(LineAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(MoveInfo.Name + WarnMsg, 13);
}
else if (rwSpan.TotalSeconds > 3 && span.TotalSeconds > 3)
{
preRWTime = DateTime.Now;
string msg = moveInfo.Name + " " + NotOkMsg + "已等待 " + Math.Abs(span.TotalSeconds) + "秒,重写DO:";
bool isLog = false;
foreach (WaitResultInfo ww in list)
{
if (ww != null && ww.WaitType.Equals(2) && Config.DOList.ContainsKey(ww.IoType))
{
isLog = true;
IOMove(ww.IoType, ww.IoValue);
msg += ww.ToStr() + ",";
}
}
if (isLog)
{
LogUtil.error(msg);
}
}
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(3))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(8))
{
string posId = moveInfo.MoveParam.PosId;
int id = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.RightInPosId(id, posId);
}
else if (wait.WaitType.Equals(9))
{
int storeId = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.BoxCanReviceTray(storeId);
}
else if (wait.WaitType.Equals(10))
{
wait.IsEnd = LineManager.Line.SideWay34HasTray().Equals(false);
}
if (wait.IsEnd && moveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
else if (!moveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
if (isOk)
{
moveInfo.EndStepWait();
}
else if (span.TotalSeconds > moveInfo.TimeOutSeconds)
{
WarnMsg = moveInfo.Name + "[" + moveInfo.MoveType + "][" + moveInfo.MoveStep + "]等待[" + NotOkMsg
+ "]超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, 18);
Alarm(LineAlarmType.IoSingleTimeOut, "", WarnMsg, moveInfo.MoveType);
}
}
#region 出库
public override bool StartOutStoreMove(InOutParam param)
{
{
string posId = param != null ? param.PosId : "";
//调试模式移栽装置不需要有操作
if (IsDebug)
......@@ -807,14 +659,7 @@ namespace OnlineStore.DeviceLibrary
}
#endregion
public override void Alarm(LineAlarmType alarmType, string alarmDetial, string alarmMsg, LineMoveType storeMoveType)
{
if (this.alarmType.Equals(alarmType))
{
return;
}
this.alarmType = alarmType;
}
private void CheckLog(string msg)
{
LogUtil.debug(Name + msg);
......@@ -831,25 +676,7 @@ namespace OnlineStore.DeviceLibrary
}
public void CylinderMove(LineMoveInfo moveInfo, string IoLowType, string IoHighType)
{
IOMove(IoLowType, IO_VALUE.LOW);
IOMove(IoHighType, IO_VALUE.HIGH);
if (moveInfo != null)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoLowType, IO_VALUE.LOW));
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoHighType, IO_VALUE.HIGH));
}
}
public void IOMove(string IoType, IO_VALUE value)
{
IOManager.IOMove(IoType, value, Config.Id);
}
public IO_VALUE IOValue(string IoType)
{
return IOManager.IOValue(IoType, Config.Id);
}
public void LogInfo(string logInfo)
{
LogUtil.info(Name + logInfo);
......
......@@ -13,30 +13,27 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 流水线自动料仓-出料装置类
/// </summary>
public partial class ProvidingEquip : KTK_Store
public partial class ProvidingEquip : EquipBase
{
private bool IsIntSlvBlock = false;
public bool IsDebug = false;
public bool UpdownUseAxis = false;
public AxisAlarmInfo AxisAlarm = new AxisAlarmInfo();
public ProvidingEquip_Config Config;
/// <summary>
///出料装置后面分为两条移动线
/// </summary>
public LineMoveInfo SecondMoveInfo = null;
// public List<InOutParam> waitOutStoreList = new List<InOutParam>();
// public List<InOutParam> waitOutStoreList = new List<InOutParam>();
public List<InOutParam> waitInStoreList = new List<InOutParam>();
public object waitInListLock = "";
// public object waitOutListLock = "";
// public object waitOutListLock = "";
public ProvidingEquip(string cid, ProvidingEquip_Config config)
{
baseConfig = config;
this.DeviceID = config.Id;
this.Config = config;
Name = (" " + "_出料_" + DeviceID % 10 + " ").ToUpper();
Name = (" " + "_出料_" + DeviceID % 10 + " ").ToUpper();
//Name = (" " + cid + "_出料_" + DeviceID + " ").ToUpper();
Init();
//添加调试
......@@ -45,42 +42,42 @@ namespace OnlineStore.DeviceLibrary
IsDebug = true;
}
//this.Box = box;
MoveInfo = new LineMoveInfo(DeviceID,"出料-"+DeviceID+"-MoveInfo");
MoveInfo = new LineMoveInfo(DeviceID, "出料-" + DeviceID + "-MoveInfo");
SecondMoveInfo = new LineMoveInfo(DeviceID, "出料-" + DeviceID + "-SecondMoveInfo");
IsDebug = config.IsDebug.Equals(1);
UpdownUseAxis = config.UpDownUseAxis.Equals(1);
if (UpdownUseAxis)
{
Config.UpDown_Axis.TargetSpeed = Config.UpdownAxis_TargetSpeed;
Config.UpDown_Axis.AddSpeed = Config.UpdownAxis_AddSpeed;
Config.UpDown_Axis.DelSpeed = Config.UpdownAxis_DelSpeed;
Config.UpDown_Axis.HomeAddSpeed = Config.UpdownAxis_HomeAddSpeed;
Config.UpDown_Axis.HomeHighSpeed = Config.UpdownAxis_HomeHighSpeed;
Config.UpDown_Axis.HomeLowSpeed = Config.UpdownAxis_HomeLowSpeed;
//UpdownUseAxis = config.UpDownUseAxis.Equals(1);
//if (UpdownUseAxis)
//{
// Config.UpDown_Axis.TargetSpeed = Config.UpdownAxis_TargetSpeed;
// Config.UpDown_Axis.AddSpeed = Config.UpdownAxis_AddSpeed;
// Config.UpDown_Axis.DelSpeed = Config.UpdownAxis_DelSpeed;
// Config.UpDown_Axis.HomeAddSpeed = Config.UpdownAxis_HomeAddSpeed;
// Config.UpDown_Axis.HomeHighSpeed = Config.UpdownAxis_HomeHighSpeed;
// Config.UpDown_Axis.HomeLowSpeed = Config.UpdownAxis_HomeLowSpeed;
portName = Config.UpDown_Axis.DeviceName;
slvAddr = config.UpDown_Axis.GetAxisValue();
}
// portName = Config.UpDown_Axis.DeviceName;
// slvAddr = config.UpDown_Axis.GetAxisValue();
//}
}
/// <summary>
/// 开始运行
/// </summary>
public override bool StartRun( )
public override bool StartRun()
{
//preTrayNum = 0;
// currMoveTrayNum = 0;
// currMoveTrayNum = 0;
mainTimer.Enabled = false;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
lineStatus = LineStatus.StoreOnline;
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
return MoveEquipMentHome();
return ReturnHome();
}
public bool StartDebugRun()
public bool StartDebugRun()
{
//preTrayNum = 0;
//currMoveTrayNum = 0;
......@@ -90,7 +87,7 @@ namespace OnlineStore.DeviceLibrary
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
bool result= MoveEquipMentHome();
bool result = ReturnHome();
if (result)
{
mainTimer.Enabled = true;
......@@ -102,8 +99,8 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
public override void StopRun()
{
// preTrayNum = 0;
// currMoveTrayNum = 0;
// preTrayNum = 0;
// currMoveTrayNum = 0;
if (mainTimer != null)
{
mainTimer.Enabled = false;
......@@ -168,13 +165,13 @@ namespace OnlineStore.DeviceLibrary
StopMoveProcess();
}
if (SecondMoveInfo.MoveType .Equals( LineMoveType.CheckFixture))
if (SecondMoveInfo.MoveType.Equals(LineMoveType.CheckFixture))
{
// CheckFixtureProcess();
// CheckFixtureProcess();
}
}
protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
TimerProcess();
......@@ -200,10 +197,10 @@ namespace OnlineStore.DeviceLibrary
if (SecondMoveInfo.MoveType.Equals(LineMoveType.None))
{
LineBean lineBean = LineManager.Line;
if (lineBean.isCanProcessLine() && IOManager.IOValue(IO_Type.DriveMotor_Run,0).Equals(IO_VALUE.HIGH) && lineBean.runStatus >= LineRunStatus.Runing && lineBean.IsSleep.Equals(false))
if (lineBean.isCanProcessLine() && IOManager.IOValue(IO_Type.DriveMotor_Run, 0).Equals(IO_VALUE.HIGH) && lineBean.runStatus >= LineRunStatus.Runing && lineBean.IsSleep.Equals(false))
{
// LogUtil.info("StartCheckFixture");
// StartCheckFixture();
// LogUtil.info("StartCheckFixture");
// StartCheckFixture();
}
}
IOTimeOutProcess();
......@@ -222,17 +219,17 @@ namespace OnlineStore.DeviceLibrary
try
{
TimeSpan span = DateTime.Now - preIoTimerOutTime;
if (span.TotalSeconds > 1&& alarmType.Equals(LineAlarmType.IoSingleTimeOut))
if (span.TotalSeconds > 1 && alarmType.Equals(LineAlarmType.IoSingleTimeOut))
{
preIoTimerOutTime = DateTime.Now;
if (runStatus < LineRunStatus.Runing|| isInSuddenDown || isNoAirCheck)
if (runStatus < LineRunStatus.Runing || isInSuddenDown || isNoAirCheck)
{
return;
}
}
//若BOX和出料都没有在等待Io的过程中则此Io超时异常可能已经处理过
if (MoveInfo.IsInWait .Equals(false)&&SecondMoveInfo.IsInWait.Equals(false))
if (MoveInfo.IsInWait.Equals(false) && SecondMoveInfo.IsInWait.Equals(false))
{
LogUtil.info(Name + "清理信号超时报警【" + WarnMsg + "】 ");
alarmType = LineAlarmType.None;
......@@ -242,28 +239,28 @@ namespace OnlineStore.DeviceLibrary
}
catch (Exception ex)
{
LogUtil.error( "IOTimeOutProcess出错:" + ex.ToString());
LogUtil.error("IOTimeOutProcess出错:" + ex.ToString());
}
}
/// <summary>
/// 出料装置原点返回
/// </summary>
public bool MoveEquipMentHome()
public bool ReturnHome()
{
mainTimer.Stop();
if (!RunAxis(true))
{
return false;
}
//if (!RunAxis(true))
//{
// return false;
//}
alarmType = LineAlarmType.None;
runStatus = LineRunStatus.HomeMoving;
LogInfo( "开始原点返回: (上下气缸回原点,阻挡气缸输入=0 )开始");
LogInfo("开始原点返回: (上下气缸回原点,阻挡气缸输入=0 )开始");
MoveInfo.NewMove(LineMoveType.ReturnHome);
//移载装置原点状态:顶升气缸下降端,前后气缸后退端,上下气缸上升端,夹料气缸放松端,阻挡气缸输入=0
UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
//UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
if (IsDebug)
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
......@@ -272,17 +269,17 @@ namespace OnlineStore.DeviceLibrary
else
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
return true;
}
/// <summary>
/// 出料装置重置
/// </summary>
public override bool Reset()
public override bool Reset()
{
WarnMsg = "";
//如果正在出库中,需要减去托盘号
if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{
......@@ -290,22 +287,22 @@ namespace OnlineStore.DeviceLibrary
//减去需要的盘数
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
if (!RunAxis(true))
{
return false;
}
// if (!RunAxis(true))
//{
// return false;
// }
alarmType = LineAlarmType.None;
//重置时清理盘号,从头开始判断
// preTrayNum = 0;
// currMoveTrayNum = 0;
LogInfo( "开始重置:清零上一个托盘号,(上下气缸回原点,阻挡气缸输入=0 )开始;");
// preTrayNum = 0;
// currMoveTrayNum = 0;
LogInfo("开始重置:清零上一个托盘号,(上下气缸回原点,阻挡气缸输入=0 )开始;");
runStatus = LineRunStatus.Reset;
SecondMoveInfo.EndMove();
MoveInfo.NewMove(LineMoveType.Reset);
UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
// UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
if (IsDebug)
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
......@@ -345,12 +342,12 @@ namespace OnlineStore.DeviceLibrary
case LineMoveStep.MH_UpDownHomeMove:
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
LogInfo("重置: (上下轴原点返回完成,上下轴走到待机点 )开始");
UpdownUpMove();
// UpdownUpMove();
break;
case LineMoveStep.MH_UpDownCylinder_Up:
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
LogInfo( "重置: (上升到位,顶升气缸下降,前后气缸回退 )开始");
LogInfo("重置: (上升到位,顶升气缸下降,前后气缸回退 )开始");
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
......@@ -358,7 +355,7 @@ namespace OnlineStore.DeviceLibrary
case LineMoveStep.MH_OtherCylinder_Back:
LogInfo( "重置完成!");
LogInfo("重置完成!");
runStatus = LineRunStatus.Runing;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
......@@ -373,7 +370,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 原点返回处理
/// </summary>
protected void ReturnHomeProcess()
protected void ReturnHomeProcess()
{
if (MoveInfo.IsInWait)
{
......@@ -390,7 +387,7 @@ namespace OnlineStore.DeviceLibrary
case LineMoveStep.MH_UpDownHomeMove:
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
LogInfo("原点返回: (上下轴原点返回完成,上下轴走到待机点 )开始");
UpdownUpMove();
// UpdownUpMove();
break;
case LineMoveStep.MH_UpDownCylinder_Up:
......@@ -405,7 +402,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
LogInfo( "原点返回完成!");
LogInfo("原点返回完成!");
runStatus = LineRunStatus.Runing;
//如果是调试模式,出料装置两个阻挡气缸落下,并且不再移动
if (IsDebug)
......@@ -436,12 +433,12 @@ namespace OnlineStore.DeviceLibrary
if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
{
switch (MoveInfo.MoveStep)
{
{
//流水线各装置复原位,夹料气缸状态不变 //阻挡气缸全部=0 //上下气缸上升,、 //上升到位,顶升气缸下降,前后气缸回退
case LineMoveStep.MH_UpDownCylinder_Up:
{
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
LogInfo( "停止运动: (上升到位,顶升气缸下降,前后气缸回退 )开始");
LogInfo("停止运动: (上升到位,顶升气缸下降,前后气缸回退 )开始");
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
......@@ -451,13 +448,13 @@ namespace OnlineStore.DeviceLibrary
case LineMoveStep.MH_OtherCylinder_Back:
{
LogInfo("停止运行完成,停止伺服!");
CloseAxis();
if (UpdownUseAxis)
{
LogInfo("停止运动:停止伺服");
ACServerManager.SuddenStop(Config.UpDown_Axis);
}
// CloseAxis();
//if (UpdownUseAxis)
//{
// LogInfo("停止运动:停止伺服");
// ACServerManager.SuddenStop(Config.UpDown_Axis);
//}
runStatus = LineRunStatus.Runing;
MoveInfo.EndMove();
break;
......@@ -474,22 +471,22 @@ namespace OnlineStore.DeviceLibrary
//如果正在出库中,需要减去托盘号
if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{
LogInfo( "停止运动时出库执行中,减去托盘数;");
LogInfo("停止运动时出库执行中,减去托盘数;");
//减去需要的盘数
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
runStatus = LineRunStatus.Busy;
SecondMoveInfo.EndMove();
LogInfo( "停止运动:(上下气缸上升端,阻挡气缸输入=0 )开始 ");
SecondMoveInfo.EndMove();
LogInfo("停止运动:(上下气缸上升端,阻挡气缸输入=0 )开始 ");
MoveInfo.NewMove(LineMoveType.StopMove);
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
UpdownUpMove();
// UpdownUpMove();
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
public void ChangeDebug()
......@@ -520,11 +517,11 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
internal void OpenStopCylinder()
{
LogInfo( "下降阻挡气缸,上下气缸上升,顶升气缸下降");
LogInfo("下降阻挡气缸,上下气缸上升,顶升气缸下降");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
//上下气缸上升
if (UpdownUseAxis.Equals(false))
// if (UpdownUseAxis.Equals(false))
{
IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.HIGH);
......@@ -535,7 +532,7 @@ namespace OnlineStore.DeviceLibrary
}
internal void CloseCylinderStop()
{
LogInfo( "上升阻挡气缸,关闭上下气缸,顶升气缸IO");
LogInfo("上升阻挡气缸,关闭上下气缸,顶升气缸IO");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
//上下气缸上升
......@@ -545,229 +542,7 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.TopCylinder_UP, IO_VALUE.LOW);
IOMove(IO_Type.TopCylinder_Down, IO_VALUE.LOW);
}
#region 上下气缸伺服运动
private string portName;
private short slvAddr;
public bool RunAxis(bool isCheck)
{
if (!UpdownUseAxis)
{
return true;
}
IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
ACServerManager.OpenPort(portName);
Thread.Sleep(50);
//初始化
if (!IsIntSlvBlock)
{
ACServerManager.InitSlvAddr(portName, slvAddr, Config.UpDown_Axis.TargetSpeed, Config.UpDown_Axis.AddSpeed, Config.UpDown_Axis.DelSpeed);
Thread.Sleep(100);
}
ACServerManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
ACServerManager.ServoOn(portName, slvAddr);
Thread.Sleep(1000);
//打开所有轴
if (isCheck)
{
if (!OpenAxis())
{
return false;
}
}
IsIntSlvBlock = true;
IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.HIGH);
return true;
}
/// <summary>
/// 打开所有轴
/// </summary>
/// <returns></returns>
private bool OpenAxis()
{
//判断轴是否正常
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info( Name + "成功打开轴:" + Config.UpDown_Axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogUtil.info( Name + "第一次打开轴" + Config.UpDown_Axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(portName, slvAddr);
System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(portName, slvAddr);
System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info( Name + "清理报警后重新打卡轴成功:" + Config.UpDown_Axis.Explain);
}
else
{
ACServerManager.ServoOff(portName, slvAddr);
WarnMsg = Name + "打开轴" + Config.UpDown_Axis.Explain + "失败 ";
LogUtil.info( Name + WarnMsg);
Alarm(LineAlarmType.AxisAlarm, 5.ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
return true;
}
public void CloseAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.LOW);
ACServerManager.ServoOff(portName, slvAddr);
//关闭串口,等下次重新打开
ACServerManager.ColsePort(portName);
Thread.Sleep(100);
IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.LOW);
}
private void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.info( moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
/// <summary>
/// 松下伺服电机运动
/// </summary>
private void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
private bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue();
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error( moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
+ "],误差过大,需要报警";
LogUtil.error( msg);
}
}
return false;
}
private bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
{
msg = "";
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
{
//原点完成并且位置=0
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error( moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
//LogUtil.error( StoreName + moveAxis.DisplayStr + "重新回原点");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error( msg);
}
}
return false;
}
/// <summary>
/// 上下气缸移动到上升端
/// </summary>
private void UpdownUpMove()
{
if (UpdownUseAxis)
{
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
}
private void UpdownDownMove(int trayHeight)
{
if (UpdownUseAxis)
{
int position = Config.GetUpdownPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position, Config.UpdownAxis_DownSpeed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
}
}
private void UpdownDownBoxMove(int trayHeight)
{
if (UpdownUseAxis)
{
int position = Config.GetUpdownBoxPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position,Config.UpdownAxis_DownSpeed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
}
}
private void UpdownHomeMove()
{
if (UpdownUseAxis)
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownHomeMove);
ACAxisHomeMove(Config.UpDown_Axis);
}
else
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
}
public override void Alarm(LineAlarmType alarmType, string alarmDetial, string alarmMsg, LineMoveType storeMoveType)
{
......@@ -793,125 +568,5 @@ namespace OnlineStore.DeviceLibrary
{
throw new NotImplementedException();
}
#endregion
private DateTime preRWTime = DateTime.Now;
private void CheckWait(LineMoveInfo moveInfo)
{
List<WaitResultInfo> list = moveInfo.WaitList;
if (list.Count <= 0)
{
moveInfo.EndStepWait();
return;
}
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - moveInfo.LastSetpTime;
string NotOkMsg = "";
bool isOk = true;
if (moveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(1))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(LineAlarmType.AxisMoveError, 5.ToString(), WarnMsg, moveInfo.MoveType);
break;
}
}
else if (wait.WaitType.Equals(2))
{
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
//屏蔽料盘检测信号
if (wait.IoType.Equals(IO_Type.TrayCheck) && wait.IoValue.Equals(IO_VALUE.HIGH) && LineManager.Config.IsUse_Tray_Check.Equals(0))
{
LogUtil.debug(moveInfo.Name + "未检测到:IsUse_Tray_Check= " + wait.IoValue + ",直接跳过检测继续下一步");
}
//夹紧按钮若果超过一秒钟还未收到,默认成功
else if (wait.IoType.Equals(IO_Type.ClampCylinder_Slack) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 3000)
{
LogInfo("未检测到:ClampCylinder_Slack=HIGH,超过2秒钟,默认下一步骤");
wait.IsEnd = true;
}
else
{
TimeSpan rwSpan = DateTime.Now - preRWTime;
//一分钟还未检测到
if (span.TotalMilliseconds > LineManager.Config.IOSingle_TimerOut)
{
//把IO重置位0
LogUtil.error(moveInfo.Name + " : " + wait.IoType + "=" + wait.IoValue + " 已等待" + Math.Abs(span.TotalMilliseconds) + ",将DO写0", 17);
ConfigIO io = Config.getWaitIO(wait.IoType);
WarnMsg = Name + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时";
Alarm(LineAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(MoveInfo.Name + " : " + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 13);
foreach (WaitResultInfo ww in list)
{
if (ww != null && ww.WaitType.Equals(2))
{
if (Config.DOList.ContainsKey(ww.IoType))
{
IOMove(wait.IoType, IO_VALUE.LOW);
}
}
}
}
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(3))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
if (wait.IsEnd && moveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
else if (!moveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
if (isOk)
{
moveInfo.EndStepWait();
}
else if (span.TotalSeconds > moveInfo.TimeOutSeconds)
{
WarnMsg = moveInfo.Name + "【" + moveInfo.MoveType + "】【" + moveInfo.MoveStep + "】等待[" + NotOkMsg
+ "]超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, 18);
Alarm(LineAlarmType.IoSingleTimeOut, "", WarnMsg, moveInfo.MoveType);
}
}
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public abstract class EquipBase : KTK_Store
{
private bool IsIntSlvBlock = false;
public bool IsDebug = false;
public AxisAlarmInfo AxisAlarm = new AxisAlarmInfo();
public bool UseAxis = false;
#region 上下气缸伺服运动
protected string portName;
protected short slvAddr;
public bool RunAxis(bool isCheck,ConfigMoveAxis axis)
{
if (!UseAxis)
{
return true;
}
IOMove(IO_Type.BatchAxis_ServoOn, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
ACServerManager.OpenPort(portName);
Thread.Sleep(50);
//初始化
if (!IsIntSlvBlock)
{
ACServerManager.InitSlvAddr(portName, slvAddr, axis.TargetSpeed, axis.AddSpeed, axis.DelSpeed);
Thread.Sleep(100);
}
ACServerManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
ACServerManager.ServoOn(portName, slvAddr);
Thread.Sleep(1000);
//打开所有轴
if (isCheck)
{
if (!OpenAxis(axis))
{
return false;
}
}
IsIntSlvBlock = true;
IOMove(IO_Type.BatchAxis_BreakOn, IO_VALUE.HIGH);
return true;
}
protected void IOMove(object batchAxis_ServoOn, IO_VALUE hIGH)
{
throw new NotImplementedException();
}
/// <summary>
/// 打开所有轴
/// </summary>
/// <returns></returns>
protected bool OpenAxis(ConfigMoveAxis axis)
{
//判断轴是否正常
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info(Name + "成功打开轴:" + axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogUtil.info(Name + "第一次打开轴" + axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(portName, slvAddr);
System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(portName, slvAddr);
System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info(Name + "清理报警后重新打卡轴成功:" + axis.Explain);
}
else
{
ACServerManager.ServoOff(portName, slvAddr);
WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
LogUtil.info(Name + WarnMsg);
Alarm(LineAlarmType.AxisAlarm, 5.ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
return true;
}
public void CloseAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(IO_Type.BatchAxis_BreakOn, IO_VALUE.LOW);
ACServerManager.ServoOff(portName, slvAddr);
//关闭串口,等下次重新打开
ACServerManager.ColsePort(portName);
Thread.Sleep(100);
IOMove(IO_Type.BatchAxis_ServoOn, IO_VALUE.LOW);
}
protected void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.info(moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
/// <summary>
/// 松下伺服电机运动
/// </summary>
protected void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
protected bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue();
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error(moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
+ "],误差过大,需要报警";
LogUtil.error(msg);
}
}
return false;
}
protected bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
{
msg = "";
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
{
//原点完成并且位置=0
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error(moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
//LogUtil.error( StoreName + moveAxis.DisplayStr + "重新回原点");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error(msg);
}
}
return false;
}
#endregion
#region CheckWait处理
/// <summary>
/// 上一个盘号
/// </summary>
public int preTrayNum = 0;
/// <summary>
/// 当前正在通过的托盘号
/// </summary>
protected int currMoveTrayNum = 0;
protected DateTime preRWTime = DateTime.Now;
protected void CheckWait(LineMoveInfo moveInfo)
{
List<WaitResultInfo> list = moveInfo.WaitList;
if (list.Count <= 0)
{
moveInfo.EndStepWait();
return;
}
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - moveInfo.LastSetpTime;
string NotOkMsg = "";
bool isOk = true;
if (moveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(1))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(LineAlarmType.AxisMoveError, 5.ToString(), WarnMsg, moveInfo.MoveType);
break;
}
}
else if (wait.WaitType.Equals(2))
{
NotOkMsg = " (" + baseConfig.GetDisplayName(wait.IoType) + "=" + wait.IoValue + ") ";
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
//屏蔽料盘检测信号
if (wait.IoType.Equals(IO_Type.TrayCheck) && wait.IoValue.Equals(IO_VALUE.HIGH) && LineManager.Config.IsUse_Tray_Check.Equals(0))
{
LogUtil.debug(moveInfo.Name + "未检测到:IsUse_Tray_Check= " + wait.IoValue + ",直接跳过检测继续下一步");
}
//夹紧按钮若果超过一秒钟还未收到,默认成功
else if (wait.IoType.Equals(IO_Type.ClampCylinder_Slack) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 4000)
{
LogInfo("未检测到:ClampCylinder_Slack=HIGH,超过4秒钟,默认下一步骤");
wait.IsEnd = true;
}
else
{
TimeSpan rwSpan = DateTime.Now - preRWTime;
//一分钟还未检测到
if (span.TotalMilliseconds > LineManager.Config.IOSingle_TimerOut)
{
ConfigIO io = baseConfig.getWaitIO(wait.IoType);
WarnMsg = Name + "等待" + NotOkMsg + " 超时";
Alarm(LineAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(MoveInfo.Name + WarnMsg, 13);
}
else if (rwSpan.TotalSeconds > 3 && span.TotalSeconds > 3)
{
preRWTime = DateTime.Now;
string msg = moveInfo.Name + " " + NotOkMsg + "已等待 " + Math.Abs(span.TotalSeconds) + "秒,重写DO:";
bool isLog = false;
foreach (WaitResultInfo ww in list)
{
if (ww != null && ww.WaitType.Equals(2) && baseConfig.DOList.ContainsKey(ww.IoType))
{
isLog = true;
IOMove(ww.IoType, ww.IoValue);
msg += ww.ToStr() + ",";
}
}
if (isLog)
{
LogUtil.error(msg);
}
}
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(3))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(8))
{
string posId = moveInfo.MoveParam.PosId;
int id = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.RightInPosId(id, posId);
}
else if (wait.WaitType.Equals(9))
{
int storeId = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.BoxCanReviceTray(storeId);
}
else if (wait.WaitType.Equals(10))
{
wait.IsEnd = LineManager.Line.SideWay34HasTray().Equals(false);
}
if (wait.IsEnd && moveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
else if (!moveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
if (isOk)
{
moveInfo.EndStepWait();
}
else if (span.TotalSeconds > moveInfo.TimeOutSeconds)
{
WarnMsg = moveInfo.Name + "[" + moveInfo.MoveType + "][" + moveInfo.MoveStep + "]等待[" + NotOkMsg
+ "]超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, 18);
Alarm(LineAlarmType.IoSingleTimeOut, "", WarnMsg, moveInfo.MoveType);
}
}
#endregion
public override void Alarm(LineAlarmType alarmType, string alarmDetial, string alarmMsg, LineMoveType storeMoveType)
{
if (this.alarmType.Equals(alarmType))
{
return;
}
this.alarmType = alarmType;
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!