using System.Runtime.InteropServices;
using System.Text;
namespace POSV.Printer
{
public class YkPosDll
{
///
/// 连接打印机设备
///
/// 设备通信接口号,如COM1 - 1 COM2 - 2 如此类推
/// 波特率 9600 , 38400 , 115200
/// 0 -- 成功 -1 -- 失败
[DllImport("YkPosdll.dll")]
public static extern int YkOpenDevice(int iport , int baud);
///
/// 断开打印设备
///
/// 0 -- 成功 -1 -- 失败
[DllImport("YkPosdll.dll")]
public static extern int YkCloseDevice();
///
/// 获取设备的操作句柄
///
///
[DllImport("YkPosdll.dll")]
public static extern int YkGetDeviceHandle();
///
/// 设备是否已经到连接计算机(仅支持USB口打印机)
///
/// >0 -- 连接 -1 -- 没有连接
[DllImport("YkPosdll.dll")]
public static extern int YkIsConnected();
///
/// 初始化打印机 〈详见命令:ESC @〉
///
/// 0 -- 成功 -1 -- 失败
[DllImport("YkPosdll.dll")]
public static extern int YkInitPrinter();
///
/// 把将要打印的字符串送入打印机缓冲区(注: 达到满行时会自动打印出来)
///
/// 将要送打印机的字符串数据缓冲
///
[DllImport("YkPosdll.dll" , CharSet = CharSet.Ansi , EntryPoint = "YkPrintStr" , CallingConvention = CallingConvention.StdCall)]
public static extern int YkPrintStr([MarshalAs(UnmanagedType.LPStr)]StringBuilder pstr);
[DllImport("YkPosdll.dll" , CharSet = CharSet.Ansi , EntryPoint = "YkPrintRasterBmp" , CallingConvention = CallingConvention.StdCall)]
public static extern int YkPrintRasterBmp(string bmpfile);
[DllImport("YkPosdll.dll" , CharSet = CharSet.Ansi , EntryPoint = "YkDownloadBitmapAndPrint" , CallingConvention = CallingConvention.StdCall)]
public static extern int YkDownloadBitmapAndPrint(string bmpfile,int m);
///
/// 打印并换行,走纸到下一行首〈详见命令:LF〉
///
///
[DllImport("YkPosdll.dll")]
public static extern int YkFeedPaper();
///
/// 获取打印机状态, 〈详见命令:DLE EOT n〉
///
/// n = 1~5
/// 0 -- 成功 -1 -- 失败
[DllImport("YkPosdll.dll")]
public static extern int YkGetStatus(byte n);
[DllImport("YkPosdll.dll")]
public static extern int YkGetPrinterStatus(byte n);
///
/// 执行切纸动作,包括进纸 〈详见命令:GS V m〉
///
/// m=66 n:打印机进纸到(切纸位置+ [n × 0.125 毫米{0.0049英寸}])并切纸
/// 一般n=0
/// 0 -- 成功 -1 -- 失败
[DllImport("YkPosdll.dll")]
public static extern int YkCutPaper(int m , int n);
///
/// 设置钱箱驱动方式 〈详见命令: ESC p m t1 t2〉
///
/// 使用那个管脚输出脉冲 m=0 2脚 m=1 5脚 脉冲宽度为 t1*2ms t2*2ms ,其中要求 t1 < t2 ,一般 t1=150 t2=250
///
///
///
[DllImport("YkPosdll.dll")]
public static extern int YkSetCashBoxDriveMode(int m , int t1 , int t2);
}
}