You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
4.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Newtonsoft.Json;
using System;
using ZJ_BYD.Model;
namespace ZJ_BYD.Untils
{
public class CAN2Helper
{
/// <summary>
///
/// </summary>
/// <param name="mskcode"></param>
/// <param name="barCode"></param>
/// <param name="num">流水号</param>
/// <returns></returns>
public static (bool isOk, string barCode, string msg) CanCommunication(T_MaskCode mskcode, string barCode, string num, out string _serialNum)
{
CAN2DeviceHelper.Instance.Run(mskcode.SoftCode, mskcode.IsSerialNum, mskcode.PartCode, mskcode.PrintBarcode, num, out _serialNum);
//软件编码、引导版本号、电压上限、电压下限
string guideversion;
decimal voltagemax_1;
decimal voltagemin_1;
decimal volt_sum = 0;
try
{
guideversion = mskcode.GuideVersion;
var voltagemax = mskcode.VoltageMax;
var voltagemin = mskcode.VoltageMin;
decimal.TryParse(voltagemax, out voltagemax_1);
decimal.TryParse(voltagemin, out voltagemin_1);
if (CAN2DeviceHelper.Instance.DeviceInfo != null && CAN2DeviceHelper.Instance.DeviceInfo.Voltage.Length >= 3)
{
volt_sum = Convert.ToDecimal(CAN2DeviceHelper.Instance.DeviceInfo.Voltage.Substring(0, 3).Trim());
}
else
{
LogHelper.WriteLog($"232通讯时异常{JsonConvert.SerializeObject(CAN2DeviceHelper.Instance.DeviceInfo)}");
}
}
catch (Exception ex)
{
var msg = ex == null ? "操作异常" : ex.Message;
LogHelper.WriteLog($"打印时查询数据库中引导版本号、电压上限、电压下限异常:{msg}");
return (false, "", $"{DateTime.Now:HH:mm:ss}>>>>>一体机反馈打印时查询数据库中引导版本号、电压上限、电压下限异常:{msg}{Environment.NewLine}");
}
//如果掩码表中配置了软件编码,则需要校验
if (!string.IsNullOrWhiteSpace(mskcode.SoftCode))
{
//验证软件编号
if (string.IsNullOrEmpty(CAN1DeviceHelper.Instance.DeviceInfo.SoftwareCode))
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【软件编号】 读取为空");
}
//与掩码表比对
if (mskcode.SoftCode.ToUpper() != CAN1DeviceHelper.Instance.DeviceInfo.SoftwareCode.ToUpper())
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【软件编号:{CAN1DeviceHelper.Instance.DeviceInfo.SoftwareCode}】与掩码表配置不一致");
}
}
//获取软件版本号
if (string.IsNullOrEmpty(CAN2DeviceHelper.Instance.DeviceInfo.SoftwareVersion))
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【软件版号本】读取为空");
}
//验证引导版本
if (string.IsNullOrEmpty(CAN2DeviceHelper.Instance.DeviceInfo.GuideVersion))
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【引导版本】读取为空");
}
if (volt_sum < voltagemin_1 || volt_sum > voltagemax_1)
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【电压:{CAN2DeviceHelper.Instance.DeviceInfo.Voltage}】不在范围内");
}
if (CAN2DeviceHelper.Instance.DeviceInfo.SoftwareVersion.Length != mskcode.SoftVersionLen)
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【软件版本:{CAN2DeviceHelper.Instance.DeviceInfo.SoftwareVersion}】长度不对");
}
//零部件号
if (CAN2DeviceHelper.Instance.DeviceInfo.PartCode.ToUpper() != mskcode.PartCode.ToUpper())
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【零部件号不一致:{CAN2DeviceHelper.Instance.DeviceInfo.PartCode}——{mskcode.PartCode}】");
}
if (string.IsNullOrEmpty(CAN2DeviceHelper.Instance.DeviceInfo.SerialNum))
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息失败,【序列号】读取为空");
}
LogHelper.WriteLog($"铭牌码={barCode},序列号={CAN2DeviceHelper.Instance.DeviceInfo.SerialNum}");
return (true, barCode, CAN2DeviceHelper.Instance.DeviceInfo.SoftwareVersion);
}
}
}