Commit 09f0b0cf LN

界面修改:DO列表无内容。点动选择速度无效果。

出入库时:托架必须在后退端
出入库时:增加料架信号检测验证(可勾选)
回原点时:前后轴和升降轴不能同时运动。先回升降轴,再回前后轴
1 个父辈 60c16229
......@@ -30,7 +30,8 @@
<!--温控器类型,0=壁挂王字壳温湿度变送器,1=妙昕温湿度记录仪-->
<add key="HumitureControllerType" value="0" />
<add key="UseAIOBOX" value="1" />
<!--是否启用物料检测信号-->
<add key ="UseTrayCheck" value ="0"/>
<!--是否调试状态-->
<add key="IsInDebug" value="1" />
</appSettings>
......
......@@ -406,14 +406,13 @@
// cmbWriteIO
//
this.cmbWriteIO.DisplayMember = "ProName";
this.cmbWriteIO.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
this.cmbWriteIO.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbWriteIO.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbWriteIO.FormattingEnabled = true;
this.cmbWriteIO.ItemHeight = 22;
this.cmbWriteIO.ItemHeight = 17;
this.cmbWriteIO.Location = new System.Drawing.Point(17, 25);
this.cmbWriteIO.Name = "cmbWriteIO";
this.cmbWriteIO.Size = new System.Drawing.Size(358, 28);
this.cmbWriteIO.Size = new System.Drawing.Size(358, 25);
this.cmbWriteIO.TabIndex = 234;
this.cmbWriteIO.ValueMember = "ProName";
this.cmbWriteIO.SelectedIndexChanged += new System.EventHandler(this.cmbWriteIO_SelectedIndexChanged_1);
......
......@@ -170,6 +170,7 @@
this.button4 = new System.Windows.Forms.Button();
this.btnClearL = new System.Windows.Forms.Button();
this.btnLogDebug = new System.Windows.Forms.Button();
this.chbUseTrayCheck = new System.Windows.Forms.CheckBox();
this.groupAxis.SuspendLayout();
this.groupBox1.SuspendLayout();
this.groupInout.SuspendLayout();
......@@ -1624,7 +1625,7 @@
this.chbDebug.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.chbDebug.AutoSize = true;
this.chbDebug.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbDebug.Location = new System.Drawing.Point(808, 12);
this.chbDebug.Location = new System.Drawing.Point(845, 12);
this.chbDebug.Name = "chbDebug";
this.chbDebug.Size = new System.Drawing.Size(84, 24);
this.chbDebug.TabIndex = 271;
......@@ -1863,6 +1864,7 @@
//
// tabPage4
//
this.tabPage4.Controls.Add(this.chbUseTrayCheck);
this.tabPage4.Controls.Add(this.btnStoreExit);
this.tabPage4.Controls.Add(this.chbDebug);
this.tabPage4.Controls.Add(this.btnStoreHome);
......@@ -2074,6 +2076,19 @@
this.btnLogDebug.UseVisualStyleBackColor = true;
this.btnLogDebug.Click += new System.EventHandler(this.开启DEBUGToolStripMenuItem_Click);
//
// chbUseTrayCheck
//
this.chbUseTrayCheck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.chbUseTrayCheck.AutoSize = true;
this.chbUseTrayCheck.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbUseTrayCheck.Location = new System.Drawing.Point(699, 12);
this.chbUseTrayCheck.Name = "chbUseTrayCheck";
this.chbUseTrayCheck.Size = new System.Drawing.Size(112, 24);
this.chbUseTrayCheck.TabIndex = 272;
this.chbUseTrayCheck.Text = "启用物料检测";
this.chbUseTrayCheck.UseVisualStyleBackColor = true;
this.chbUseTrayCheck.CheckedChanged += new System.EventHandler(this.chbUseTrayCheck_CheckedChanged);
//
// FrmStoreBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
......@@ -2265,6 +2280,7 @@
private System.Windows.Forms.Button btnOpenRDoor;
private System.Windows.Forms.Button btnOpenLDoor;
private System.Windows.Forms.ComboBox cmbHumpPort;
private System.Windows.Forms.CheckBox chbUseTrayCheck;
}
}
......@@ -60,6 +60,7 @@ namespace OnlineStore.ACSquareStore
{
cmbHumpPort.SelectedIndex = 0;
}
chbUseTrayCheck.Checked = StoreManager.UseShelfCheck;
// txtTempPort.Text = store.Config.Humiture_Port;
LoadOk = true;
......@@ -1289,5 +1290,20 @@ namespace OnlineStore.ACSquareStore
BtnMove(btnOpenRDoor, "右侧门锁-打开", "右侧门锁-关闭", IO_Type.RightDoor_Close);
}
private void chbUseTrayCheck_CheckedChanged(object sender, EventArgs e)
{
if (!LoadOk)
{
return;
}
if (chbUseTrayCheck.Checked.Equals(StoreManager.UseShelfCheck))
{
return;
}
StoreManager.UseShelfCheck = chbUseTrayCheck.Checked;
ConfigAppSettings.SaveValue(Setting_Init.UseTrayCheck, chbUseTrayCheck.Checked ? 1 : 0);
LogUtil.info("点击:启用物料检测 = " + chbUseTrayCheck.Checked);
}
}
}
......@@ -31,9 +31,9 @@
新建分支ACSquareStore,做为方仓项目。
方仓三个轴:
伺服X轴 1 前原点后正限
伺服Z轴 2 下原点上正限
伺服Y轴 3 中间原点前正限后负限
伺服X轴 -前后轴 1 前原点后正限
伺服Z轴-升降轴 2 下原点上正限
伺服Y轴-进出轴 3 中间原点前正限后负限
三个温湿度:
温湿度1 单接com2
温湿度2 单接com3
......@@ -41,3 +41,17 @@
20200320
轴名称修改:X轴-前后轴,Y轴-进出轴。
需需修改?
回原点时:前后轴和升降轴不能同时运动。先回升降轴,再回前后轴
出入库时:托架必须在后退端
出入库时:增加料架信号检测验证(可勾选)
界面修改:DO列表无内容。点动选择速度无效果。
需要增加电池?伺服回好原点之后不需要每次回原点。
20200325修改:
界面修改:DO列表无内容。点动选择速度无效果。
出入库时:托架必须在后退端
出入库时:增加料架信号检测验证(可勾选)
回原点时:前后轴和升降轴不能同时运动。先回升降轴,再回前后轴
......@@ -91,5 +91,8 @@ namespace OnlineStore.Common
public static string Tool_TargetSpeed= "Tool_TargetSpeed";
public static string Tool_TargetPosition= "Tool_TargetPosition";
public static string UseTrayCheck = "UseTrayCheck";
}
}
......@@ -14,7 +14,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
public partial class ACServerManager
{
public static bool IsShowMsg = false ;
public static bool IsShowMsg = false;
private static int SleepMSendons = 20;
private static int ReviceOutTimeMS = 100;
private static Dictionary<string, Dictionary<string, int>> ComAddrValue = new Dictionary<string, Dictionary<string, int>>();
......@@ -146,15 +146,15 @@ namespace OnlineStore.DeviceLibrary
{
if (!serialBeanMap.ContainsKey(portName))
{
return false ;
return false;
}
PreReadCoilAddr = ACCMDManager.ServerOn_Addr;
byte[] dataArray = ACCMDManager.GetWriteData(slvAddr, ACCMDManager.CMD_ReadCoil, PreReadCoilAddr, "0000", 1);
//SendData(portName,dataArray);
byte[] reviceData = SendCommand(portName, dataArray, ReviceOutTimeMS, 6);
int result= GetCoilData(portName, reviceData, PreReadCoilAddr);
int result = GetCoilData(portName, reviceData, PreReadCoilAddr);
//TODO
return result>=1;
return result >= 1;
}
/// <summary>
/// 是否原点返回完成
......@@ -162,23 +162,25 @@ namespace OnlineStore.DeviceLibrary
public static bool IsHomeMoveEnd(string portName, int slvAddr)
{
int status = GetHomeEndStatus(portName, slvAddr);
if (status >= 1)
bool isOk = ACServerManager.GetBusyStatus(portName, slvAddr).Equals(0);
if (status >= 1 && isOk)
{
return true;
} return false;
}
return false;
}
public static void InitSlvAddr(string portName, int slvAddr)
{
InitSlvAddr(portName, slvAddr, 100, 30, 30 );
InitSlvAddr(portName, slvAddr, 100, 30, 30);
//InitSlvAddr(portName, slvAddr, 100, 30, 30, 100, 50, 30);
}
//把数字转换为四位的字符串
public static string SpeedToStr(int speed,int length)
public static string SpeedToStr(int speed, int length)
{
string str = String.Format("{0:X}", speed);
return str.PadLeft(length, '0');
}
public static void InitSlvAddr(string portName, int slvAddr,int targetSpeed,int addSpeed,int delSpeed )
public static void InitSlvAddr(string portName, int slvAddr, int targetSpeed, int addSpeed, int delSpeed)
//public static void InitSlvAddr(string portName, int slvAddr,int targetSpeed,int addSpeed,int delSpeed,int homeHighSpeed,int homeLowSpeed,int homeAddSpeed)
{
LogUtil.info("开始初始化伺服【" + portName + "】【" + slvAddr + "】");
......@@ -259,12 +261,12 @@ namespace OnlineStore.DeviceLibrary
SendData(portName, dataArray);
}
public static void RelMove(string portName, int slvAddr, int position,int targetSpeed)
public static void RelMove(string portName, int slvAddr, int position, int targetSpeed)
{
//先更新速度
string slvAddrStr = string.Format(strFromat, slvAddr);
string v1 = slvAddrStr + "064601 " + SpeedToStr(targetSpeed, 4) + " ffff";
SendStrAndSleep(portName, v1,SleepMSendons);
SendStrAndSleep(portName, v1, SleepMSendons);
RelMove(portName, slvAddr, position);
}
......@@ -324,7 +326,7 @@ namespace OnlineStore.DeviceLibrary
if (isHomeEnd.Equals(1))
{
int value = 2000;
LogUtil.info("轴【" + portName +"_"+slvAddr +"】原点返回时发现原点已亮且回过原点,需要先相对走" + value);
LogUtil.info("轴【" + portName + "_" + slvAddr + "】原点返回时发现原点已亮且回过原点,需要先相对走" + value);
RelMove(portName, slvAddr, value);
bool isStop = false;
for (int i = 0; i <= 10; i++)
......@@ -345,9 +347,9 @@ namespace OnlineStore.DeviceLibrary
}
else
{
int volSpeed =Math.Abs( speed / 5);
int volSpeed = Math.Abs(speed / 5);
int time = 1500;
LogUtil.info("轴【" + portName + "_" + slvAddr + "】原点返回时发现原点已亮但未回过原点,先匀速向上走"+time+",速度["+ volSpeed + "]" );
LogUtil.info("轴【" + portName + "_" + slvAddr + "】原点返回时发现原点已亮但未回过原点,先匀速向上走" + time + ",速度[" + volSpeed + "]");
//需要匀速向上走
ACServerManager.SpeedMove(portName, slvAddr, volSpeed);
......@@ -357,7 +359,7 @@ namespace OnlineStore.DeviceLibrary
Thread.Sleep(100);
}
}
}catch(Exception ex)
}catch (Exception ex)
{
LogUtil.error("轴【" + portName + "_" + slvAddr + "】原点返回前验证是否在原点出错:" + ex.StackTrace);
}
......@@ -368,8 +370,9 @@ namespace OnlineStore.DeviceLibrary
}
public static void SetSpeed(string portName, int slvAddr, int speed)
{
speed = Math.Abs(speed);
int preSpeed = GetAddrValue(portName, slvAddr, ACCMDManager.Speed_Addr);
if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(Math.Abs(speed))))
if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(speed)))
{
string v1 = slvAddr + "064601 " + ACServerManager.SpeedToStr(speed, 4) + " ffff";
LogUtil.debug("轴【" + portName + "_" + slvAddr + "】更新速度为【" + speed + "】,发送数据【" + v1 + "】");
......@@ -387,7 +390,7 @@ namespace OnlineStore.DeviceLibrary
Thread.Sleep(SleepMSendons);
}
}
UpdateAddrValue(portName, slvAddr, ACCMDManager.Speed_Addr, Math.Abs(speed));
UpdateAddrValue(portName, slvAddr, ACCMDManager.Speed_Addr, speed);
Thread.Sleep(SleepMSendons);
}
}
......@@ -425,13 +428,13 @@ namespace OnlineStore.DeviceLibrary
//先更新速度
string slvAddrStr = string.Format(strFromat, slvAddr);
int preSpeed = GetAddrValue(portName,slvAddr, ACCMDManager.Speed_Addr);
int preSpeed = GetAddrValue(portName, slvAddr, ACCMDManager.Speed_Addr);
if ((preSpeed.Equals(-1)) || (!preSpeed.Equals(targetSpeed)))
{
//速度 V1 =100
string v1 = slvAddrStr + "064601 " + SpeedToStr(targetSpeed, 4) + " ffff";
SendStrAndSleep(portName, v1, SleepMSendons);
UpdateAddrValue(portName,slvAddr, ACCMDManager.Speed_Addr, targetSpeed);
UpdateAddrValue(portName, slvAddr, ACCMDManager.Speed_Addr, targetSpeed);
}
//绝对运动
AbsMove(portName, slvAddr, targetPosition);
......@@ -484,3 +487,4 @@ namespace OnlineStore.DeviceLibrary
}
}
}
......@@ -209,7 +209,7 @@ namespace OnlineStore.DeviceLibrary
storeRunStatus = StoreRunStatus.HomeMoving;
StoreMove.NewMove(StoreMoveType.ReturnHome);
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
StoreMove.NextMoveStep(StoreMoveStep.SH_12_InOutBack);
ACAxisHomeMove(Config.InOut_Axis);
LogUtil.info(LOGGER, StoreName + "开始原点返回,先把进出轴回原点");
......@@ -217,14 +217,11 @@ namespace OnlineStore.DeviceLibrary
}
public void MoveToP1()
{
//压紧轴回原点,叉子回到P1,关闭门前后轴和升降轴回到P1
//叉子回到P1,关闭门前后轴和升降轴回到P1
StoreMove.NewMove(StoreMoveType.StoreReset);
StoreMove.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_InOutToP1);
LogUtil.info(LOGGER, StoreName + "到待机状态,进出轴到P1,判断叉子没有料盘");
StoreMove.NextMoveStep(StoreMoveStep.SP1_01_InOutToP1);
LogUtil.info(LOGGER, StoreName + "到待机状态,进出轴到P1");
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
//ComBeforeHomeMove();
//判断叉子没有料盘
//StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
}
public override void Reset(bool isNeedClearAuto = true)
......@@ -274,7 +271,7 @@ namespace OnlineStore.DeviceLibrary
LeftShlefMove.Stop();
RightShelfMove.Stop();
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
StoreMove.NextMoveStep(StoreMoveStep.SH_12_InOutBack);
LogUtil.info(LOGGER, StoreName + "复位中,进出轴开始原点返回");
ACAxisHomeMove(Config.InOut_Axis);
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
......@@ -299,26 +296,26 @@ namespace OnlineStore.DeviceLibrary
}
switch (StoreMove.MoveStep)
{
case StoreMoveStep.BOX_H_LocationCylinderBack:
case StoreMoveStep.SH_10_LocationCylinderBack:
InoutStartReset();
break;
case StoreMoveStep.BOX_H_InOutMove:
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
case StoreMoveStep.SH_11_InOutMove:
StoreMove.NextMoveStep(StoreMoveStep.SH_12_InOutBack);
ACAxisHomeMove(Config.InOut_Axis);
LogUtil.info(LOGGER, StoreName + logName+ " 进出轴开始原点返回");
LogUtil.info(LOGGER, StoreName + logName + " 进出轴开始原点返回");
StoreMove.WaitList.Add(WaitResultInfo.WaitTime(2000));
break;
case StoreMoveStep.BOX_H_InOutBack:
case StoreMoveStep.SH_12_InOutBack:
Thread.Sleep(200);
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_InOutToP1);
StoreMove.NextMoveStep(StoreMoveStep.SH_13_InOutToP1);
LogUtil.info(LOGGER, StoreName + logName + " 进出轴到待机点P1,关闭左右两侧门");
//进出轴原点返回完成,将进出轴的位置设置=0
AxisCountClear(Config.InOut_Axis);
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
CloseDoor(1,StoreMove);
CloseDoor(2,StoreMove);
CloseDoor(1, StoreMove);
CloseDoor(2, StoreMove);
break;
case StoreMoveStep.BOX_H_InOutToP1:
case StoreMoveStep.SH_13_InOutToP1:
//如果此时轴三还在报警,需要提示错误并等待
if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{
......@@ -326,23 +323,28 @@ namespace OnlineStore.DeviceLibrary
}
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
LogUtil.info(LOGGER, StoreName + logName + " 压紧轴,前后轴,升降轴开始 原点返回 ,左右托盘前进");
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack);
LogUtil.info(LOGGER, StoreName + logName + " 前后轴,升降轴开始 原点返回 ,左右托盘前进");
StoreMove.NextMoveStep(StoreMoveStep.SH_14_UpdownBack);
StoreMove.TimeOutSeconds = 100;
ACAxisHomeMove(Config.Middle_Axis);
ACAxisHomeMove(Config.UpDown_Axis);
ShelfForward(1);
ShelfForward(2);
break;
case StoreMoveStep.BOX_H_OtherAxisBack:
case StoreMoveStep.SH_14_UpdownBack:
StoreMove.NextMoveStep(StoreMoveStep.SH_15_MiddleBack);
StoreMove.TimeOutSeconds = 100;
ACAxisHomeMove(Config.Middle_Axis);
break;
case StoreMoveStep.SH_15_MiddleBack:
StoreMove.NextMoveStep(StoreMoveStep.BOX_H_MiddleAxisToP1);
LogUtil.info(LOGGER, StoreName + logName + " 前后轴运动到P1,升降轴走到P1,压紧轴到P1!");
StoreMove.NextMoveStep(StoreMoveStep.SH_16_OtherAxisToP1);
LogUtil.info(LOGGER, StoreName + logName + " 前后轴运动到P1,升降轴走到P1,托架前进到位");
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorO_P1, Config.UpDownAxis_P1_Speed);
ShelfForward(1, StoreMove);
ShelfForward(2, StoreMove);
break;
case StoreMoveStep.BOX_H_MiddleAxisToP1:
case StoreMoveStep.SH_16_OtherAxisToP1:
LogUtil.info(LOGGER, StoreName + "复位完成");
storeRunStatus = StoreRunStatus.Runing;
StoreMove.EndMove();
......@@ -353,21 +355,26 @@ namespace OnlineStore.DeviceLibrary
}
break;
case StoreMoveStep.BOX_M_H_TOP1_InOutToP1:
StoreMove.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_CompressHome);
LogUtil.info(LOGGER, StoreName + "到待机状态,压紧轴回原点,关闭左右两侧门");
case StoreMoveStep.SP1_01_InOutToP1:
StoreMove.NextMoveStep(StoreMoveStep.SP1_02_CloseDoor);
LogUtil.info(LOGGER, StoreName + "到待机状态,关闭左右两侧门,托架前进");
CloseDoor(1, StoreMove);
CloseDoor(2, StoreMove);
break;
case StoreMoveStep.BOX_M_H_TOP1_CompressHome:
StoreMove.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1);
LogUtil.info(LOGGER, StoreName + "到待机状态:前后轴运动到P1,升降轴走到P1,压紧轴到P1,左右托架前进");
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
case StoreMoveStep.SP1_02_CloseDoor:
StoreMove.NextMoveStep(StoreMoveStep.SP1_03_OtherAxisToP1);
LogUtil.info(LOGGER, StoreName + "到待机状态:升降轴走到P1,前后轴到P1");
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorO_P1, Config.UpDownAxis_P1_Speed);
ShelfForward(1);
ShelfForward(2);
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
break;
case StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1:
case StoreMoveStep.SP1_03_OtherAxisToP1:
StoreMove.NextMoveStep(StoreMoveStep.SP1_04_ShelfForward);
LogUtil.info(LOGGER, StoreName + "到待机状态:托架前进");
ShelfForward(1, StoreMove);
ShelfForward(2, StoreMove);
break;
case StoreMoveStep.SP1_04_ShelfForward:
LogUtil.info(LOGGER, StoreName + "到待机状态完成");
StoreMove.EndMove();
storeStatus = StoreStatus.StoreOnline;
......@@ -376,6 +383,7 @@ namespace OnlineStore.DeviceLibrary
{
WarnMsg = "";
}
break;
default: break;
......@@ -1441,8 +1449,8 @@ namespace OnlineStore.DeviceLibrary
{
if (storeRunStatus.Equals(StoreRunStatus.Runing) && IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
boxStatus.msg = "叉子料盘检测有料,请检查";
lineOperation.msg = "叉子料盘检测有料,请检查";
boxStatus.msg = "货叉物料检测有料,请检查";
lineOperation.msg = "货叉物料检测有料,请检查";
}
}
CodeMsg = "";
......
......@@ -23,6 +23,8 @@ namespace OnlineStore.DeviceLibrary
public static Box_Config Config = null;
private static bool isInit = false;
public static bool IsConnectServer = !ConfigAppSettings.GetValue(Setting_Init.http_server).Equals("");
public static bool UseShelfCheck = ConfigAppSettings.GetIntValue(Setting_Init.UseTrayCheck).Equals(1);
public StoreManager()
{
}
......
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class LineConnect
{
private static int ClientKeepSecond = 10;
private static TcpClient client = null;
public static List<string> WaitInStoreList = new List<string>();
public static void StartConnect()
{
Task.Factory.StartNew(delegate
{
string lineServer = ConfigAppSettings.GetValue(Setting_Init.LineServerIp);
int linePort = ConfigAppSettings.GetIntValue(Setting_Init.LineServerPort);
if (lineServer.Equals(""))
{
LogUtil.error("未配置流水线地址,不需要连接");
return;
}
client = new TcpClient();
bool result = client.StartConnect(lineServer, linePort, HandlerMsg, 2000);
});
}
public static void StopConnect()
{
if (client != null)
{
client.close();
}
}
private static int seq = 1;
public static int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
{
LogUtil.info("seq当前值:" + seq + ",重置seq=0");
seq = 0;
}
Interlocked.Increment(ref seq);
return seq;
}
public static void SendHeart(StoreSendBean store)
{
if (client == null)
{
return;
}
try
{
store.Cmd = cmd_heart;
string heartMsg = ToParamStr(store);
client.send(heartMsg);
} catch (Exception ex)
{
LogUtil.error("SendHeart 出错:" + ex.ToString());
}
}
private static DateTime LastOutStoreEndTime = DateTime.Now;
public static void OutStoreEnd(StoreSendBean store)
{
if (client == null)
{
return;
}
try
{
LastOutStoreEndTime = DateTime.Now;
store.Cmd = cmd_outend;
string msg = ToParamStr(store);
LogUtil.info("OutStoreEnd:" + msg);
client.send(msg);
}
catch (Exception ex)
{
LogUtil.error("OutStoreEnd 出错:" + ex.ToString());
}
}
private static string ToParamStr(StoreSendBean store)
{
return JsonHelper.SerializeObject(store)+"\r";
}
private static void HandlerMsg(string message)
{
try
{
message = message.Replace("\r", "");
StoreReviceBean reviceInfo = JsonHelper.DeserializeJsonToObject<StoreReviceBean>(message);
//string[] msgArray = message.Split(cmd_spilt);
if (reviceInfo == null)
{
LogUtil.debug("收到消息:" + message + ",解析失败");
}
else
{
string cmd = reviceInfo.Cmd;
CanOutStore = reviceInfo.CanOutStore.Equals(1);
LastUpdateTime = DateTime.Now;
if (cmd.Equals(cmd_startIn))
{
LogUtil.info("收到流水线入库消息:" + message);
StoreManager.Store.ReviceLineInStoreCMD(reviceInfo.PosId, reviceInfo.PlateH, reviceInfo.PlateW, reviceInfo.WareCode);
}
else if (cmd.Equals(cmd_updateDebug))
{
int isDebug = reviceInfo.IsDebug;
LogUtil.info("收到流水线更改调试状态=" + isDebug);
StoreManager.Store.IsDebug = isDebug.Equals(1) ? true : false;
ConfigAppSettings.SaveValue(Setting_Init.IsInDebug, isDebug);
LogUtil.info("切换调试状态= " + isDebug + ";");
}
else if (cmd.Equals(cmd_checStartIn))
{
LogUtil.info("收到流水线入库库位验证消息:" + message);
//if (LineConnect.WaitInStoreList.Contains(reviceInfo.PosId))
//{
// LogUtil.error(" LineConnect.WaitInStoreList已存在库位【" + reviceInfo.PosId + "】先移除在验证");
// LineConnect.WaitInStoreList.Remove(reviceInfo.PosId);
//}
bool result = StoreManager.Store.ReviceLineCheckInStoreCMD(reviceInfo.PosId, reviceInfo.PlateH, reviceInfo.PlateW, reviceInfo.WareCode);
if (result && (!WaitInStoreList.Contains(reviceInfo.PosId)))
{
LineConnect.WaitInStoreList.Add(reviceInfo.PosId);
}
}
}
}
catch (Exception ex)
{
LogUtil.error("处理流水线消息【"+ message +"】出错:" +ex.ToString() );
}
}
public static char cmd_spilt = ';';
public static string cmd_heart = "heart";
private static string cmd_outend = "outend";
private static string cmd_startIn = "starIn";
private static string cmd_updateDebug = "updateDebug";
private static bool CanOutStore = false;
public static DateTime LastUpdateTime = new DateTime(0);
public static string cmd_checStartIn = "cmd_checStartIn";
public static bool IsConnect()
{
if (client == null)
{
return false;
}
if (client.IsRun()&& client.IsConnected())
{
return true;
}
return false ;
}
public static bool CanStartOut()
{
TimeSpan span = DateTime.Now - LastUpdateTime;
if (span.TotalSeconds < ClientKeepSecond && CanOutStore)
{
return true;
}
return false;
}
/// <summary>
/// 是否可以重发消息
/// </summary>
/// <returns></returns>
public static bool CanReSend()
{
TimeSpan span = DateTime.Now - LastOutStoreEndTime;
if (span.TotalSeconds > 8)
{
return true;
}
return false;
}
}
public class StoreReviceBean
{
public string Cmd = "";
public int CanOutStore = 0;
public string PosId = "";
public string PlateH = "0";
public string PlateW = "0";
public string WareCode = "";
public int IsDebug = 0;
}
public class StoreSendBean
{
public StoreSendBean(int id, string cid, int ss, int runs, int doorHasTray, int alarmType)
{
this.StoreId = id;
this.Cid = cid;
this.SStatus = ss;
this.SRunStatus = runs;
this.DoorHasTray = doorHasTray;
this.AlarmType = alarmType;
this.Seq = LineConnect.nextSeq();
this.WaitInStoreList = new List<string>(LineConnect.WaitInStoreList);
this.data = new Dictionary<string, string>();
// WaitInStoreList.Add("1#AC1_1_1");
}
public string Cmd =LineConnect. cmd_heart;
public int StoreId = 0;
public string Cid = "";
public int Seq = 0;
public int SStatus = 0;
public int SRunStatus = 0;
public int DoorHasTray = 0;
public int AlarmType = 0;
public List<string> WaitInStoreList = new List<string>();
public Dictionary<string, string> data = new Dictionary<string, string>();
//public string PosId = "";
//public string PlateH = "0";
//public string PlateW = "0";
///// <summary>
///// urgentReel: true 表示紧急料,需要出到料串上
///// </summary>
//public bool urgentReel = false;
///// <summary>
///// cutReel: true 表示分盘料,需要出到料串上
///// </summary>
//public bool cutReel = false;
///// <summary>
///// smallReel: true 小料(7x8),放置到小料架上
///// </summary>
//public bool smallReel = false;
///// <summary>
///// rfid: 分配的料架RFID
///// </summary>
//public string rfid = "";
///// <summary>
///// rfidLoc: 料架的架位,值为 - 1时,可以自由分配皮带线,
///// 小料时,架位为1 - 46优先走1 / 2号皮带线,47 - 92优先走3 / 4号皮带线,
///// 70,71,72时只能分配到3 / 4号皮带线;
///// 大料时,架位1 - 6优先走1 / 2号皮带线, 7 - 12优先走3/ 4号皮带线
///// </summary>
//public int rfidLoc = 0;
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!