Browse Source

fix to hz

HuiZhou
fajiao 2 years ago
parent
commit
79439149f5
  1. 2
      AutoWeightServer/App.config
  2. 19
      AutoWeightServer/AutoWeightServer.csproj
  3. 125
      AutoWeightServer/Center/DeviceCenter.cs
  4. 1
      AutoWeightServer/IfManager/Light/ILightManager.cs
  5. 9
      AutoWeightServer/IfManager/Light/LightManager.cs
  6. 206
      AutoWeightServer/IfManager/Pos/PosManager.cs
  7. 274
      AutoWeightServer/IfManager/Pos/PosSDK.cs
  8. 1
      AutoWeightServer/IfManager/Scales/Scales.cs
  9. 45
      AutoWeightServer/IfManager/Scales/ScalesHuiZhou.cs
  10. 11
      AutoWeightServer/IfManager/Scales/ScalesManager.cs
  11. 20
      AutoWeightServer/IfManager/Scales/ScalesZhuHai.cs
  12. BIN
      AutoWeightServer/Img/logo.bmp
  13. 7
      AutoWeightServer/Model/Config/BaseConfig.cs
  14. 3
      AutoWeightServer/Model/Config/ServerConfig.cs
  15. 6
      AutoWeightServer/Program.cs
  16. 2
      AutoWeightServer/Properties/Resources.resx
  17. 0
      AutoWeightServer/Resources/title.ico
  18. 2
      AutoWeightServer/UI/FrmMainServer.cs
  19. 0
      AutoWeightServer/data/image/Thumbs.db
  20. BIN
      AutoWeightServer/data/image/logo.bmp
  21. 0
      AutoWeightServer/data/light/lightCode.json
  22. 0
      AutoWeightServer/data/light/lightCode2.json
  23. 0
      AutoWeightServer/data/light/lightCode3.json
  24. 0
      AutoWeightServer/data/light/lightCodeTemplate.json
  25. 0
      AutoWeightServer/data/voice.config
  26. BIN
      Debug.rar
  27. 2
      EC.Service/Transport/PhotoService.cs
  28. 7
      EC.Utils/CommonUtil.cs
  29. 1
      EC.Utils/EC.Utils.csproj
  30. 50
      EC.Utils/EnvUtil.cs
  31. BIN
      dll.rar

2
AutoWeightServer/App.config

@ -40,7 +40,7 @@
<!--指示灯继电器-->
<add key="Light_Relay_COM" value="COM4" />
<add key="Light_Relay_BaudRate" value="9600" />
<add key="Light_Code_Name" value="lightCode3.json" />
<add key="Light_Code_Name" value="lightCode2.json" />
<add key="Light_Interval" value="8000" />
<add key="Light_Blink" value="300" />
<!--Led控制-->

19
AutoWeightServer/AutoWeightServer.csproj

@ -57,7 +57,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>title.ico</ApplicationIcon>
<ApplicationIcon>Resources\title.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
@ -195,7 +195,10 @@
<Compile Include="IfManager\Light\ILightRelay.cs" />
<Compile Include="IfManager\Light\LightManager.cs" />
<Compile Include="IfManager\Light\LightRelay.cs" />
<Compile Include="IfManager\Pos\PosManager.cs" />
<Compile Include="IfManager\Pos\PosSDK.cs" />
<Compile Include="IfManager\Scales\Scales.cs" />
<Compile Include="IfManager\Scales\ScalesHuiZhou.cs" />
<Compile Include="IfManager\Scales\ScalesZhuHai.cs" />
<Compile Include="IfManager\Speech\SpeakHelper.cs" />
<Compile Include="IfManager\YkPos\YkPosManager.cs" />
@ -328,16 +331,16 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="conf\lightCodeTemplate.json">
<None Include="data\light\lightCodeTemplate.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="conf\lightCode3.json">
<None Include="data\light\lightCode3.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="conf\lightCode2.json">
<None Include="data\light\lightCode2.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="conf\lightCode.json">
<None Include="data\light\lightCode.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
@ -351,7 +354,7 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="Voice.config">
<None Include="data\voice.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
@ -433,11 +436,11 @@
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Img\logo.bmp">
<Content Include="data\image\logo.bmp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\title.ico" />
<None Include="Resources\重置.png" />
<None Include="title.ico" />
<None Include="Resources\指纹.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

125
AutoWeightServer/Center/DeviceCenter.cs

