Commit 24b7bfb3 LN

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

1 个父辈 475ba646
...@@ -88,4 +88,8 @@ ...@@ -88,4 +88,8 @@
XA 开头的二维码,默认为 13*48 XA 开头的二维码,默认为 13*48
XB 开头的二维码,默认为 13* XB 开头的二维码,默认为 13*
\ No newline at end of file \ No newline at end of file
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
...@@ -24,7 +24,7 @@ namespace OnlineStore.Common ...@@ -24,7 +24,7 @@ namespace OnlineStore.Common
//public event SerialErrorReceivedEventHandler Error; //public event SerialErrorReceivedEventHandler Error;
//接收事件是否有效 false表示有效 //接收事件是否有效 false表示有效
//public bool ReceiveEventFlag = false; //public bool ReceiveEventFlag = false;
#endregion #endregion
#region 获取串口名 #region 获取串口名
...@@ -52,7 +52,7 @@ namespace OnlineStore.Common ...@@ -52,7 +52,7 @@ namespace OnlineStore.Common
} }
} }
#endregion #endregion
#region 默认构造函数 #region 默认构造函数
///// <summary> ///// <summary>
///// 默认构造函数,操作COM1,速度为9600,没有奇偶校验,8位字节,停止位为1 "COM1", 9600, Parity.None, 8, StopBits.One ///// 默认构造函数,操作COM1,速度为9600,没有奇偶校验,8位字节,停止位为1 "COM1", 9600, Parity.None, 8, StopBits.One
...@@ -62,7 +62,7 @@ namespace OnlineStore.Common ...@@ -62,7 +62,7 @@ namespace OnlineStore.Common
// _serialPort = new SerialPort(); // _serialPort = new SerialPort();
//} //}
#endregion #endregion
#region 构造函数 #region 构造函数
///// <summary> ///// <summary>
///// 构造函数, ///// 构造函数,
...@@ -81,7 +81,7 @@ namespace OnlineStore.Common ...@@ -81,7 +81,7 @@ namespace OnlineStore.Common
// setSerialPort(); // setSerialPort();
//} //}
#endregion #endregion
#region 构造函数,可以自定义串口的初始化参数 #region 构造函数,可以自定义串口的初始化参数
/// <summary> /// <summary>
/// 构造函数,可以自定义串口的初始化参数 /// 构造函数,可以自定义串口的初始化参数
...@@ -99,7 +99,7 @@ namespace OnlineStore.Common ...@@ -99,7 +99,7 @@ namespace OnlineStore.Common
setSerialPort(); setSerialPort();
} }
#endregion #endregion
#region 析构函数 #region 析构函数
/// <summary> /// <summary>
/// 析构函数,关闭串口 /// 析构函数,关闭串口
...@@ -110,7 +110,7 @@ namespace OnlineStore.Common ...@@ -110,7 +110,7 @@ namespace OnlineStore.Common
_serialPort.Close(); _serialPort.Close();
} }
#endregion #endregion
#region 设置串口参数 #region 设置串口参数
/// <summary> /// <summary>
/// 设置串口参数 /// 设置串口参数
...@@ -148,7 +148,7 @@ namespace OnlineStore.Common ...@@ -148,7 +148,7 @@ namespace OnlineStore.Common
//设置触发DataReceived事件的字节数为1 //设置触发DataReceived事件的字节数为1
_serialPort.ReceivedBytesThreshold = 1; _serialPort.ReceivedBytesThreshold = 1;
//接收到一个字节时,也会触发DataReceived事件 //接收到一个字节时,也会触发DataReceived事件
// _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived); // _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived);
//接收数据出错,触发事件 //接收数据出错,触发事件
_serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(_serialPort_ErrorReceived); _serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(_serialPort_ErrorReceived);
//打开串口 //打开串口
...@@ -183,7 +183,7 @@ namespace OnlineStore.Common ...@@ -183,7 +183,7 @@ namespace OnlineStore.Common
return ok; return ok;
} }
#endregion #endregion
#region 关闭串口 #region 关闭串口
/// <summary> /// <summary>
/// 关闭串口资源,操作完成后,一定要关闭串口 /// 关闭串口资源,操作完成后,一定要关闭串口
...@@ -211,8 +211,8 @@ namespace OnlineStore.Common ...@@ -211,8 +211,8 @@ namespace OnlineStore.Common
} }
#endregion #endregion
#region 接收数据出错事件 #region 接收数据出错事件
/// <summary> /// <summary>
/// 接收数据出错事件 /// 接收数据出错事件
...@@ -271,7 +271,7 @@ namespace OnlineStore.Common ...@@ -271,7 +271,7 @@ namespace OnlineStore.Common
// LogUtil.error(LOGGER, "SendData ERROR:" + ex.ToString(), 21); // LogUtil.error(LOGGER, "SendData ERROR:" + ex.ToString(), 21);
// } // }
// } // }
//} //}
#endregion #endregion
#region 发送命令 #region 发送命令
...@@ -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
...@@ -326,7 +326,7 @@ namespace OnlineStore.Common ...@@ -326,7 +326,7 @@ namespace OnlineStore.Common
LogUtil.error(LOGGER, "SendCommand ERROR:" + ex.ToString(), 20); LogUtil.error(LOGGER, "SendCommand ERROR:" + ex.ToString(), 20);
} }
finally finally
{ {
Monitor.Exit(lockObj); Monitor.Exit(lockObj);
} }
} }
...@@ -348,19 +348,18 @@ namespace OnlineStore.Common ...@@ -348,19 +348,18 @@ namespace OnlineStore.Common
/// <param name="Overtime">超时时间</param> /// <param name="Overtime">超时时间</param>
/// <param name="ReceiveLength">接收数据长度</param> /// <param name="ReceiveLength">接收数据长度</param>
/// <returns></returns> /// <returns></returns>
public int SendCommand(byte[] SendData, ref byte[] ReceiveData, int Overtime, int ReceiveLength) public int SendCommand(byte[] SendData, ref byte[] ReceiveData, int Overtime, int ReceiveLength)
{ {
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(); //清空接收缓冲区
...@@ -370,32 +369,32 @@ namespace OnlineStore.Common ...@@ -370,32 +369,32 @@ namespace OnlineStore.Common
if (ReceiveData == null) if (ReceiveData == null)
{ {
ReceiveData = new byte[ReceiveLength]; ReceiveData = new byte[ReceiveLength];
} }
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);
} }
if (num >= Overtime) if (num >= Overtime)
{ {
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
{ {
ret = _serialPort.Read(ReceiveData, 0, _serialPort.BytesToRead); ret = _serialPort.Read(ReceiveData, 0, _serialPort.BytesToRead);
} }
return ret; return ret;
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + " 出错:"+ex.ToString()); LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + " 出错:" + ex.ToString());
} }
finally finally
{ {
...@@ -410,8 +409,8 @@ namespace OnlineStore.Common ...@@ -410,8 +409,8 @@ namespace OnlineStore.Common
} }
return -1; return -1;
} }
#endregion #endregion
#region 获取串口 #region 获取串口
...@@ -457,7 +456,7 @@ namespace OnlineStore.Common ...@@ -457,7 +456,7 @@ namespace OnlineStore.Common
#endregion #endregion
#region 十六进制字符串转字节型 #region 十六进制字符串转字节型
/// <summary> /// <summary>
/// 打包方法,可以将十六制字符串转成byte[] ,字符串没有空格 /// 打包方法,可以将十六制字符串转成byte[] ,字符串没有空格
/// </summary> /// </summary>
...@@ -493,7 +492,7 @@ namespace OnlineStore.Common ...@@ -493,7 +492,7 @@ namespace OnlineStore.Common
return putout; return putout;
} }
#endregion #endregion
#region 字节型转十六进制字符串 #region 字节型转十六进制字符串
/// <summary> /// <summary>
/// 字节数组转16进制字符串 /// 字节数组转16进制字符串
...@@ -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 计算校验码
...@@ -557,4 +568,4 @@ namespace OnlineStore.Common ...@@ -557,4 +568,4 @@ namespace OnlineStore.Common
#endregion #endregion
} }
} }
...@@ -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,,,,,,,
...@@ -1493,9 +1493,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -1493,9 +1493,7 @@ 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,32 +1509,47 @@ namespace OnlineStore.DeviceLibrary ...@@ -1511,32 +1509,47 @@ namespace OnlineStore.DeviceLibrary
foreach (string str in codeList) foreach (string str in codeList)
{ {
string code = str; string code = str;
//根据二维码开头获取固定尺寸
string codeSize = Config.GetCodeSize(str.Trim());
if (String.IsNullOrEmpty(codeSize))
{
//无固定尺寸,判断宽度是否是固定,如果不是固定,直接获取当前高度宽度
codeSize = GetSize() + "x" + GetHeight();
}
if (str.Trim().ToUpper().StartsWith("XA"))//西安料仓
{
code = "=1+0x0-13x48" + "=" + str.Trim();
}
else if (str.Trim().ToUpper().StartsWith("XB"))//西安料仓
{
code = "=1+0x0-13x32" + "=" + str.Trim();
}
else if (str.ToUpper().StartsWith("FA"))//孝感料仓
{
code = "=1+0x0-7x32" + "=" + code;
}
if (CodeManager.DeCodeType.Equals(1)) if (CodeManager.DeCodeType.Equals(1))
{ {
if (str.ToUpper().StartsWith("XA")) //只有西安料仓使用此解码类型
{ string codea = CodeManager.GetBarcode(str);
code = "=1+0x0-13x48" + "=" + code; if (String.IsNullOrEmpty(codea))
}else if (str.ToUpper().StartsWith("XB"))
{ {
code = "=1+0x0-13x32" + "=" + code; code = "";
} }
else else
{ {
code = "=1+0x0-" + GetSize() + "x" + height + "=" + CodeManager.GetBarcode(str); code = "=1+0x0-" + codeSize + "=" + codea;
} }
} }
else else
{
code = "=1+0x0-" + codeSize + "=" + code;
}
if (!String.IsNullOrEmpty(code))
{ {
if (str.ToUpper().StartsWith("FA")) message = message + code + spiltStr;
{
code = "=1+0x0-7x32" + "=" + code;
}
else
{
code = "=1+0x0-7x" + height + "=" + code;
}
} }
message = message + code + spiltStr;
} }
if (!outMsg.Equals("")) if (!outMsg.Equals(""))
{ {
...@@ -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!