Commit 24b7bfb3 LN

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

1 个父辈 475ba646
......@@ -88,4 +88,8 @@
XA 开头的二维码,默认为 13*48
XB 开头的二维码,默认为 13*
\ 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
......@@ -24,7 +24,7 @@ namespace OnlineStore.Common
//public event SerialErrorReceivedEventHandler Error;
//接收事件是否有效 false表示有效
//public bool ReceiveEventFlag = false;
#endregion
#region 获取串口名
......@@ -52,7 +52,7 @@ namespace OnlineStore.Common
}
}
#endregion
#region 默认构造函数
///// <summary>
///// 默认构造函数,操作COM1,速度为9600,没有奇偶校验,8位字节,停止位为1 "COM1", 9600, Parity.None, 8, StopBits.One
......@@ -62,7 +62,7 @@ namespace OnlineStore.Common
// _serialPort = new SerialPort();
//}
#endregion
#region 构造函数
///// <summary>
///// 构造函数,
......@@ -81,7 +81,7 @@ namespace OnlineStore.Common
// setSerialPort();
//}
#endregion
#region 构造函数,可以自定义串口的初始化参数
/// <summary>
/// 构造函数,可以自定义串口的初始化参数
......@@ -99,7 +99,7 @@ namespace OnlineStore.Common
setSerialPort();
}
#endregion
#region 析构函数
/// <summary>
/// 析构函数,关闭串口
......@@ -110,7 +110,7 @@ namespace OnlineStore.Common
_serialPort.Close();
}
#endregion
#region 设置串口参数
/// <summary>
/// 设置串口参数
......@@ -148,7 +148,7 @@ namespace OnlineStore.Common
//设置触发DataReceived事件的字节数为1
_serialPort.ReceivedBytesThreshold = 1;
//接收到一个字节时,也会触发DataReceived事件
// _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived);
// _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived);
//接收数据出错,触发事件
_serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(_serialPort_ErrorReceived);
//打开串口
......@@ -183,7 +183,7 @@ namespace OnlineStore.Common
return ok;
}
#endregion
#region 关闭串口
/// <summary>
/// 关闭串口资源,操作完成后,一定要关闭串口
......@@ -211,8 +211,8 @@ namespace OnlineStore.Common
}
#endregion
#region 接收数据出错事件
/// <summary>
/// 接收数据出错事件
......@@ -271,7 +271,7 @@ namespace OnlineStore.Common
// LogUtil.error(LOGGER, "SendData ERROR:" + ex.ToString(), 21);
// }
// }
//}
#endregion
#region 发送命令
......@@ -282,13 +282,13 @@ namespace OnlineStore.Common
/// <param name="ReceiveData">接收数据</param>
/// <param name="Overtime">超时时间</param>
/// <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;
if (_serialPort.IsOpen)
{
//lock (lockObj)
if(Monitor.TryEnter(lockObj,10))
if (Monitor.TryEnter(lockObj, 10))
{
//Monitor.Enter(lockObj);
try
......@@ -326,7 +326,7 @@ namespace OnlineStore.Common
LogUtil.error(LOGGER, "SendCommand ERROR:" + ex.ToString(), 20);
}
finally
{
{
Monitor.Exit(lockObj);
}
}
......@@ -348,19 +348,18 @@ namespace OnlineStore.Common
/// <param name="Overtime">超时时间</param>
/// <param name="ReceiveLength">接收数据长度</param>
/// <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)
{
LogUtil.error(PortName+" 发送数据"+ByteToString(SendData)+ "失败,_serialPort=null");
LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + "失败,_serialPort=null");
return -1;
}
if (_serialPort.IsOpen)
{
if (Monitor.TryEnter(lockObj, 10))
if (Monitor.TryEnter(lockObj, 200))
{
//Monitor.Enter(lockObj);
try
{
_serialPort.DiscardInBuffer(); //清空接收缓冲区
......@@ -370,32 +369,32 @@ namespace OnlineStore.Common
if (ReceiveData == null)
{
ReceiveData = new byte[ReceiveLength];
}
}
while (num++ < Overtime)
{
if (_serialPort.BytesToRead >= ReceiveData.Length)
{
if (_serialPort.BytesToRead >= ReceiveLength)
break;
System.Threading.Thread.Sleep(1);
}
if (num >= Overtime)
{
{
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
{
ret = _serialPort.Read(ReceiveData, 0, _serialPort.BytesToRead);
}
return ret;
}
catch (Exception ex)
{
LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + " 出错:"+ex.ToString());
LogUtil.error(PortName + " 发送数据" + ByteToString(SendData) + " 出错:" + ex.ToString());
}
finally
{
......@@ -410,8 +409,8 @@ namespace OnlineStore.Common
}
return -1;
}
#endregion
#region 获取串口
......@@ -457,7 +456,7 @@ namespace OnlineStore.Common
#endregion
#region 十六进制字符串转字节型
/// <summary>
/// 打包方法,可以将十六制字符串转成byte[] ,字符串没有空格
/// </summary>
......@@ -493,7 +492,7 @@ namespace OnlineStore.Common
return putout;
}
#endregion
#region 字节型转十六进制字符串
/// <summary>
/// 字节数组转16进制字符串
......@@ -512,6 +511,18 @@ namespace OnlineStore.Common
}
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
#region 计算校验码
......@@ -557,4 +568,4 @@ namespace OnlineStore.Common
#endregion
}
}
}
......@@ -147,7 +147,11 @@ namespace OnlineStore.DeviceLibrary
}
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);
}
}
......
......@@ -124,3 +124,6 @@ PRO,模拟信号1的地址,AIDI1_Addr,7,,,,,,,
PRO,模拟信号2的地址,AIDI2_Addr,8,,,,,,,
PRO,模拟信号3的地址,AIDI3_Addr,5,,,,,,,
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
private string spiltStr = "##";
private void scanTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
int height = GetHeight();
{
DateTime date = DateTime.Now;
//scanTimer.Enabled = false;
KNDIOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
......@@ -1511,32 +1509,47 @@ namespace OnlineStore.DeviceLibrary
foreach (string str in codeList)
{
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 (str.ToUpper().StartsWith("XA"))
{
code = "=1+0x0-13x48" + "=" + code;
}else if (str.ToUpper().StartsWith("XB"))
//只有西安料仓使用此解码类型
string codea = CodeManager.GetBarcode(str);
if (String.IsNullOrEmpty(codea))
{
code = "=1+0x0-13x32" + "=" + code;
code = "";
}
else
{
code = "=1+0x0-" + GetSize() + "x" + height + "=" + CodeManager.GetBarcode(str);
}
{
code = "=1+0x0-" + codeSize + "=" + codea;
}
}
else
{
code = "=1+0x0-" + codeSize + "=" + code;
}
if (!String.IsNullOrEmpty(code))
{
if (str.ToUpper().StartsWith("FA"))
{
code = "=1+0x0-7x32" + "=" + code;
}
else
{
code = "=1+0x0-7x" + height + "=" + code;
}
message = message + code + spiltStr;
}
message = message + code + spiltStr;
}
if (!outMsg.Equals(""))
{
......@@ -1570,6 +1583,11 @@ namespace OnlineStore.DeviceLibrary
#region 高度传感器处理
public int GetSize()
{
if (Config.Default_TrayWidth > 0)
{
//如果配置了默认宽度,使用默认宽度且不能修改
return Config.Default_TrayWidth;
}
if (Config.AIDI3_Addr <= 0 || Config.AIDI4_Addr <= 0)
{
return 7;
......
......@@ -532,30 +532,60 @@ namespace OnlineStore.LoadCSVLibrary
/// </summary>
[ConfigProAttribute("AIDI4_Addr", false )]
public int AIDI4_Addr { get; set; }
//private List<string> TempAddrList = null;
//public static char TempAddrSpilt = '#';
///// <summary>
///// 温湿度地址列表
///// </summary>
//public List<string> GetTempAddrList()
//{
// if (TempAddrList == null)
// {
// TempAddrList = new List<string>();
// string[] array = Temperate_Serveraddress.Split(TempAddrSpilt);
// if (array.Length > 0)
// {
// foreach (string str in array)
// {
// if (!str.Equals(""))
// {
// TempAddrList.Add(str);
// }
// }
// }
// }
// return TempAddrList;
//}
/// <summary>
/// PRO,特殊二维码尺寸配置,CodeSizeConfig,XA=13x48#XB=13x32#FA=7x32,,,,,,,
/// </summary>
[ConfigProAttribute("CodeSizeConfig", false)]
public string CodeSizeConfig { get; set; }
/// <summary>
/// PRO,默认的料盘宽度(不可更改),Default_TrayWidth,0,,,,,,,
/// </summary>
[ConfigProAttribute("Default_TrayWidth", false)]
public int Default_TrayWidth { get; set; }
private Dictionary<string, string> CodeSizeMap =null ;
private static char codeSpilt= '#';
public string GetCodeSize(string code)
{
try
{
if (CodeSizeMap == null)
{
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()
{
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!