@ -1,6 +1,7 @@
using EC.AutoWeightServer.IfManager.FingerPrint;
using EC.AutoWeightServer.IfManager.LedZK;
using EC.AutoWeightServer.IfManager.Light;
using EC.AutoWeightServer.IfManager.Pos;
using EC.AutoWeightServer.IfManager.Scales;
using EC.AutoWeightServer.IfManager.YkPos;
using EC.AutoWeightServer.Model.Config;
@ -10,7 +11,6 @@ using EC.Entity.Transport;
using EC.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace EC.AutoWeightServer.Center
@ -32,7 +32,7 @@ namespace EC.AutoWeightServer.Center
/// <summary>
/// 灯光控制
/// </summary>
internal ILightManager LightManager { get; set; }
internal LightManager LightManager { get; set; }
/// <summary>
/// 指纹识别
@ -44,6 +44,8 @@ namespace EC.AutoWeightServer.Center
/// </summary>
internal LedZKManager LedZKManager { get; set; }
internal PosManager PosManager { get; set; }
public DeviceCenter()
{
}
@ -66,7 +68,8 @@ namespace EC.AutoWeightServer.Center
OpenLightServer();
OpenLedServer();
OpenFingerPrintServer();
OpenYkPosServer();
//OpenYkPosServer();
OpenPosServer();
}
public void CloseDevices()
@ -74,9 +77,10 @@ namespace EC.AutoWeightServer.Center
//CloseCameraServer();
//CloseWeightServer();
//CloseLightServer();
//CloseLedServer();
//CloseFingerPrintServer();
//CloseYkPosServer();
//CloseLedServer();
//OpenPosServer();
}
public void CheckDevicesConnect()
@ -98,13 +102,24 @@ namespace EC.AutoWeightServer.Center
msgList.Add("指纹接口未连接");
if (LedZKManager == null || !LedZKManager.IsConnected())
msgList.Add("Led屏未连接");
if (!YkPosManager.IsConnected())
//if (!YkPosManager.IsConnected())
//{
// msgList.Add("打印接口未连接");
//}
//else
//{
// if (YkPosManager.IsPaperExhaust())
// msgList.Add("打印接口纸尽");
// //if (YkPosManager.IsPaperWillExhaust())
// // msgList.Add("打印接口纸将尽");
//}
if (!PosManager.IsConnected())
{
msgList.Add("打印接口未连接");
}
else
{
if (YkPosManager.IsPaperExhaust())
if (PosManager.IsPaperExhaust())
msgList.Add("打印接口纸尽");
//if (YkPosManager.IsPaperWillExhaust())
// msgList.Add("打印接口纸将尽");
@ -308,6 +323,8 @@ namespace EC.AutoWeightServer.Center
/// <param name="billEntity"></param>
public void PrintBill(TransportBillEntity billEntity)
{
if (billEntity == null)
return;
if (!YkPosManager.IsConnected() || YkPosManager.IsPaperExhaust())
{
var msg = "打印接口纸尽,请联系管理人员";
@ -315,11 +332,9 @@ namespace EC.AutoWeightServer.Center
_mainServer?.ShowRecvMessage(msg);
return;
}
if (billEntity == null)
return;
YkPosManager.InitPrinter();
var bmpPath = Path.Combine(CommonUtil.GetWorkDirectory(), Path.Combine("Img", "logo.bmp"));
var bmpPath = EnvUtil.CombinePath(EnvUtil.GetWorkDirectory(), "data", "image", "logo.bmp");
YkPosManager.SetAlign(1);//居中
YkPosManager.PrintRasterBmp(new StringBuilder(bmpPath));//打印图片
@ -379,5 +394,97 @@ namespace EC.AutoWeightServer.Center
}
#endregion YkPosManager
#region PosManager
public void OpenPosServer()
{
PosManager = new PosManager();
PosManager.OpenDevice(PosSDK.POS_PT_USB);
}
public void ClosePosServer()
{
PosManager?.CloseDevice();
PosManager = null;
}
public void PrintBIll(TransportBillEntity billEntity)
{
if (PosManager == null || billEntity == null)
return;
if (!PosManager.IsConnected() || PosManager.IsPaperExhaust())
{
var msg = "打印接口纸尽,请联系管理人员";
_mainServer?.SetScrollLabelText(msg);
_mainServer?.ShowRecvMessage(msg);
return;
}
// 初始化
PosManager.InitPrinter();
// 打印票头
string bmpPath2 = EnvUtil.CombinePath(EnvUtil.GetWorkDirectory(), "data", "image", "logom.bmp");
if (!EnvUtil.ExistFile(bmpPath2))
{
string bmpPath1 = EnvUtil.CombinePath(EnvUtil.GetWorkDirectory(), "data", "image", "logo.bmp");
PosManager.Color24_GrayBW(bmpPath1, bmpPath2);
}
PosManager.PrintBmp(bmpPath2);
// 缓冲区
byte[] cmd = new byte[] { 0x1c, 0x26 };
PosManager.PrintData(cmd, 2);
// 打印公司
PosManager.SetAlign(1);
PosManager.PrintStr(0, 1, 0, 0, 0, $"{_mainServer.LocalAttrCenter.Company.F_FullName}\r\n");
// 打印分隔符
PosManager.PrintStr(0, 0, 0, 0, 0, "================================\r\n");
// 打印运单信息
PosManager.SetAlign(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");
PosManager.PrintStr(0, 0, 0, 0, 0, content.ToString());
// 打印分隔符
PosManager.SetAlign(1);
PosManager.PrintStr(0, 0, 0, 0, 0, "--------------------------------\r\n");
// 打印进出场信息
PosManager.SetAlign(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");
PosManager.PrintStr(0, 0, 0, 0, 0, content.ToString());
//打印分隔符
PosManager.SetAlign(1);
PosManager.PrintStr(0, 0, 0, 0, 0, "================================\r\n");
//打印票尾
PosManager.SetAlign(2);
//PosManager.PrintStr(0, 0, 0, 0, 0,$"管理员:{user?.F_RealName}\n");
PosManager.PrintStr(0, 0, 0, 0, 0, $"出票时间:{DateTime.Now:yyyy/MM/dd HH:mm:ss}\r\n");
PosManager.InitPrinter();
//切纸
PosManager.CutPaper(1, 3);
}
#endregion PosManager
}
}

1
AutoWeightServer/IfManager/Light/ILightManager.cs

@ -27,6 +27,5 @@
public bool LockLightOff(int index);
#endregion Control Lights
}
}

