You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
381 lines
11 KiB
381 lines
11 KiB
using EC.AutoWeightServer.IfManager.FingerPrint;
|
|
using EC.AutoWeightServer.IfManager.LedZK;
|
|
using EC.AutoWeightServer.IfManager.Light;
|
|
using EC.AutoWeightServer.IfManager.Scales;
|
|
using EC.AutoWeightServer.IfManager.YkPos;
|
|
using EC.AutoWeightServer.Model.Config;
|
|
using EC.AutoWeightServer.UI;
|
|
using EC.AutoWeightServer.UI.UC;
|
|
using EC.Entity.Transport;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace EC.AutoWeightServer.Center
|
|
{
|
|
public class DeviceCenter
|
|
{
|
|
private FrmMainServer _mainServer { get; set; }
|
|
|
|
internal UCLicensePlate PlateManager1 { get; set; }
|
|
internal UCLicensePlate PlateManager2 { get; set; }
|
|
internal UCLicensePlate PlateManager3 { get; set; }
|
|
internal UCLicensePlate PlateManager4 { get; set; }
|
|
|
|
/// <summary>
|
|
/// 称重管理
|
|
/// </summary>
|
|
internal ScalesManager ScalesManager { get; set; }
|
|
|
|
/// <summary>
|
|
/// 灯光控制
|
|
/// </summary>
|
|
internal ILightManager LightManager { get; set; }
|
|
|
|
/// <summary>
|
|
/// 指纹识别
|
|
/// </summary>
|
|
internal FingerPrintManager FPManager { get; set; }
|
|
|
|
/// <summary>
|
|
/// Led控制
|
|
/// </summary>
|
|
internal LedZKManager LedZKManager { get; set; }
|
|
|
|
public DeviceCenter()
|
|
{
|
|
}
|
|
|
|
public DeviceCenter(FrmMainServer mainServer)
|
|
{
|
|
_mainServer = mainServer;
|
|
PlateManager1 = mainServer.ucLicensePlate1;
|
|
PlateManager2 = mainServer.ucLicensePlate2;
|
|
PlateManager3 = mainServer.ucLicensePlate3;
|
|
PlateManager4 = mainServer.ucLicensePlate4;
|
|
}
|
|
|
|
#region Gather
|
|
|
|
public void OpenDevices()
|
|
{
|
|
OpenCameraServer();
|
|
OpenWeightServer();
|
|
OpenLightServer();
|
|
OpenLedServer();
|
|
OpenFingerPrintServer();
|
|
OpenYkPosServer();
|
|
}
|
|
|
|
public void CloseDevices()
|
|
{
|
|
//CloseCameraServer();
|
|
//CloseWeightServer();
|
|
//CloseLightServer();
|
|
//CloseFingerPrintServer();
|
|
//CloseYkPosServer();
|
|
//CloseLedServer();
|
|
}
|
|
|
|
public void CheckDevicesConnect()
|
|
{
|
|
var msgList = new List<string>();
|
|
if (!PlateManager1.IsDeviceConnected())
|
|
msgList.Add("1号摄像头未连接");
|
|
if (!PlateManager2.IsDeviceConnected())
|
|
msgList.Add("2号摄像头未连接");
|
|
if (!PlateManager3.IsDeviceConnected())
|
|
msgList.Add("3号摄像头未连接");
|
|
if (!PlateManager4.IsDeviceConnected())
|
|
msgList.Add("4号摄像头未连接");
|
|
if (ScalesManager == null || !ScalesManager.IsOpen())
|
|
msgList.Add("地磅接口未连接");
|
|
if (LightManager == null || !LightManager.IsOpen())
|
|
msgList.Add("灯光接口未连接");
|
|
if (FPManager == null || !FPManager.IsConnected())
|
|
msgList.Add("指纹接口未连接");
|
|
if (LedZKManager == null || !LedZKManager.IsConnected())
|
|
msgList.Add("Led屏未连接");
|
|
if (!YkPosManager.IsConnected())
|
|
{
|
|
msgList.Add("打印接口未连接");
|
|
}
|
|
else
|
|
{
|
|
if (YkPosManager.IsPaperExhaust())
|
|
msgList.Add("打印接口纸尽");
|
|
//if (YkPosManager.IsPaperWillExhaust())
|
|
// msgList.Add("打印接口纸将尽");
|
|
}
|
|
var msg = string.Join("\n", msgList.ToArray());
|
|
if (!string.IsNullOrEmpty(msg))
|
|
UiExtendCenter.ShowErrorMsgBox(msg);
|
|
}
|
|
|
|
#endregion Gather
|
|
|
|
#region CameraServer
|
|
|
|
private void OpenCameraServer()
|
|
{
|
|
var address1 = ServerConfig.CameraAddress1;
|
|
var address2 = ServerConfig.CameraAddress2;
|
|
var address3 = ServerConfig.CameraAddress3;
|
|
var address4 = ServerConfig.CameraAddress4;
|
|
var port = ServerConfig.CameraSocketPort;
|
|
var username = ServerConfig.CameraUsername;
|
|
var password = ServerConfig.CameraPassword;
|
|
|
|
try
|
|
{
|
|
PlateManager1.InitForm(address1, port, username, password);
|
|
var enableOpen = PlateManager1.OpenDevice();
|
|
if (enableOpen)
|
|
FileUnit.Log(address1 + "打开成功 相机1");
|
|
else
|
|
FileUnit.Log(address1 + "打开失败 相机1");
|
|
|
|
PlateManager2.InitForm(address2, port, username, password);
|
|
enableOpen = PlateManager2.OpenDevice();
|
|
if (enableOpen)
|
|
FileUnit.Log(address2 + "打开成功 相机2");
|
|
else
|
|
FileUnit.Log(address2 + "打开失败 相机2");
|
|
|
|
PlateManager3.InitForm(address3, port, username, password);
|
|
enableOpen = PlateManager3.OpenDevice();
|
|
if (enableOpen)
|
|
FileUnit.Log(address3 + "打开成功 相机3");
|
|
else
|
|
FileUnit.Log(address3 + "打开失败 相机3");
|
|
|
|
PlateManager4.InitForm(address4, port, username, password);
|
|
enableOpen = PlateManager4.OpenDevice();
|
|
if (enableOpen)
|
|
FileUnit.Log(address4 + "打开成功 相机4");
|
|
else
|
|
FileUnit.Log(address4 + "打开失败 相机4");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogUnit.Error(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void CloseCameraServer()
|
|
{
|
|
PlateManager1.CloseForm();
|
|
PlateManager2.CloseForm();
|
|
PlateManager3.CloseForm();
|
|
PlateManager4.CloseForm();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过2号摄像头(入场后摄像头)拍摄照片,并返回照片路径
|
|
/// </summary>
|
|
/// <param name="license"></param>
|
|
/// <returns></returns>
|
|
internal string GetInPicture2(string license)
|
|
{
|
|
return PlateManager2.GetPlatePic(license);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过4号摄像头(出场后摄像头)拍摄照片,并返回照片路径
|
|
/// </summary>
|
|
/// <param name="license"></param>
|
|
/// <returns></returns>
|
|
internal string GetOutPicture2(string license)
|
|
{
|
|
return PlateManager4.GetPlatePic(license);
|
|
}
|
|
|
|
#endregion CameraServer
|
|
|
|
#region ScalesManager
|
|
|
|
public void OpenWeightServer()
|
|
{
|
|
var com = ServerConfig.WtCom;
|
|
var rate = ServerConfig.WtBaudRate;
|
|
var receivedBytesThreshold = ServerConfig.WtReceivedBytesThreshold;
|
|
ScalesManager = new ScalesManager(com, rate, receivedBytesThreshold);
|
|
ScalesManager.StartServer();
|
|
}
|
|
|
|
public void CloseWeightServer()
|
|
{
|
|
ScalesManager?.StopServer();
|
|
ScalesManager = null;
|
|
}
|
|
|
|
#endregion ScalesManager
|
|
|
|
#region LightManager
|
|
|
|
public void OpenLightServer()
|
|
{
|
|
var com = ServerConfig.LightRelayCom;
|
|
var rate = ServerConfig.LightRelayBaudRate;
|
|
LightManager = new Light2Manager(com, rate);
|
|
LightManager.StartServer();
|
|
}
|
|
|
|
public void CloseLightServer()
|
|
{
|
|
LightManager?.StopServer();
|
|
LightManager = null;
|
|
}
|
|
|
|
#endregion LightManager
|
|
|
|
#region LedZKManager
|
|
|
|
public void OpenLedServer()
|
|
{
|
|
var ip = ServerConfig.LedIp;
|
|
var port = (ushort)ServerConfig.LedPort;
|
|
LedZKManager = new LedZKManager(ip, port);
|
|
LedZKManager.StartServer();
|
|
}
|
|
|
|
public void CloseLedServer()
|
|
{
|
|
LedZKManager?.StopServer();
|
|
LedZKManager = null;
|
|
}
|
|
|
|
#endregion LedZKManager
|
|
|
|
#region FingerPrintManager
|
|
|
|
public void OpenFingerPrintServer()
|
|
{
|
|
FPManager = new FingerPrintManager();
|
|
FPManager.StartServer();
|
|
FPManager.SetVerBoxAble(true);//设置验证窗体开启
|
|
FPManager.SetVerTime(30 * 1000);//设置认证窗口超时时间
|
|
}
|
|
|
|
public void CloseFingerPrintServer()
|
|
{
|
|
FPManager?.StopServer();
|
|
FPManager = null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取特征指纹
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetVerFingerPrint()
|
|
{
|
|
var fp = string.Empty;
|
|
var stat = FPManager.GetVerFingerPrint(ref fp);
|
|
return stat ? fp : string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 比对指纹
|
|
/// </summary>
|
|
/// <param name="regFp"></param>
|
|
/// <param name="verFp"></param>
|
|
/// <returns></returns>
|
|
public bool MatchFingerPrint(string regFp, string verFp)
|
|
{
|
|
return FPManager.MatchFingerPrint(regFp, verFp);
|
|
}
|
|
|
|
#endregion FingerPrintManager
|
|
|
|
#region YkPosManager
|
|
|
|
public void OpenYkPosServer()
|
|
{
|
|
YkPosManager.OpenDevice();
|
|
}
|
|
|
|
public void CloseYkPosServer()
|
|
{
|
|
YkPosManager.CloseDevice();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 打印运单
|
|
/// </summary>
|
|
/// <param name="billEntity"></param>
|
|
public void PrintBill(TransportBillEntity billEntity)
|
|
{
|
|
if (!YkPosManager.IsConnected() || YkPosManager.IsPaperExhaust())
|
|
{
|
|
var msg = "打印接口纸尽,请联系管理人员";
|
|
_mainServer?.SetScrollLabelText(msg);
|
|
_mainServer?.ShowRecvMessage(msg);
|
|
return;
|
|
}
|
|
if (billEntity == null)
|
|
return;
|
|
|
|
YkPosManager.InitPrinter();
|
|
var bmpPath = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine("Img", "logo.bmp"));
|
|
YkPosManager.SetAlign(1);//居中
|
|
YkPosManager.PrintRasterBmp(new StringBuilder(bmpPath));//打印图片
|
|
|
|
//YkPosManager.InitPrinter();//重置
|
|
//YkPosManager.SetAlign(1);//居中
|
|
YkPosManager.SetEmphasized(1);//字体加粗
|
|
//YkPosManager.SetCharSize(1,1);//字体放大
|
|
YkPosManager.PrintStr(new StringBuilder($"{_mainServer.LocalAttrCenter.Company.F_FullName}\n"));//打印公司名
|
|
|
|
YkPosManager.InitPrinter();//重置
|
|
YkPosManager.SetAlign(1);//居中
|
|
YkPosManager.PrintStr(new StringBuilder("========================================\n"));//打印分隔符
|
|
|
|
//YkPosManager.InitPrinter();//重置
|
|
YkPosManager.SetAlign(0);//居左
|
|
YkPosManager.SetLeftMargin(8 * 8, 0);//设置左边距
|
|
var content = new StringBuilder();
|
|
content.Append($"场地:\t{billEntity.SiteName}\n");
|
|
content.Append($"运单号:\t{billEntity.SerialNumber}\n");
|
|
content.Append($"供应商:\t{billEntity.SupplierName}\n");
|
|
content.Append($"运输车:\t{billEntity.LicensePlate}\n");
|
|
content.Append($"挂车:\t{billEntity.TrailerPlate}\n");
|
|
content.Append($"运输员:\t{billEntity.DriverName}\n");
|
|
content.Append($"押运员:\t{billEntity.Driver2Name}\n");
|
|
content.Append($"料号:\t{billEntity.MaterialNo}\n");
|
|
YkPosManager.PrintStr(content);//打印内容
|
|
|
|
YkPosManager.InitPrinter();//重置
|
|
YkPosManager.SetAlign(1);//居中
|
|
YkPosManager.PrintStr(new StringBuilder("----------------------------------------\n"));//打印分隔符
|
|
|
|
//YkPosManager.InitPrinter();//重置
|
|
YkPosManager.SetAlign(0);//居左
|
|
YkPosManager.SetLeftMargin(8 * 8, 0);//设置左边距
|
|
content = new StringBuilder();
|
|
content.Append($"运单重量:\t{billEntity.BillWeight}吨\n");
|
|
content.Append($"入场重量:\t{billEntity.InWeight}吨\n");
|
|
content.Append($"出场重量:\t{billEntity.OutWeight}吨\n");
|
|
content.Append($"实际重量:\t{billEntity.NetWeight}吨\n");
|
|
content.Append($"达标率:\t{billEntity.StandardRate}%\n");
|
|
content.Append($"入场时间:\t{billEntity.InStartTime:yyyy/MM/dd HH:mm:ss}\n");
|
|
content.Append($"出场时间:\t{billEntity.OutFinishTime:yyyy/MM/dd HH:mm:ss}\n");
|
|
//content.Append($"运单状态:\t{BillStateExt.GetBillStateDesc(billEntity.State)}\n");
|
|
YkPosManager.PrintStr(content);//打印内容
|
|
|
|
YkPosManager.InitPrinter();//重置
|
|
YkPosManager.SetAlign(1);//居中
|
|
YkPosManager.PrintStr(new StringBuilder("========================================\n"));
|
|
|
|
//YkPosManager.InitPrinter();//重置
|
|
YkPosManager.SetAlign(2);//居右
|
|
//YkPosManager.PrintStr(new StringBuilder($"管理员:{user?.F_RealName}\n"));
|
|
YkPosManager.PrintStr(new StringBuilder($"出票时间:{DateTime.Now:yyyy/MM/dd HH:mm:ss}\n"));//打印页脚
|
|
|
|
YkPosManager.FeedPaper();//走纸,留空隙
|
|
YkPosManager.CutPaper();//切纸
|
|
}
|
|
|
|
#endregion YkPosManager
|
|
}
|
|
}
|