Commit 24b7bfb3 LN

二维码特殊尺寸改为可配置

1 个父辈 475ba646
...@@ -88,4 +88,8 @@ ...@@ -88,4 +88,8 @@
XA 开头的二维码,默认为 13*48 XA 开头的二维码,默认为 13*48
XB 开头的二维码,默认为 13* XB 开头的二维码,默认为 13*
20190812修改: StoreConfig增加配置
PRO,默认的料盘宽度(多种尺寸为0),Default_TrayWidth,0,,,,,,,
PRO,特殊二维码尺寸配置,CodeSizeConfig,XA=13x48#XB=13x32#FA=7x32,,,,,,,
二维码特殊尺寸改为可配置。
\ No newline at end of file \ No newline at end of file
...@@ -282,13 +282,13 @@ namespace OnlineStore.Common ...@@ -282,13 +282,13 @@ namespace OnlineStore.Common
/// <param name="ReceiveData">接收数据</param> /// <param name="ReceiveData">接收数据</param>
/// <param name="Overtime">超时时间</param> /// <param name="Overtime">超时时间</param>
/// <returns></returns> /// <returns></returns>
public int SendCommand(byte[] SendData, ref byte[] ReceiveData, int Overtime,out bool isOk) public int SendCommand(byte[] SendData, ref byte[] ReceiveData, int Overtime, out bool isOk)
{ {
isOk = false; isOk = false;
if (_serialPort.IsOpen) if (_serialPort.IsOpen)
{ {
//lock (lockObj) //lock (lockObj)
if(Monitor.TryEnter(lockObj,10)) if (Monitor.TryEnter(lockObj, 10))
{ {
//Monitor.Enter(lockObj); //Monitor.Enter(lockObj);
try try
...@@ -352,15 +352,14 @@ namespace OnlineStore.Common ...@@ -352,15 +352,14 @@ namespace OnlineStore.Common
{ {
if (_serialPort == null) if (_serialPort == null)
{ {
LogUtil.error(PortName+" 发送数据"+ByteToString(SendData)+ "失败,_serialPort=null"); LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + "失败,_serialPort=null");
return -1; return -1;
} }
if (_serialPort.IsOpen) if (_serialPort.IsOpen)
{ {
if (Monitor.TryEnter(lockObj, 10)) if (Monitor.TryEnter(lockObj, 200))
{ {
//Monitor.Enter(lockObj);
try try
{ {
_serialPort.DiscardInBuffer(); //清空接收缓冲区 _serialPort.DiscardInBuffer(); //清空接收缓冲区
...@@ -373,7 +372,7 @@ namespace OnlineStore.Common ...@@ -373,7 +372,7 @@ namespace OnlineStore.Common
} }
while (num++ < Overtime) while (num++ < Overtime)
{ {
if (_serialPort.BytesToRead >= ReceiveData.Length) if (_serialPort.BytesToRead >= ReceiveLength)
break; break;
System.Threading.Thread.Sleep(1); System.Threading.Thread.Sleep(1);
} }
...@@ -381,10 +380,10 @@ namespace OnlineStore.Common ...@@ -381,10 +380,10 @@ namespace OnlineStore.Common
{ {
LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + "等待接受数据超时"); LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + "等待接受数据超时");
} }
if (_serialPort.BytesToRead >= ReceiveData.Length) if (_serialPort.BytesToRead >= ReceiveLength)
{ {
ret = _serialPort.Read(ReceiveData, 0, ReceiveData.Length); ret = _serialPort.Read(ReceiveData, 0, ReceiveLength);
} }
else else
{ {
...@@ -395,7 +394,7 @@ namespace OnlineStore.Common ...@@ -395,7 +394,7 @@ namespace OnlineStore.Common
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + " 出错:"+ex.ToString()); LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + " 出错:" + ex.ToString());
} }
finally finally
{ {
...@@ -512,6 +511,18 @@ namespace OnlineStore.Common ...@@ -512,6 +511,18 @@ namespace OnlineStore.Common
} }
return returnStr; return returnStr;
} }
public static string byteToHexStr(byte[] bytes, string spilChar)
{
string returnStr = "";
if (bytes != null)
{
for (int i = 0; i < bytes.Length; i++)
{
returnStr += bytes[i].ToString("X2") + spilChar;
}
}
return returnStr;
}
#endregion #endregion
#region 计算校验码 #region 计算校验码
......
...@@ -147,7 +147,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -147,7 +147,11 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
bean.SendCommand(data, ref returnData, outTime, reviceLength); int ret = bean.SendCommand(data, ref returnData, outTime, reviceLength);
if (!ret.Equals(reviceLength))
{
LogUtil.error("串口" + portName + " 写入数据:" + strSend + ",预计返回字节数【" + reviceLength + "】实际返回【" + ret + "】");
}
System.Threading.Thread.Sleep(2); System.Threading.Thread.Sleep(2);
} }
} }
......
...@@ -124,3 +124,6 @@ PRO,模拟信号1的地址,AIDI1_Addr,7,,,,,,, ...@@ -124,3 +124,6 @@ PRO,模拟信号1的地址,AIDI1_Addr,7,,,,,,,
PRO,模拟信号2的地址,AIDI2_Addr,8,,,,,,, PRO,模拟信号2的地址,AIDI2_Addr,8,,,,,,,
PRO,模拟信号3的地址,AIDI3_Addr,5,,,,,,, PRO,模拟信号3的地址,AIDI3_Addr,5,,,,,,,
PRO,模拟信号4的地址,AIDI4_Addr,6,,,,,,, PRO,模拟信号4的地址,AIDI4_Addr,6,,,,,,,
,,,,,,,,, ,
PRO,默认的料盘宽度(多种尺寸为0),Default_TrayWidth,0,,,,,,,
PRO,特殊二维码尺寸配置,CodeSizeConfig,XA=13x48#XB=13x32#FA=7x32,,,,,,,
...@@ -1494,8 +1494,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -1494,8 +1494,6 @@ namespace OnlineStore.DeviceLibrary
private string spiltStr = "##"; private string spiltStr = "##";
private void scanTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void scanTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
int height = GetHeight();
DateTime date = DateTime.Now; DateTime date = DateTime.Now;
//scanTimer.Enabled = false; //scanTimer.Enabled = false;
KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH); KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
...@@ -1511,33 +1509,48 @@ namespace OnlineStore.DeviceLibrary ...@@ -1511,33 +1509,48 @@ namespace OnlineStore.DeviceLibrary
foreach (string str in codeList) foreach (string str in codeList)
{ {
string code = str; string code = str;
if (CodeManager.DeCodeType.Equals(1)) //根据二维码开头获取固定尺寸
string codeSize = Config.GetCodeSize(str.Trim());
if (String.IsNullOrEmpty(codeSize))
{ {
if (str.ToUpper().StartsWith("XA")) //无固定尺寸,判断宽度是否是固定,如果不是固定,直接获取当前高度宽度
{ codeSize = GetSize() + "x" + GetHeight();
code = "=1+0x0-13x48" + "=" + code; }
}else if (str.ToUpper().StartsWith("XB"))
if (str.Trim().ToUpper().StartsWith("XA"))//西安料仓
{ {
code = "=1+0x0-13x32" + "=" + code; code = "=1+0x0-13x48" + "=" + str.Trim();
} }
else else if (str.Trim().ToUpper().StartsWith("XB"))//西安料仓
{ {
code = "=1+0x0-" + GetSize() + "x" + height + "=" + CodeManager.GetBarcode(str); code = "=1+0x0-13x32" + "=" + str.Trim();
} }
else if (str.ToUpper().StartsWith("FA"))//孝感料仓
{
code = "=1+0x0-7x32" + "=" + code;
} }
else if (CodeManager.DeCodeType.Equals(1))
{ {
if (str.ToUpper().StartsWith("FA")) //只有西安料仓使用此解码类型
string codea = CodeManager.GetBarcode(str);
if (String.IsNullOrEmpty(codea))
{ {
code = "=1+0x0-7x32" + "=" + code; code = "";
} }
else else
{ {
code = "=1+0x0-7x" + height + "=" + code; code = "=1+0x0-" + codeSize + "=" + codea;
}
} }
else
{
code = "=1+0x0-" + codeSize + "=" + code;
} }
if (!String.IsNullOrEmpty(code))
{
message = message + code + spiltStr; message = message + code + spiltStr;
} }
}
if (!outMsg.Equals("")) if (!outMsg.Equals(""))
{ {
CodeMsg = "盘尺寸错误,清理二维码【" + message + "】"; CodeMsg = "盘尺寸错误,清理二维码【" + message + "】";
...@@ -1570,6 +1583,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -1570,6 +1583,11 @@ namespace OnlineStore.DeviceLibrary
#region 高度传感器处理 #region 高度传感器处理
public int GetSize() public int GetSize()
{ {
if (Config.Default_TrayWidth > 0)
{
//如果配置了默认宽度,使用默认宽度且不能修改
return Config.Default_TrayWidth;
}
if (Config.AIDI3_Addr <= 0 || Config.AIDI4_Addr <= 0) if (Config.AIDI3_Addr <= 0 || Config.AIDI4_Addr <= 0)
{ {
return 7; return 7;
......
...@@ -532,30 +532,60 @@ namespace OnlineStore.LoadCSVLibrary ...@@ -532,30 +532,60 @@ namespace OnlineStore.LoadCSVLibrary
/// </summary> /// </summary>
[ConfigProAttribute("AIDI4_Addr", false )] [ConfigProAttribute("AIDI4_Addr", false )]
public int AIDI4_Addr { get; set; } public int AIDI4_Addr { get; set; }
//private List<string> TempAddrList = null;
//public static char TempAddrSpilt = '#'; /// <summary>
///// <summary> /// PRO,特殊二维码尺寸配置,CodeSizeConfig,XA=13x48#XB=13x32#FA=7x32,,,,,,,
///// 温湿度地址列表 /// </summary>
///// </summary> [ConfigProAttribute("CodeSizeConfig", false)]
//public List<string> GetTempAddrList() public string CodeSizeConfig { get; set; }
//{
// if (TempAddrList == null) /// <summary>
// { /// PRO,默认的料盘宽度(不可更改),Default_TrayWidth,0,,,,,,,
// TempAddrList = new List<string>(); /// </summary>
// string[] array = Temperate_Serveraddress.Split(TempAddrSpilt); [ConfigProAttribute("Default_TrayWidth", false)]
// if (array.Length > 0) public int Default_TrayWidth { get; set; }
// {
// foreach (string str in array) private Dictionary<string, string> CodeSizeMap =null ;
// { private static char codeSpilt= '#';
// if (!str.Equals(""))
// { public string GetCodeSize(string code)
// TempAddrList.Add(str); {
// } try
// } {
// } if (CodeSizeMap == null)
// } {
// return TempAddrList; CodeSizeMap = new Dictionary<string, string>();
//} string[] array = CodeSizeConfig.Split(codeSpilt);
if (array.Length > 0)
{
foreach (string str in array)
{
string[] codeStr = str.Split('=');
if (codeStr.Length == 2)
{
string key = codeStr[0].Trim();
string value = codeStr[1].Trim();
CodeSizeMap.Add(key, value);
}
}
}
}
foreach (string key in CodeSizeMap.Keys)
{
if (code.Trim().StartsWith(key))
{
return CodeSizeMap[key];
}
}
}catch(Exception ex)
{
LOGGER.Error("获取二维码【"+code+"】的固定尺寸出错:"+ex.ToString());
}
return "";
}
protected override void initMustHavePro() protected override void initMustHavePro()
{ {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!