9
AutoWeightServer/IfManager/Light/LightManager.cs

@ -22,7 +22,7 @@ namespace EC.AutoWeightServer.IfManager.Light
_baudRate = baudRate;
_fileName = fileName;
ReadLightCodeJson();
_readCodeFlag = ReadLightCodeJson();
}
#region Start & Stop Server
@ -58,6 +58,8 @@ namespace EC.AutoWeightServer.IfManager.Light
#region Control Lights Code
private bool _readCodeFlag;
/// <summary>
/// 控制所有灯编码,1 为开启所有灯,2 为关闭所有灯
/// </summary>
@ -95,6 +97,11 @@ namespace EC.AutoWeightServer.IfManager.Light
return true;
}
public bool IsReadCodeSuccess()
{
return _readCodeFlag;
}
#endregion Control Lights Code
#region Control Lights

206
AutoWeightServer/IfManager/Pos/PosManager.cs

@ -0,0 +1,206 @@
namespace EC.AutoWeightServer.IfManager.Pos
{
public class PosManager
{
private int _portType { get; set; }//0 COM,1 LPT ,2 USB 3 ETH
private int _printer { get; set; }
private int _bitmapType { get; set; }
private int _paperType { get; set; } = 1; //0 88m 1 58m 2 76m
private int _result { get; set; }
public PosManager()
{
}
/// <summary>
/// 打开设备
/// </summary>
/// <param name="portType"></param>
/// <param name="bFile"></param>
/// <param name="path"></param>
/// <returns></returns>
public bool OpenDevice(int portType, bool bFile = false, string path = "")
{
string lpName;
_portType = portType;
switch (portType)
{
case PosSDK.POS_PT_COM:
lpName = "COM1:9600,N,8,1";
break;
case PosSDK.POS_PT_LPT:
lpName = "LPT1";
break;
case PosSDK.POS_PT_USB:
lpName = "SP-USB1";
break;
case PosSDK.POS_PT_NET:
lpName = "192.168.1.114";
break;
default:
lpName = "SP-USB1";
portType = PosSDK.POS_PT_USB;
break;
}
_printer = PosSDK.POS_Port_OpenA(lpName, portType, bFile, path);
SetResult(_printer);
return _printer >= 0;
}
/// <summary>
/// 关闭设备
/// </summary>
/// <returns></returns>
public bool CloseDevice()
{
int ret = PosSDK.POS_Port_Close(_printer);
SetResult(ret);
_printer = PosSDK.POS_ES_INVALIDPARA;
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 设备是否连接
/// </summary>
/// <returns></returns>
public bool IsConnected()
{
return _printer >= 0;
}
public int GetResult()
{
return _result;
}
private void SetResult(int ret)
{
_result = ret;
}
/// <summary>
/// 初始化打印机
/// </summary>
/// <returns></returns>
public bool InitPrinter()
{
int ret = PosSDK.POS_Control_ReSet(_printer);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 选择字符对齐(居左/居中/居右)方式
/// </summary>
/// <param name="alignType">0:左对齐,1:居中,2:右对齐</param>
/// <returns></returns>
public bool SetAlign(int alignType)
{
int ret = PosSDK.POS_Control_AlignType(_printer, alignType);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 设置打印左边距和打印区域
/// </summary>
/// <param name="iLeft">设置左边距,默认值为 0</param>
/// <param name="iWidth">设置打印区域,默认值为 0</param>
/// <returns></returns>
public bool SetLeftMargin(int iLeft, int iWidth)
{
int ret = PosSDK.POS_Control_SetPrintPosition(_printer, iLeft, iWidth);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 缓冲数据
/// </summary>
/// <param name="strBuff"></param>
/// <param name="ilen"></param>
/// <returns></returns>
public bool PrintData(byte[] strBuff, int ilen)
{
int ret = PosSDK.POS_Output_PrintData(_printer, strBuff, ilen);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 打印本地单色位图
/// </summary>
/// <param name="bmpPath">本地单色位图存储路径</param>
/// <returns></returns>
public bool PrintBmp(string bmpPath)
{
int ret = PosSDK.POS_Output_PrintBmpDirectA(_printer, bmpPath);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 打印格式化后的字符串
/// </summary>
/// <param name="iFont">0:选择标准 ASCII 字体A(12×24),1:选择压缩 ASCII 字体B(9×17)</param>
/// <param name="iThick">0:取消加粗模式,1:选择加粗模式</param>
/// <param name="iWidth">0:取消倍宽模式,1:选择倍宽模式</param>
/// <param name="iHeight">0:取消倍高模式,1:选择倍高模式</param>
/// <param name="iUnderLine">0:取消下划线模式,1:选择下划线模式</param>
/// <param name="lpstring">以空字符结尾的字符串</param>
/// <returns></returns>
public bool PrintStr(int iFont, int iThick, int iWidth, int iHeight, int iUnderLine, string lpstring)
{
int ret = PosSDK.POS_Output_PrintFontStringA(_printer, iFont, iThick, iWidth, iHeight, iUnderLine, lpstring);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 打印缓冲区内容,进纸由参数 iLines 设置的行数并切纸
/// </summary>
/// <param name="type">0:全切,1:半切</param>
/// <param name="len">进纸行数</param>
/// <returns></returns>
public bool CutPaper(int type = 0, int len = 1)
{
int ret = PosSDK.POS_Control_CutPaper(_printer, type, len);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
public bool Color24_GrayBW(string path1, string path2)
{
int ret = PosSDK.Color24_GrayBW(path1, path2);
SetResult(ret);
return ret == PosSDK.POS_ES_SUCCESS;
}
/// <summary>
/// 是否纸尽
/// </summary>
/// <returns></returns>
public bool IsPaperExhaust()
{
int ret = PosSDK.POS_Status_RTQueryTypeStatus(_printer, 4);
SetResult(ret);
return ret == PosSDK.POS_ES_PAPEROUT;
}
/// <summary>
/// 是否将纸尽
/// </summary>
/// <returns></returns>
public bool IsPaperWillExhaust()
{
int ret = PosSDK.POS_Status_RTQueryTypeStatus(_printer, 4);
SetResult(ret);
return ret == PosSDK.POS_ES_PAPERENDING;
}
}
}

274
AutoWeightServer/IfManager/Pos/PosSDK.cs

@ -0,0 +1,274 @@
using System.Runtime.InteropServices;
using System.Text;
namespace EC.AutoWeightServer.IfManager.Pos
{
public class PosSDK
{
#region Custom
public struct PosParam
{
private string lpName;
private string portType;
private bool bFile;
private string path;
}
#endregion Custom
#region Const
// pritner connect way
public const int POS_PT_COM = 1000;
public const int POS_PT_LPT = 1001;
public const int POS_PT_USB = 1002;
public const int POS_PT_NET = 1003;
// printer state
public const int POS_PS_NORMAL = 3001;
public const int POS_PS_PAPEROUT = 3002;
public const int POS_PS_HEAT = 3003;
public const int POS_PS_DOOROPEN = 3004;
public const int POS_PS_BUFFEROUT = 3005;
public const int POS_PS_CUT = 3006;
public const int POS_PS_DRAWERHIGH = 3007;
public const int POS_ES_PAPERENDING = 6; //纸将尽
public const int POS_ES_DRAWERHIGH = 5; //钱箱高电平
public const int POS_ES_CUT = 4; //切刀未复位
public const int POS_ES_DOOROPEN = 3; //纸仓门开
public const int POS_ES_HEAT = 2; //机头过热
public const int POS_ES_PAPEROUT = 1; //打印机缺纸
public const int POS_ES_SUCCESS = 0; //成功/发送成功/状态正常/打印完成
public const int POS_ES_INVALIDPARA = -1; //参数错误
public const int POS_ES_WRITEFAIL = -2; //写失败
public const int POS_ES_READFAIL = -3; //读失败
public const int POS_ES_NONMONOCHROMEBITMAP = -4; //非单色位图
public const int POS_ES_OVERTIME = -5; //超时/写超时/读超时/打印未完成
public const int POS_ES_FILEOPENERROR = -6; //文件/图片打开失败
public const int POS_ES_OTHERERRORS = -100; //其他原因导致的错误
// barcode type
public const int POS_BT_UPCA = 4001;
public const int POS_BT_UPCE = 4002;
public const int POS_BT_JAN13 = 4003;
public const int POS_BT_JAN8 = 4004;
public const int POS_BT_CODE39 = 4005;
public const int POS_BT_ITF = 4006;
public const int POS_BT_CODABAR = 4007;
public const int POS_BT_CODE93 = 4073;
public const int POS_BT_CODE128 = 4074;
// 2D barcode type
public const int POS_BT_PDF417 = 4100;
public const int POS_BT_DATAMATRIX = 4101;
public const int POS_BT_QRCODE = 4102;
// HRI type
public const int POS_HT_NONE = 4011;
public const int POS_HT_UP = 4012;
public const int POS_HT_DOWN = 4013;
public const int POS_HT_BOTH = 4014;
//TSPL
public const int TSPL_PRINTER_STATUS_OUTPAPER = 1;//打印机缺纸
public const int TSPL_PRINTER_STATUS_WORK = 2; //打印中
public const int TSPL_PRINTER_STATUS_ENCLOSURENOCLOSE = 3; //机壳未关
public const int TSPL_PRINTER_STATUS_ERROR = 4; //打印机内部错误
public const int TSPL_PARAM_LESS_EQUAL_ZERO = -2; //参数小于等于0
public const int TSPL_PARAM_GREAT_RANGE = -3; //参数大于指定范围
public const int TSPL_SUCCESS = 0;
public const int TSPL_IDERROR = -1;
#endregion Const
#region Method
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Port_OpenA")]
public static extern int POS_Port_OpenA(string lpName, int iPort, bool bFile, string path);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintstringA")]
public static extern int POS_Output_PrintstringA(int printID, string strBuff);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintData")]
public static extern int POS_Output_PrintData(int printID, byte[] strBuff, int ilen);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Port_Close")]
public static extern int POS_Port_Close(int printID);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_CutPaper")]
public static extern int POS_Control_CutPaper(int printID, int type, int len);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_CashDraw")]
public static extern int POS_Control_CashDraw(int printID, int iNum, int time1, int time2);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Status_QueryStatus")]
public static extern int POS_Status_QueryStatus(int printID);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Status_RTQueryStatus")]
public static extern int POS_Status_RTQueryStatus(int printID);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Status_RTQueryTypeStatus")]
public static extern int POS_Status_RTQueryTypeStatus(int printID, int n);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_DownloadBmpToFlashA")]
public static extern int POS_Output_DownloadBmpToFlashA(int printID, string strPath);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_DownloadBmpToFlashNumA")]
public static extern int POS_Control_DownloadBmpToFlashNumA(int printID, string strPath, int num);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintBmpDirectA")]
public static extern int POS_Output_PrintBmpDirectA(int printID, string strPath);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintFontStringA")]
public static extern int POS_Output_PrintFontStringA(int printID, int iFont, int iThick, int iWidth, int iHeight, int iUnderLine, string lpString);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Input_PrinterId")]
public static extern int POS_Input_PrinterId(int printID, StringBuilder Buff);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_BlackMark")]
public static extern int POS_Control_BlackMark(int printID);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_SetPrintPosition")]
public static extern int POS_Control_SetPrintPosition(int printID, int iLeft, int iWidth);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Status_QueryTaskStatus")]
public static extern int POS_Status_QueryTaskStatus(int printID, int second);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintFlashBmp")]
public static extern int POS_Output_PrintFlashBmp(int printID, int n);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintOneDimensionalBarcodeA")]
public static extern int POS_Output_PrintOneDimensionalBarcodeA(int printID, int iType, int iWidth, int iHeight, int hri, string lpstring);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintTwoDimensionalBarcodeA")]
public static extern int POS_Output_PrintTwoDimensionalBarcodeA(int printID, int iType, int parameter1, int parameter2, int parameter3, string lpstring);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_DownloadRamBmpA")]
public static extern int POS_Output_DownloadRamBmpA(int printID, string lpFilePath);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_PrintRamBmp")]
public static extern int POS_Output_PrintRamBmp(int printID, int n);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_PrintTestpage")]
public static extern int POS_Control_PrintTestpage(int printID);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "Color24_GrayBW")]
public static extern int Color24_GrayBW(string szSourceFile, string szTargetFile);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_SetRotaryPrint")]
public static extern int POS_Control_SetRotaryPrint(int printID, int n);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_OppositeColor")]
public static extern int POS_Control_OppositeColor(int printID, bool bOppsite);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_AlignType")]
public static extern int POS_Control_SetRotaryPrint(int printID, bool iAlignType);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Output_SendLocalFileA")]
public static extern int POS_Output_SendLocalFileA(int printID, string lpFilePath);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_ReSet")]
public static extern int POS_Control_ReSet(int printID);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_SetPrintFontC")]
public static extern int POS_Control_SetPrintFontC(int printID, bool iDoubleWidth, bool iDoubleHeight, bool iUnderLine);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_SetInvertedPrint")]
public static extern int POS_Control_SetInvertedPrint(int printID, int n);
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "POS_Control_AlignType")]
public static extern int POS_Control_AlignType(int printID, int iAlignType);
//--------------ztongli.20170123--------------
//设置页宽页高
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "PageSetupTSPL")]
public static extern int PageSetupTSPL(int printID, int PageWidth, int PageHeight);
//画线
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "DrawLineTSPL")]
public static extern int DrawLineTSPL(int printID, int StartX, int StartY, int LineWidth, int LineHeight);
//TL51打印
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "PrintTSPL")]
public static extern int PrintTSPL(int printID, int Set, int Copy);
//画矩形
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "DrawBorderTSPL")]
public static extern int DrawBorderTSPL(int printID, int LineWidth, int top_left_x, int top_left_y, int bottom_right_x, int bottom_right_y);
//文字
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "DrawTextTSPL")]
public static extern int DrawTextTSPL(int printID, int start_x, int start_y, bool isSimplifiedChinese, int xMultiplication, int yMultiplication, int rotate, string content);
//一维条码
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "DrawBarCodeTSPL")]
public static extern int DrawBarCodeTSPL(int printID, int start_x, int start_y, string type, int height, bool isReadable, int rotate, int narrowWidth, int wideWidth, string content);
////清空缓冲区
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "ClearBuffTSPL")]
public static extern int ClearBuffTSPL(int printID);
//二维条码
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "Draw2DBarCodeTSPL")]
public static extern int Draw2DBarCodeTSPL(int printID, int start_x, int start_y, string Max, string content);
//下载位图
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "DownLoadBitMapTSPL")]
public static extern int DownLoadBitMapTSPL(int printID, bool isMoveFlash, string PathName);
//将图片刷到缓冲区
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "PutBitMapTSPL")]
public static extern int PutBitMapTSPL(int printID, int start_x, int start_y, string fileName);
//得到打印机状态
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "GetPrinterStatusTSPL")]
public static extern int GetPrinterStatusTSPL(int printID);
//控制蜂鸣器发出一声响
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "DriveBeepTSPL")]
public static extern int DriveBeepTSPL(int printID);
//设置国际字符集
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "SetCharsetNameTSPL")]
public static extern int SetCharsetNameTSPL(int printID, string CharsetName);
//控制进纸或退纸距离
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "SetPaperbackOrPaperFeedTSPL")]
public static extern int SetPaperbackOrPaperFeedTSPL(int printID, bool isFeedBack, int mDot);
//指定的区域反相打印命令
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "ReverseAreaTSPL")]
public static extern int ReverseAreaTSPL(int printID, int start_x, int start_y, int width, int height);
//选择字符代码页
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "SelectCodePageTSPL")]
public static extern int SelectCodePageTSPL(int printID, int value);
//设置标签间垂直间距
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "SetGAPTSPL")]
public static extern int SetGAPTSPL(int printID, double value);
//定义标签的参考坐标原点命令
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "SetLabelReferenceTSPL")]
public static extern int SetLabelReferenceTSPL(int printID, int x, int y);
//TL21打印
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "PrintTSPL21")]
public static extern int PrintTSPL21(int printID, int Set);
//用于确认机型是TL21便于内部区别指令以及相关条件
[DllImport("POS_SDK.dll", CharSet = CharSet.Ansi, EntryPoint = "SetIs21")]
public static extern int SetIs21();
#endregion Method
}
}

