Commit 5c460336 几米阳光

1.测高AI模块BUG修改。

2.出库增加缓存功能,若出库失败也放入缓存。
1 个父辈 edfa6340
......@@ -48,7 +48,7 @@ namespace OnlineStore.ACSingleStore
txtMiddleSpeed.Text = (middle.TargetSpeed / 5).ToString();
txtInOutSpeed.Text = (inout.TargetSpeed / 5).ToString();
txtUpDownSpeed.Text = (updown.TargetSpeed / 5).ToString();
txtComSpeed.Text = (StoreManager.Config.CompressAxis_EndSpeed/5).ToString();
txtComSpeed.Text = (StoreManager.Config.CompressAxis_EndSpeed).ToString();
timer1.Start();
}
/// <summary>
......
......@@ -54,6 +54,9 @@
1.出库叉子退回后增加出库完成的状态。
2.门口是否有料的信号发送给服务器。
20190312
1.测高AI模块BUG修改。
2.出库增加缓存功能,若出库失败也放入缓存。
......
......@@ -67,7 +67,10 @@ namespace OnlineStore.Common
/// </summary>
public static void Release()
{
sb.closePort();
if (sb != null)
{
sb.closePort();
}
IsRun = false;
}
public static ASTemperateParam LastData = new ASTemperateParam(0, 0);
......
......@@ -12,7 +12,7 @@ using OnlineStore.Common;
namespace OnlineStore.DeviceLibrary
{
public class AITcpClient
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
......@@ -69,7 +69,7 @@ namespace OnlineStore.DeviceLibrary
// ------------------------------------------------------------------------
/// <summary>Response data event. This event is called when new data arrives</summary>
public delegate void ResponseData(string ip, ushort id, byte function, byte[] data,byte[] reviceData);
public delegate void ResponseData(string ip, ushort id, byte function, byte[] data, byte[] reviceData);
/// <summary>Response data event. This event is called when new data arrives</summary>
public event ResponseData OnResponseData;
/// <summary>Exception data event. This event is called when the data is incorrect</summary>
......@@ -83,25 +83,25 @@ namespace OnlineStore.DeviceLibrary
public bool autoConnectOfBreak
{
get { return _autoConnectOfBreak; }
set { _autoConnectOfBreak = value; }
}
set { _autoConnectOfBreak = value; }
}
public static ushort timeout
{
get { return _timeout; }
set { _timeout = value; }
}
public ushort refresh
{
get { return _refresh; }
set { _refresh = value; }
}
public bool connected
{
get { return _connected; }
}
public AITcpClient()
{
}
......@@ -182,21 +182,21 @@ namespace OnlineStore.DeviceLibrary
byte[] _adr = AcSerialBean.StringToByte(address);
data[8] = _adr[0]; // Start address
data[9] = _adr[1]; // Start address
byte[] _length = BitConverter.GetBytes((short)1);
byte[] _length = BitConverter.GetBytes((short)1);
data[10] = _length[0]; // Number of data to read
data[11] = _length[1]; // Number of data to read
WriteAsyncData( data,id);
data[11] = _length[1]; // Number of data to read
WriteAsyncData(data, id);
}
public void ReadAllAI(ushort id, string startAddress, int length, byte slaveId)
{
//0x 000100000006FF0302580010
byte function = 0x03;
byte[] data = CreateData(id, startAddress,(ushort) length, function, slaveId);
byte[] data = CreateData(id, startAddress, (ushort)length, function, slaveId);
WriteAsyncData(data, id);
}
private byte[] CreateData(ushort id, string startAddress, ushort length, byte function, byte SlaveID)
private byte[] CreateData(ushort id, string startAddress, ushort length, byte function, byte SlaveID)
{
byte[] data = new byte[12];
......@@ -207,11 +207,12 @@ namespace OnlineStore.DeviceLibrary
data[6] = SlaveID; // Slave address //必须设置为"1": 2012.04-24 覃发光;
data[7] = function; // Function code
byte[] _adr = AcSerialBean.StringToByte(startAddress);
if (_adr.Length .Equals( 2))
if (_adr.Length.Equals(2))
{
data[8] = _adr[0]; // Start address
data[9] = _adr[1]; // Start address
}else if (_adr.Length.Equals(1))
}
else if (_adr.Length.Equals(1))
{
data[8] = 0x00;
data[9] = _adr[0]; // Start address
......@@ -230,7 +231,7 @@ namespace OnlineStore.DeviceLibrary
{
try
{
ReviceDataProcess();
ReviceDataProcess();
Thread.Sleep(10);
}
catch (Exception ex)
......@@ -241,82 +242,72 @@ namespace OnlineStore.DeviceLibrary
private void ReviceDataProcess()
{
int lengthIndex = 5;
byte[] rdata = Receive();
if (rdata != null)
if (rdata == null)
{
string str = "";
foreach (byte by in rdata)
{
str = str + " " + by;
//if (str.Length > 200)
//{
// break;
//}
}
//这里rdata就是接收到的数据,
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
//ushort id = BitConverter.ToUInt16(rdata, 0);
//byte function = rdata[7];
byte dataLength = rdata[lengthIndex];
return;
}
string str = "";
foreach (byte by in rdata)
{
str = str + " " + by;
}
int allLength = lengthIndex + 1 + dataLength;
if (rdata.Length > allLength)
int lengthIndex = 5;
//这里rdata就是接收到的数据,
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
byte dataLength = rdata[lengthIndex];
int allLength = lengthIndex + 1 + dataLength;
if (rdata.Length <= allLength)
{
LogUtil.debug(LOGGER, clientipe.ToString() + "收到数据(无需分包):" + str);
ushort id = BitConverter.ToUInt16(rdata, 0);
byte function = rdata[7];
DataProcess(clientipe.ToString(), id, function, rdata);
return;
}
int currStartIndex = 0;
try
{
for (int i = 0; i < 100; i++)
{
//LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str);
int currStartIndex = 0;
for (int i = 0; i < 100; i++)
if (rdata.Length < currStartIndex + lengthIndex)
{
try
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]");
break;
}
else
{
dataLength = rdata[currStartIndex + lengthIndex];
allLength = lengthIndex + 1 + dataLength;
byte[] thisData = new byte[allLength];
Array.Copy(rdata, currStartIndex, thisData, 0, allLength);
ushort id = BitConverter.ToUInt16(thisData, 0);
byte function = thisData[7];
DataProcess(clientipe.ToString(), id, function, thisData);
//剩余的数据处理
if (rdata.Length < currStartIndex + lengthIndex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]");
break;
}
else
{
dataLength = rdata[currStartIndex + lengthIndex];
allLength = lengthIndex + 1 + dataLength;
byte[] thisData = new byte[allLength];
Array.Copy(rdata, currStartIndex, thisData, 0, allLength);
ushort id = BitConverter.ToUInt16(thisData, 0);
byte function = thisData[7];
DataProcess(clientipe.ToString(), id, function, thisData);
//剩余的数据处理
if (rdata.Length <= currStartIndex + allLength)
{
break;
}
currStartIndex = currStartIndex + allLength;
}
}
catch (Exception ex)
if (rdata.Length <= currStartIndex + allLength)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString());
break;
}
currStartIndex = currStartIndex + allLength;
}
}
else
{
LogUtil.debug(LOGGER, clientipe.ToString() + "收到数据(无需分包):" + str);
ushort id = BitConverter.ToUInt16(rdata, 0);
byte function = rdata[7];
DataProcess(clientipe.ToString(),id,function,rdata);
}
}
catch (Exception ex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString());
}
}
private void DataProcess(string clientIp, ushort id, byte function, byte[] rdata)
{
byte[] data;
if (rdata.Length <= 9)
{
return;
}
if ((function >= fctWriteSingleCoil) && (function != fctReadWriteMultipleRegister))
{
data = new byte[2];
......@@ -325,7 +316,7 @@ namespace OnlineStore.DeviceLibrary
// ------------------------------------------------------------
// Read response data
else
{
{
data = new byte[rdata[8]];
Array.Copy(rdata, 9, data, 0, rdata[8]);
}
......@@ -340,11 +331,11 @@ namespace OnlineStore.DeviceLibrary
// Response data is regular data
else if (OnResponseData != null)
{ //收到的数据打印出来
OnResponseData(clientIp, id, function, data, rdata);
}
}
private byte[] Receive()
{
try
......@@ -353,10 +344,10 @@ namespace OnlineStore.DeviceLibrary
{
return null;
}
int size = socketClient.Available;
byte[] rData = new byte[size];
socketClient.Receive(rData, size, SocketFlags.None);
byte[] rData = new byte[size];
socketClient.Receive(rData, size, SocketFlags.None);
return rData;
}
......@@ -370,19 +361,19 @@ namespace OnlineStore.DeviceLibrary
return null;
}
}
}
public void disconnect()
{
Dispose();
}
~AITcpClient()
{
Dispose();
}
public void Dispose()
{
reviceTimer.Enabled = false;
......@@ -395,7 +386,7 @@ namespace OnlineStore.DeviceLibrary
socketClient.Close();
}
socketClient = null;
}
}
}
internal void CallException(ushort id, byte function, byte exception, byte[] rdata)
......@@ -417,7 +408,7 @@ namespace OnlineStore.DeviceLibrary
OnException(socketClient.RemoteEndPoint.AddressFamily.ToString(), id, function, exception, rdata);
}
}
public void WriteAsyncData(byte[] write_data, ushort id)
{
try
......@@ -432,14 +423,7 @@ namespace OnlineStore.DeviceLibrary
{
try
{
//发送的数据打印出来
string str = "";
foreach (byte by in write_data)
{
str = str + " " + by;
}
//LogUtil.info( clientipe.ToString()+"发送数据:" + str);
//LogUtil.info( clientipe.ToString()+"发送数据:" + AcSerialBean.byteToHexStr(write_data));
socketClient.BeginSend(write_data, 0, write_data.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
//socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient);
ReviceDataProcess();
......@@ -453,18 +437,18 @@ namespace OnlineStore.DeviceLibrary
}
catch (Exception ex)
{
LOGGER.Error("出错:"+ex.ToString());
LOGGER.Error("出错:" + ex.ToString());
}
}
// ------------------------------------------------------------------------
// Write asynchronous data acknowledge
private void OnSend(System.IAsyncResult result)
{
if (result.IsCompleted == false) CallException(0xFFFF, 0xFF, excSendFailt, tcpSocketReviceBuffer);
}
}
internal bool ISConnection()
{
{
if (socketClient == null)
{
return false;
......
......@@ -68,11 +68,11 @@ namespace OnlineStore.DeviceLibrary
MBmaster.OnException += new AITcpClient.ExceptionData(MBmaster_OnException);
MBmaster.autoConnectOfBreak = false;
mastMap.Add(ioIp, MBmaster);
LogUtil.info(LOGGER, "连接AI模块[" + ioIp + "]成功");
Thread.Sleep(10);
WriteAIScope(ioIp, 1);
Thread.Sleep(10);
ReadAll(ioIp);
LogUtil.info(LOGGER, "连接AI模块[" + ioIp + "]成功");
}
catch (Exception error)
{
......@@ -157,8 +157,8 @@ namespace OnlineStore.DeviceLibrary
Thread.Sleep(2);
isProcess = false;
}
private static void WriteAIScope(string ioIp,int value)
private static void WriteAIScope(string ioIp, int value)
{
// 0 表示 0 - 10V, 1 表示 0 - 5V
WriteAIScope(ioIp, DefualtSlaveID, "03EA", value);
......@@ -202,17 +202,17 @@ namespace OnlineStore.DeviceLibrary
}
mastMap.Clear();
}
public static double ConvertAI(double aiValue,double defaultValue )
public static double ConvertAI(double aiValue, double defaultValue)
{
double xishu =(double) ConfigAppSettings.GetNumValue(Setting_Init.AI_ConvertPosition);
double result= Math.Round((aiValue-defaultValue)/xishu,2);
double xishu = (double)ConfigAppSettings.GetNumValue(Setting_Init.AI_ConvertPosition);
double result = Math.Round((aiValue - defaultValue) / xishu, 2);
return result;
}
public static double GetAIValue(string ioiP, int index)
{
double aiValue = GetAIValue(ioiP, DefualtSlaveID, index-1);
return Math.Round(aiValue,2);
double aiValue = GetAIValue(ioiP, DefualtSlaveID, index - 1);
return Math.Round(aiValue, 2);
}
public static double GetAIValue(string ioIP, byte slaveId, int index)
......@@ -284,7 +284,7 @@ namespace OnlineStore.DeviceLibrary
}
try
{
if (StoreManager.Store.KNDIOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.HIGH))
if (StoreManager.Store != null && StoreManager.Store.KNDIOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.HIGH))
{
if (StoreManager.Config.AIDI1_Addr > 0 && StoreManager.Config.AIDI2_Addr > 0)
{ //每次上传后验证下
......@@ -298,7 +298,7 @@ namespace OnlineStore.DeviceLibrary
// ConnectionIP(ioIp);
}
}
else if(StoreManager.Config.AIDI3_Addr > 0 && StoreManager.Config.AIDI4_Addr > 0)
else if (StoreManager.Config.AIDI3_Addr > 0 && StoreManager.Config.AIDI4_Addr > 0)
{ //每次上传后验证下
int v1 = (int)GetAIValue(ioIp, StoreManager.Config.AIDI3_Addr);
int v2 = (int)GetAIValue(ioIp, StoreManager.Config.AIDI4_Addr);
......@@ -311,6 +311,7 @@ namespace OnlineStore.DeviceLibrary
}
}
}
}
catch (Exception ex)
{
......@@ -349,7 +350,7 @@ namespace OnlineStore.DeviceLibrary
break;
}
}
// LOGGER.Info ("Read data:【" + reviceMsg + "】 ");
// LOGGER.Info ("Read data:【" + reviceMsg + "】 ");
if (ID == 0xFF)
{
return;
......@@ -392,9 +393,9 @@ namespace OnlineStore.DeviceLibrary
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "处理接受数据出错:" + ex.ToString());
LogUtil.error(LOGGER, "处理接受数据出错:" + ex.ToString());
}
}
}
private static void MBmaster_OnException(string ioIp, ushort id, byte function, byte exception, byte[] reviceData)
{
string exc = "Modbus says error: ";
......@@ -413,7 +414,7 @@ namespace OnlineStore.DeviceLibrary
default:
break;
}
LOGGER.Error("接收数据出错:" + exc);
LOGGER.Error("接收数据出错:" + exc);
}
}
......
......@@ -1225,7 +1225,12 @@ namespace OnlineStore.DeviceLibrary
if (currInOutFixture.WareNum.Equals(""))
{
LogUtil.info(LOGGER, StoreName + "开始执行排队中的出库【" + currInOutFixture.ToStr() + "】");
StartOutStoreMove(new InOutStoreParam("", currInOutFixture.PosId, currInOutFixture.plateH, currInOutFixture.plateW));
bool result = StartOutStoreMove(new InOutStoreParam("", currInOutFixture.PosId, currInOutFixture.plateH, currInOutFixture.plateW));
if (!result)
{
LogUtil.info(LOGGER, StoreName + " 执行排队中的出库【" + currInOutFixture.ToStr() + "】失败,重新加入等待队列");
AddWaitOutInfo(currInOutFixture);
}
}
}
}
......@@ -1954,13 +1959,20 @@ namespace OnlineStore.DeviceLibrary
}
else
{
FixtureCodeInfo currInOutFixture = new FixtureCodeInfo(0, "", posId, plateW, plateH);
if (CanStarInOut())
{
StartOutStoreMove(new InOutStoreParam("", posId, position));
bool result = StartOutStoreMove(new InOutStoreParam("", posId, position));
if (!result)
{
LogUtil.info(LOGGER, StoreName + " 执行出库【" + currInOutFixture.ToStr() + "】失败,加入等待队列");
AddWaitOutInfo(currInOutFixture);
}
}
else
{
LogUtil.error(LOGGER, "收到服务器出库命令:出库【" + posId + "】失败,当前在忙碌中");
LogUtil.error(LOGGER, "执行出库【" + currInOutFixture.ToStr() + "】失败,当前在忙碌中,加入等待队列");
AddWaitOutInfo(currInOutFixture);
}
}
......
......@@ -517,7 +517,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 开始出库运动
/// </summary>
public override void StartOutStoreMove(InOutStoreParam param)
public override bool StartOutStoreMove(InOutStoreParam param)
{
startOutStoreTime = DateTime.Now;
string posId = param != null ? param.PositionNum : "";
......@@ -526,12 +526,12 @@ namespace OnlineStore.DeviceLibrary
if (!LoadParamPosition(param))
{
LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,找不到库位信息");
return;
return false ;
}
if (KNDIOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,叉子料盘检测有料");
return;
return false ;
}
storeStatus = StoreStatus.OutStoreExecute;
LogUtil.info(LOGGER, StoreName + "启动出库【" + posId + "】 ", storeMoveColor);
......@@ -552,11 +552,13 @@ namespace OnlineStore.DeviceLibrary
OutStoreLog("出库:SO_01 定位气缸下降");
LocationDownAndWait();
}
return true;
}
else
{
LogUtil.error(LOGGER, StoreName + " 启动出库出错,当前状态,storeStatus=" + storeRunStatus);
}
return false;
}
protected override void OutStoreProcess()
{
......
......@@ -89,7 +89,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 开始出库运动
/// </summary>
public abstract void StartOutStoreMove(InOutStoreParam param);
public abstract bool StartOutStoreMove(InOutStoreParam param);
protected abstract void OutStoreProcess();
#endregion
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!