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.

84 lines
3.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
{
/// <summary>
/// CAN通讯
/// </summary>
public class CAN1Helper
{
public static (bool isOk, string barCode, string msg) CanCommunication(T_MaskCode mskcode, string barCode)
{
CAN1DeviceHelper.Instance.Run();
LogHelper.WriteLog(JsonConvert.SerializeObject(CAN1DeviceHelper.Instance.DeviceInfo));
//软件编码、引导版本号、电压上限、电压下限
string softcode;
string guideversion;
decimal voltagemax_1;
decimal voltagemin_1;
decimal volt_sum = 0;
try
{
softcode = mskcode.SoftCode;
guideversion = mskcode.GuideVersion;
var voltagemax = mskcode.VoltageMax;
var voltagemin = mskcode.VoltageMin;
decimal.TryParse(voltagemax, out voltagemax_1);
decimal.TryParse(voltagemin, out voltagemin_1);
if (CAN1DeviceHelper.Instance.DeviceInfo != null && CAN1DeviceHelper.Instance.DeviceInfo.Voltage.Length >= 3)
{
volt_sum = Convert.ToDecimal(CAN1DeviceHelper.Instance.DeviceInfo.Voltage.Substring(0, 3).Trim());
}
else
{
LogHelper.WriteLog($"232通讯时异常{JsonConvert.SerializeObject(CAN1DeviceHelper.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.IsNullOrEmpty(CAN1DeviceHelper.Instance.DeviceInfo.SoftwareVersion))
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息NG【软件版号本】读取为空");
}
//验证软件编号
if (string.IsNullOrEmpty(CAN1DeviceHelper.Instance.DeviceInfo.SoftwareCode))
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息NG【软件编号】 读取为空");
}
//验证引导版本
if (string.IsNullOrEmpty(CAN1DeviceHelper.Instance.DeviceInfo.GuideVersion))
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息NG【引导版本】读取为空");
}
//与掩码表比对
if (softcode != CAN1DeviceHelper.Instance.DeviceInfo.SoftwareCode && guideversion != CAN1DeviceHelper.Instance.DeviceInfo.GuideVersion)
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息NG【软件编号{CAN1DeviceHelper.Instance.DeviceInfo.SoftwareCode}】和【引导版本: {CAN1DeviceHelper.Instance.DeviceInfo.GuideVersion}】与掩码表匹配不一致");
}
if (volt_sum < voltagemin_1 || volt_sum > voltagemax_1)
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息NG【电压{CAN1DeviceHelper.Instance.DeviceInfo.Voltage}】不在范围内");
}
if (CAN1DeviceHelper.Instance.DeviceInfo.SoftwareVersion.Length != mskcode.SoftVersionLen)
{
return (false, barCode, $"{DateTime.Now:HH:mm:ss}>>>>>验证设备信息NG【软件版本{CAN1DeviceHelper.Instance.DeviceInfo.SoftwareVersion}】长度不对");
}
return (true, barCode, CAN1DeviceHelper.Instance.DeviceInfo.SoftwareVersion);
}
}
}