1
AutoWeightServer/IfManager/Scales/Scales.cs

@ -19,6 +19,7 @@ namespace EC.AutoWeightServer.IfManager.Scales
{
this.ComName = comName;
this.BaudRate = baudRate;
this.ReceivedBytesThreshold = 32;
}
public Scales(string comName, int baudRate, int receivedBytesThreshold)

45
AutoWeightServer/IfManager/Scales/ScalesHuiZhou.cs

@ -0,0 +1,45 @@
using EC.AutoWeightServer.Model.Config;
using EC.AutoWeightServer.Model.EventArgsEx;
using EC.Utils;
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace EC.AutoWeightServer.IfManager.Scales
{
public class ScalesHuiZhou : Scales
{
public ScalesHuiZhou(string comName, int baudRate, int receivedBytesThreshold) : base(comName, baudRate, receivedBytesThreshold)
{
}
public override event EventHandler<ScaleEventArgs> OnRecData;
public event EventHandler<byte[]> OnRecTransmit = null;
public override void RecData(object sender, byte[] buf)
{
OnRecTransmit?.Invoke(sender, buf);
string tempBuf = Encoding.UTF8.GetString(buf);
string[] splitBufArray = tempBuf.Split('\r');
foreach (var item in splitBufArray)
{
if (item.Length != 16) { continue; }
tempBuf = item;
MatchCollection mc = Regex.Matches(tempBuf, @"(\d+)");
if (mc.Count != 3) { continue; }
string weightArg = mc[1].Value;
decimal weight = CommonUtil.WeightStrToDec(weightArg) / 1000;
string unit = "t";
var scaleArgs = new ScaleEventArgs(weight, unit);
OnRecData?.Invoke(sender, scaleArgs);
break;
}
if (ServerConfig.WTDiscardInBufferFlag > 0)
_port.DiscardInBuffer();
}
}
}

