fajiao
2 years ago
31 changed files with 734 additions and 59 deletions
@ -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; |
|||
} |
|||
} |
|||
} |
@ -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
|
|||
} |
|||
} |
@ -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(); |
|||
} |
|||
} |
|||
} |
Before Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
@ -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); |
|||
} |
|||
} |
|||
} |
Binary file not shown.
Loading…
Reference in new issue