11
AutoWeightServer/IfManager/Scales/ScalesManager.cs

@ -1,7 +1,7 @@
using EC.AutoWeightServer.Model.EventArgsEx;
using EC.AutoWeightServer.Model.Config;
using EC.AutoWeightServer.Model.EventArgsEx;
using EC.Utils.SerialPortHelper;
using System;
using EC.AutoWeightServer.Model.Config;
namespace EC.AutoWeightServer.IfManager.Scales
{
@ -11,7 +11,7 @@ namespace EC.AutoWeightServer.IfManager.Scales
private string _comName;
private int _baudRate;
private int _receivedBytesThreshold;
private ECSerialPort _transmitPort;
private ECSerialPort _transmitPort;
public ScalesManager()
{
@ -34,13 +34,12 @@ namespace EC.AutoWeightServer.IfManager.Scales
public bool StartServer()
{
//Scales = new ScalesDefault(_comName, _baudRate);
Scales = new ScalesZhuHai(_comName, _baudRate, _receivedBytesThreshold);
Scales = new ScalesHuiZhou(_comName, _baudRate, _receivedBytesThreshold);
Scales.OnRecData += RecData;
if (ServerConfig.WtTransmitFlag > 0)
{
_transmitPort = SerialPortManager.CreateSerialPort(ServerConfig.WtTransmitCom, _baudRate);
((ScalesZhuHai)Scales).OnRecTransmit += RecTransmit;
((ScalesHuiZhou)Scales).OnRecTransmit += RecTransmit;
}
Scales.StartServer();
return true;

20
AutoWeightServer/IfManager/Scales/ScalesZhuHai.cs

@ -1,31 +1,19 @@
using EC.AutoWeightServer.Model.EventArgsEx;
using EC.AutoWeightServer.Model.Config;
using EC.AutoWeightServer.Model.EventArgsEx;
using EC.Utils;
using System;
using System.Text;
using EC.AutoWeightServer.Model.Config;
namespace EC.AutoWeightServer.IfManager.Scales
{
public class ScalesZhuHai : Scales
{
public ScalesZhuHai()
public ScalesZhuHai(string comName, int baudRate, int receivedBytesThreshold) : base(comName, baudRate, receivedBytesThreshold)
{
}
public ScalesZhuHai(string comName, int baudRate)
{
this.ComName = comName;
this.BaudRate = baudRate;
}
public ScalesZhuHai(string comName, int baudRate, int receivedBytesThreshold)
{
this.ComName = comName;
this.BaudRate = baudRate;
this.ReceivedBytesThreshold = receivedBytesThreshold;
}
public override event EventHandler<ScaleEventArgs> OnRecData;
public event EventHandler<byte[]> OnRecTransmit = null;
public override void RecData(object sender, byte[] buf)

BIN
AutoWeightServer/Img/logo.bmp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

7
AutoWeightServer/Model/Config/BaseConfig.cs

@ -1,4 +1,5 @@
using System.Configuration;
using EC.Utils;
using System.Configuration;
namespace EC.AutoWeightServer.Model.Config
{
@ -51,7 +52,9 @@ namespace EC.AutoWeightServer.Model.Config
#region Voice.config
private static readonly Configuration VoiceConfig = GetConfiguration("Voice.config");
private static readonly string VoiceConfigPath = EnvUtil.CombinePath(EnvUtil.GetWorkDirectory(), "data", "voice.config");
private static readonly Configuration VoiceConfig = GetConfiguration(VoiceConfigPath);
public static string GetVoiceConfig(string key)
{

3
AutoWeightServer/Model/Config/ServerConfig.cs

@ -15,7 +15,6 @@ namespace EC.AutoWeightServer.Model.Config
/// 相机
/// </summary>
public static string CameraAddress1 { get; } = GetAppConfig("CAMERA_ADDRESS1");
public static string CameraAddress2 { get; } = GetAppConfig("CAMERA_ADDRESS2");
public static string CameraAddress3 { get; } = GetAppConfig("CAMERA_ADDRESS3");
public static string CameraAddress4 { get; } = GetAppConfig("CAMERA_ADDRESS4");
@ -45,7 +44,7 @@ namespace EC.AutoWeightServer.Model.Config
public static string LightRelayCom { get; } = GetAppConfig("Light_Relay_COM");
public static int LightRelayBaudRate { get; } = FormatCom.ToInt(GetAppConfig("Light_Relay_BaudRate"));
public static string LightCodeName { get; } = Path.Combine(CommonUtil.GetWorkDirectory(), "conf", GetAppConfig("Light_Code_Name"));
public static string LightCodeName { get; } = Path.Combine(EnvUtil.GetWorkDirectory(), "data", "light", GetAppConfig("Light_Code_Name"));
public static int LightInterval { get; } = FormatCom.ToInt(GetAppConfig("Light_Interval"));
public static int LightBlink { get; } = FormatCom.ToInt(GetAppConfig("Light_Blink"));

6
AutoWeightServer/Program.cs

@ -1,9 +1,8 @@
using EC.AutoWeightServer.UI;
using EC.Utils;
using EC.Utils.Storage;
using System;
using System.Data.SqlClient;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
@ -20,7 +19,8 @@ namespace EC.AutoWeightServer
[STAThread]
private static void Main()
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
EnvUtil.InitWorkDirectory();
EnvUtil.AddDllPath(EnvUtil.CombinePath(EnvUtil.GetWorkDirectory(), "dll"));
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

2
AutoWeightServer/Properties/Resources.resx

@ -303,7 +303,7 @@
<value>..\Resources\指纹.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="title" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\title.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<value>..\Resources\title.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="重置" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\重置.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>

0
AutoWeightServer/title.ico → AutoWeightServer/Resources/title.ico

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

2
AutoWeightServer/UI/FrmMainServer.cs

@ -994,7 +994,7 @@ namespace EC.AutoWeightServer.UI
private void CheckPhotoSaveCycle()
{
var now = DateTime.Now;
var workPath = CommonUtil.GetWorkDirectory();
var workPath = EnvUtil.GetWorkDirectory();
var capDir = new DirectoryInfo(Path.Combine(workPath, "cap"));
if (!capDir.Exists)
return;

0
AutoWeightServer/Img/Thumbs.db → AutoWeightServer/data/image/Thumbs.db

BIN
AutoWeightServer/data/image/logo.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

0
AutoWeightServer/conf/lightCode.json → AutoWeightServer/data/light/lightCode.json

0
AutoWeightServer/conf/lightCode2.json → AutoWeightServer/data/light/lightCode2.json

0
AutoWeightServer/conf/lightCode3.json → AutoWeightServer/data/light/lightCode3.json

0
AutoWeightServer/conf/lightCodeTemplate.json → AutoWeightServer/data/light/lightCodeTemplate.json

0
AutoWeightServer/Voice.config → AutoWeightServer/data/voice.config

BIN
Debug.rar

Binary file not shown.

2
EC.Service/Transport/PhotoService.cs

@ -40,7 +40,7 @@ namespace EC.Service.Transport
public static string GetSaveImagePath(string license)
{
var now = DateTime.Now;
var workPath = CommonUtil.GetWorkDirectory();
var workPath = EnvUtil.GetWorkDirectory();
var subPath = Path.Combine(new string[] { "cap", now.ToString("yyyy"), now.ToString("MM"), now.ToString("dd") });
//var subPath = Path.Combine("cap", now.ToString("yyyy-MM-dd"));
var fileFolder = Path.Combine(workPath, subPath);

7
EC.Utils/CommonUtil.cs

@ -218,12 +218,5 @@ namespace EC.Utils
}
}
private static string workDirectory;
public static string GetWorkDirectory()
{
workDirectory = string.IsNullOrEmpty(workDirectory) ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : workDirectory;
return workDirectory;
}
}
}

1
EC.Utils/EC.Utils.csproj

@ -82,6 +82,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="EnvUtil.cs" />
<Compile Include="FileUnitEx.cs" />
<Compile Include="CommonUtil.cs" />
<Compile Include="ConvertEx\CharHelper.cs" />

50
EC.Utils/EnvUtil.cs

@ -0,0 +1,50 @@
using System;
using System.IO;
using System.Reflection;
namespace EC.Utils
{
public class EnvUtil
{
private static string workDirectory;
public static void InitWorkDirectory()
{
Directory.SetCurrentDirectory(GetWorkDirectory());
}
public static string GetWorkDirectory()
{
workDirectory = string.IsNullOrEmpty(workDirectory) ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : workDirectory;
return workDirectory;
}
public static bool AddDllPath(string dllPath)
{
if (!Directory.Exists(dllPath)) { return false; }
string envPath = Environment.GetEnvironmentVariable("PATH");
Environment.SetEnvironmentVariable("PATH", envPath + ";" + dllPath);
return true;
}
public static string CombinePath(string path1, string path2)
{
return Path.Combine(path1, path2);
}
public static string CombinePath(params string[] paths)
{
return Path.Combine(paths);
}
public static bool ExistFile(string file)
{
return File.Exists(file);
}
public static bool ExistDirectory(string dir)
{
return Directory.Exists(dir);
}
}
}

BIN
dll.rar

Binary file not shown.
Loading…
Cancel
Save