码迷,mamicode.com
首页 > Windows程序 > 详细

那些年,用C#调用过的外部Dll

时间:2017-08-03 22:43:50      阅读:597      评论:0      收藏:0      [点我收藏+]

标签:har   签名   bitmap   序列号   进制   one   编程   dll导出   direction   

经常有人找到我咨询以前在csdn资源里分享的dll调用。算算也写过N多接口程序。翻一翻试试写篇随笔。

  • 明华IC读写器DLL
  • 爱迪尔门锁接口DLL
  • 通用OPOS指令打印之北洋pos打印机dll
  • 明泰非接触式RF读写器DLL

还有很多,以后补上。大多找不到了。也是懒得找了。

先抄点名词解释

DllImport是System.Runtime.InteropServices命名空间下的一个属性类,其功能是提供从非托管DLL导出的函数的必要调用信息。
DllImport属性应用于方法,要求最少要提供包含入口点的dll的名称。
DllImport的定义如下:

[AttributeUsage(AttributeTargets.Method)]
  public class DllImportAttribute: System.Attribute
  {
   public DllImportAttribute(string dllName) {…} //定位参数为dllName
   public CallingConvention CallingConvention; //入口点调用约定
   public CharSet CharSet; //入口点采用的字符接
   public string EntryPoint; //入口点名称
   public bool ExactSpelling; //是否必须与指示的入口点拼写完全一致,默认false
   public bool PreserveSig; //方法的签名是被保留还是被转换
   public bool SetLastError; //FindLastError方法的返回值保存在这里
   public string Value { get {…} }
  }

Mwic_32.dll(明华IC卡)

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace mw_rdp
{
	/// <summary>
	/// IC4442 的摘要说明。
	/// </summary>
	public unsafe class IC4442
	{
		public IC4442()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}

        //向IC卡中写数据

        [DllImport("Mwic_32.dll", EntryPoint = "swr_4442", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]

        public static extern int swr_4442(int icdev, int offset, int len, char* w_string);

		[DllImport("Mwic_32.dll", EntryPoint="srd_4442",  SetLastError=true,
			 CharSet=CharSet.Auto, ExactSpelling=false, 
			 CallingConvention=CallingConvention.StdCall)]
			//说明:    从指定地址读数据  
			//		   调用:    icdev:    通讯设备标识符 offset:   偏移地址,其值范围0~255
			//  		len:      字符串长度,其值范围1~256  		r_string: 读出数据所存放地址指针
			//返回:     <>0   错误 	=0 正确
		public  static extern  Int16 srd_4442(int icdev, Int16 offset, Int16 len,[MarshalAs(UnmanagedType.LPArray)]byte[] r_string ); 
		

		[DllImport("Mwic_32.dll", EntryPoint="chk_4442",  SetLastError=true,
			 CharSet=CharSet.Auto , ExactSpelling=false,
			 CallingConvention=CallingConvention.StdCall)]
			//	说明:    检查卡型是否正确  
			//调用:    icdev:   通讯设备标识符 
			//返回:     <0   错误   =0   正确
		public static extern  Int16 chk_4442(int icdev);


        [DllImport("Mwic_32.dll", EntryPoint = "csc_4442", SetLastError = true,
     CharSet = CharSet.Auto, ExactSpelling = true,
     CallingConvention = CallingConvention.Winapi)]
        public static extern Int16 Csc_4442(int icdev, int len, [MarshalAs(UnmanagedType.LPArray)] byte[] p_string);



		[DllImport("Mwic_32.dll", EntryPoint="wsc_4442",  SetLastError=true,
			 CharSet=CharSet.Auto, ExactSpelling=false,
			 CallingConvention=CallingConvention.StdCall)]
			//说明:    改写卡密码
			//调用:    icdev:    通讯设备标识符 len: 密码个数,其值为3 p_string: 新密码地址指针
			//返回:    <0   错误   =0   正确
		public static extern Int16 wsc_4442(int icdev, Int16 len, [MarshalAs(UnmanagedType.LPArray)]byte[] p_string);

		[DllImport("Mwic_32.dll", EntryPoint="rsc_4442",  SetLastError=true,
			 CharSet=CharSet.Auto, ExactSpelling=false,
			 CallingConvention=CallingConvention.StdCall)]
			//说明:    读出卡密码  
			//调用:    icdev:    通讯设备标识符  len:      密码个数,其值为3 	p_string: 存放密码地址指针
			// 返回:    <>0   错误   =0   正确	
         
		public static extern Int16 rsc_4442(int icdev, Int16 len,  [MarshalAs(UnmanagedType.LPArray)]byte[] p_string);

		[DllImport("Mwic_32.dll", EntryPoint="rsct_4442",  SetLastError=true,
			 CharSet=CharSet.Auto, ExactSpelling=false,
			 CallingConvention=CallingConvention.StdCall)]
			//说明:    读出密码错误计数器值
			//调用:    icdev:    通讯设备标识符 counter:  密码错误记数值存放指针
			//返回:     <0   错误 >=0   正确
		public static extern Int16 rsct_4442(int icdev, out byte counter);


	}
}

MainDll.Dll(爱迪尔门锁)

public static class AdelDoorCardIfc
    {
        public enum AdelSoftType
        {
            Lock3200 = 1,
            Lock3200K,
            Lock4200,
            Lock4200D,
            Lock5200,
            Lock6200,
            Lock7200,
            Lock7200D,
            Lock9200,
            Lock9200T,
            A30,
            A50 = 14,
            A90 = 18,
            A92 = 22
        }
        public enum TMEncoder
        {
            DS9097E = 1,
            DS9097U = 5
        }
        public enum EnCoderType
        {
            手动发行机,
            自动发行机,
            MSR206磁卡
        }
        private const string IFC_DllFileName = "MainDll.Dll";
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int SetPort(int Soft, int Port, int EncoderType, int TMEncoder);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int Reader_Beep(int Sound);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int EndSession();
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern void ChangeUser(string username);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int Init(int Soft, string Server, string UName, int EnCoderType, int TMEncoder);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int NewKey(string RoomNo, string Gate, string StartTime, string GuestName, string GuestId, int OverFlag, out int CardNo, string str1, string str2);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int AddKey(string RoomNo, string Gate, string StartTime, string GuestName, string GuestId, int OverFlag, out int CardNo, string str1, string str2);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int DupKey(string RoomNo, string Gate, string StartTime, string GuestName, string GuestId, int OverFlag, out int CardNo, string str1, string str2);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int ReadCard(StringBuilder room, StringBuilder gate, StringBuilder stime, StringBuilder guestname, StringBuilder guestid, StringBuilder track1, StringBuilder track2, ref int cardno, ref int st);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int EraseCard(int CardNo, string str1, string str2);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int CheckOut(string RoomNo, int CardNo);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int LostCard(string RoomNo, int CardNo);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int ReadCardId(ref uint cardNo);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int ReadIC(int start, int len, StringBuilder buff);
        [DllImport("MainDll.Dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
        public static extern int WriteIC(int start, int len, StringBuilder buff);
        public static void ShowMessageResult(int iResult, bool ifSystemBarNotity)
        {
            string text = string.Empty;
            switch (iResult)
            {
            case 0:
                text = "门口接口调用,操作成功!";
                break;
            case 1:
                text = "读写错误或者数据错误!";
                break;
            case 2:
                text = "卡已损坏!";
                break;
            case 3:
                text = "没有检测到卡!";
                break;
            case 4:
                text = "串口通信错误,请检测连接线!";
                break;
            case 5:
                text = "卡被更换!";
                break;
            case 6:
                text = "不是新卡!";
                break;
            case 7:
                text = "卡是新卡!";
                break;
            case 8:
                text = "非本系统卡!";
                break;
            case 9:
                text = "不是客人卡!";
                break;
            case 10:
                text = "不是会员卡!";
                break;
            case 11:
                text = "密码错误!";
                break;
            case 12:
                text = "无开门记录!";
                break;
            case 13:
                text = "卡型不正确!";
                break;
            case 14:
                text = "参数错误!";
                break;
            case 15:
                text = "用户取消操作(按下<ESC>键)!";
                break;
            case 16:
                text = "等待超时!";
                break;
            case 17:
                text = "插卡错误!";
                break;
            case 18:
                text = "卡是空白卡或插卡错误!";
                break;
            case 19:
                text = "19";
                break;
            case 20:
                text = "没有调用Init函数!";
                break;
            case 21:
                text = "不支持该版本的门锁软件!";
                break;
            case 22:
                text = "连接(门锁系统数据库)错误!";
                break;
            case 23:
                text = "门锁系统参数不存在!";
                break;
            case 24:
                text = "初始化失败!";
                break;
            case 25:
                text = "没有客人在住/指定客人不存在!";
                break;
            case 26:
                text = "客房已满!";
                break;
            case 27:
                text = "没有此卡记录!";
                break;
            case 28:
                text = "没有调用SetPort函数!";
                break;
            case 29:
                text = "无效的客房房号!";
                break;
            case 30:
                text = "错误的时间范围!";
                break;
            case 31:
                text = "卡号已存在,无法登记!";
                break;
            case 32:
                text = "不支持调用!";
                break;
            case 33:
                text = "无效的授权码,授权码错误或过期!";
                break;
            }
            if (ifSystemBarNotity)
            {
                Utility.NotifyMessageBox(text, "接口系统提示");
            }
            else
            {
                MessageBox.Show(text, "接口系统提示");
            }
        }
    }

posdll.dll(北洋打印机封装的OPOS指令打印DLL)

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO.Ports;

namespace PosPrintService
{
    /// <summary>
    /// 北洋OPOS指令集二次开发包DLL调用  
    ///   
    public class BeiYangOPOS
    {
        const string _DllVer = "1.4";
        /// <summary>
        /// 获取动态库版本号
        /// </summary>
        public string GetDllVer
        {
            get { return _DllVer;}
        }

      
        /// <summary>
        /// 设备打开后的句柄
        /// </summary>
        public IntPtr POS_IntPtr;

        /// <summary>
        /// 函数返回值
        /// </summary>
        public uint POS_SUCCESS = 1001;//  函数执行成功 
        public uint POS_FAIL = 1002;   //  函数执行失败 
        public uint POS_ERROR_INVALID_HANDLE = 1101; // 端口或文件的句柄无效 
        public uint POS_ERROR_INVALID_PARAMETER = 1102;// 参数无效 
        public uint POS_ERROR_NOT_BITMAP = 1103 ; // 不是位图格式的文件 
        public uint POS_ERROR_NOT_MONO_BITMAP = 1104;// 位图不是单色的 
        public uint POS_ERROR_BEYONG_AREA = 1105 ;//位图超出打印机可以处理的大小 
        public uint POS_ERROR_INVALID_PATH = 1106; // 没有找到指定的文件路径或名 

        /// <summary>
        /// 停止位
        /// </summary>
        public uint POS_COM_ONESTOPBIT = 0x00;//停止位为1
        public uint POS_COM_ONE5STOPBITS = 0x01;//停止位为1.5
        public uint POS_COM_TWOSTOPBITS = 0x02;//停止位为2
        /// <summary>
        /// 奇偶校验
        /// </summary>
        public uint POS_COM_NOPARITY = 0x00;//无校验
        public uint POS_COM_ODDPARITY = 0x01;//奇校验
        public uint POS_COM_EVENPARITY = 0x02;//偶校验
        public uint POS_COM_MARKPARITY = 0x03;//标记校验
        public uint POS_COM_SPACEPARITY = 0x04;//空格校验
        /// <summary>
        /// 其他COM口参数及端口类型定义
        /// </summary>
        public uint POS_COM_DTR_DSR = 0x00;// 流控制为DTR/DST  
        public uint POS_COM_RTS_CTS = 0x01;// 流控制为RTS/CTS 
        public uint POS_COM_XON_XOFF = 0x02;// 流控制为XON/OFF 
        public uint POS_COM_NO_HANDSHAKE = 0x03;//无握手 
        public uint POS_OPEN_PARALLEL_PORT = 0x12;//打开并口通讯端口 
        public uint POS_OPEN_BYUSB_PORT = 0x13;//打开USB通讯端口 
        public uint POS_OPEN_PRINTNAME = 0X14;// 打开打印机驱动程序 
        public uint POS_OPEN_NETPORT = 0x15;// 打开网络接口 

        public uint POS_CUT_MODE_FULL = 0x00;// 全切 
        public uint POS_CUT_MODE_PARTIAL = 0x01;// 半切 

        /// <summary>
        /// 打开POS机的端口 开始会话
        /// </summary>
        /// <param name="lpName">
        ///指向以 null 结尾的打印机名称或端口名称。
        ///当参数nParam的值为POS_COM_DTR_DSR、POS_COM_RTS_CTS、POS_COM_XON_XOFF或POS_COM_NO_HANDSHAKE 时, “COM1”,“COM2”,“COM3”,“COM4”等表示串口;
        ///当参数nParam的值为POS_OPEN_PARALLEL_PORT时,“LPT1”,“LPT2”等表示并口;
        ///当参数nParam的值为POS_OPEN_BYUSB_PORT时,“BYUSB-0”、“BYUSB-1”、“BYUSB-2”、“BYUSB-3”等表示USB端口。
        ///当参数nParam的值为POS_OPEN_PRINTNAME时,表示打开指定的打印机。
        ///当参数nParam的值为POS_OPEN_NETPORT时,表示打开指定的网络接口,如“192.168.10.251”表示网络接口IP地址</param>
        /// <param name="nComBaudrate">串口通信需要的波特率</param>
        /// <param name="nComDataBits">串口通信需要的数据位</param>
        /// <param name="nComStopBits">串口通信需要的停止位</param>
        /// <param name="nComParity">串口通信需要的是否要奇偶校验</param>
        /// <param name="nParam">指向以 null 结尾的打印机名称或端口名称。
        /// 参数nParam的值为POS_COM_DTR_DSR、POS_COM_RTS_CTS、POS_COM_XON_XOFF或POS_COM_NO_HANDSHAKE 时,
        /// “COM1”,“COM2”,“COM3”,“COM4”等表示串口;
        /// 当参数nParam的值为POS_OPEN_PARALLEL_PORT时,“LPT1”,“LPT2”等表示并口;
        /// 当参数nParam的值为POS_OPEN_BYUSB_PORT时,“BYUSB-0”、“BYUSB-1”、“BYUSB-2”、“BYUSB-3”等表示USB端口。
        /// 当参数nParam的值为POS_OPEN_PRINTNAME时,表示打开指定的打印机。</param>
        /// <returns>如果函数调用成功,返回一个已打开的端口句柄。如果函数调用失败,返回值为 INVALID_HANDLE_VALUE (-1)。</returns>
        [DllImport("POSDLL.dll", CharSet = CharSet.Ansi)]
        public static extern IntPtr POS_Open([MarshalAs(UnmanagedType.LPStr)]string lpName, 
                                             uint nComBaudrate, 
                                             uint nComDataBits, 
                                             uint nComStopBits, 
                                             uint nComParity,
                                             uint nParam);

        /// <summary>
        /// 关闭已经打开的并口或串口,USB端口,网络接口或打印机。
        /// </summary>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_Close();

        /// <summary>
        /// 复位打印机,把打印缓冲区中的数据清除,字符和行高的设置被清除,打印模式被恢复到上电时的缺省模式。
        /// </summary>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_Reset();

        /// <summary>
        /// 设置打印机的移动单位。
        /// </summary>
        /// <param name="nHorizontalMU">把水平方向上的移动单位设置为 25.4 / nHorizontalMU 毫米。可以为0到255。</param>
        /// <param name="nVerticalMU">把垂直方向上的移动单位设置为 25.4 / nVerticalMU 毫米。可以为0到255。</param>
        /// <returns>
        /// 如果函数成功,则返回值为 POS_SUCCESS。
        /// 如果函数失败,则返回值为以下值之一:POS_FAIL POS_ERROR_INVALID_HANDLE POS_ERROR_INVALID_PARAMETER </returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_SetMotionUnit(uint nHorizontalMU, uint nVerticalMU);
        /// <summary>
        /// 选择国际字符集和代码页
        /// </summary>
        /// <param name="nCharSet">
        /// 指定国际字符集。不同的国际字符集对0x23到0x7E的ASCII码值对应的符号定义是不同的。
        /// 可以为以下列表中所列值之一。
        /// 0x00 U.S.A  0x01 France  0x02 Germany  0x03 U.K. 0x04 Denmark I 0x05 Sweden 
        /// 0x06 Italy 0x07 Spain I  0x08 Japan 0x09 Nonway 0x0A Denmark II 0x0B Spain II 
        /// 0x0C Latin America 0x0D Korea </param>
        /// <param name="nCodePage">
        /// 指定字符的代码页。不同的代码页对0x80到0xFF的ASCII码值对应的符号定义是不同的。
        /// 0x00 PC437 [U.S.A. Standard Europe 0x01 Reserved 0x02 PC850 [Multilingual] 
        /// 0x03 PC860 [Portuguese] 0x04 PC863 [Canadian-French] 0x05 PC865 [Nordic] 
        /// 0x12 PC852 0x13 PC858 
        /// </param>
        /// <returns>
        /// 如果函数成功,则返回值为 POS_SUCCESS。
        /// 如果函数失败,则返回值为以下值之一:POS_FAIL POS_ERROR_INVALID_HANDLE POS_ERROR_INVALID_PARAMETER </returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_SetCharSetAndCodePage(uint nCharSet, uint nCodePage);

        /// <summary>
        /// POS字体样式
        /// </summary>
        /// 
        public uint  POS_FONT_TYPE_STANDARD  = 0x00;// 标准 ASCII 
        public uint  POS_FONT_TYPE_COMPRESSED = 0x01;// 压缩 ASCII  
        public uint  POS_FONT_TYPE_UDC = 0x02;       // 用户自定义字符 
        public uint  POS_FONT_TYPE_CHINESE = 0x03;   // 标准 “宋体” 
        public uint  POS_FONT_STYLE_NORMAL =  0x00;   //  正常 
        public uint  POS_FONT_STYLE_BOLD =  0x08;   //  加粗 
        public uint  POS_FONT_STYLE_THIN_UNDERLINE =  0x80;   //  1点粗的下划线 
        public uint  POS_FONT_STYLE_THICK_UNDERLINE =  0x100;   //  2点粗的下划线 
        public uint  POS_FONT_STYLE_UPSIDEDOWN =  0x200;   //  倒置(只在行首有效) 
        public uint  POS_FONT_STYLE_REVERSE =  0x400;   //  反显(黑底白字) 
        public uint  POS_FONT_STYLE_SMOOTH =  0x800;   //  平滑处理(用于放大时) 
        public uint POS_FONT_STYLE_CLOCKWISE_90 = 0x1000;   //  每个字符顺时针旋转 90 度

        /// <summary>
        /// 把将要打印的字符串数据发送到打印缓冲区中,并指定X 方向(水平)上的绝对起始点位置,
        /// 指定每个字符宽度和高度方向上的放大倍数、类型和风格。
        /// </summary>
        /// <param name="pszString">指向以 null 结尾的字符串缓冲区</param>
        /// <param name="nOrgx">指定 X 方向(水平)的起始点位置离左边界的点数。</param>
        /// <param name="nWidthTimes">指定字符的宽度方向上的放大倍数。可以为 1到 6。</param>
        /// <param name="nHeightTimes">指定字符高度方向上的放大倍数。可以为 1 到 6。</param>
        /// <param name="nFontType">指定字符的字体类型。</param>
        /// <param name="nFontStyle">指定字符的字体风格。</param>
        /// <returns></returns>
        
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_S_TextOut([MarshalAs(UnmanagedType.LPStr)]string pszString, 
                                                   uint nOrgx, uint nWidthTimes, uint nHeightTimes, 
                                                   uint nFontType, uint nFontStyle);

        /// <summary>
        /// 设置POS的打印模式 (只有两种 页模式和标准模式)
        /// </summary>
        /// <param name="nPrintMode">
        /// POS_PRINT_MODE_STANDARD 0x00 标准模式(行模式) 
        /// POS_PRINT_MODE_PAGE 0x01 页模式 
        /// POS_PRINT_MODE_BLACK_MARK_LABEL 0x02 黑标记标签模式 
        /// POS_PRINT_MODE_WHITE_MARK_LABEL 0x03 白标记标签模式 </param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_SetMode(uint nPrintMode);
        /// <summary>
        /// 设置字符的行高。
        /// </summary>
        /// <param name="nDistance">指定行高点数。可以为 0 到 255。每点的距离与打印头分辨率相关。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_SetLineSpacing(uint nDistance);
        /// <summary>
        /// 设置字符的右间距(相邻两个字符的间隙距离)。
        /// </summary>
        /// <param name="nDistance">指定右间距的点数。可以为 0 到 255。每点的距离与打印头分辨率相关。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_SetRightSpacing(int nDistance);

        /// <summary>
        /// 向前走纸。
        /// 1.如果在标准打印模式(行模式)下打印文本,则打印缓冲区中的数据,且打印位置自动移动到下一行的行首。
        /// 2.如果在标准打印模式(行模式)下打印位图,则在指定的位置打印位图,且打印位置自动移动到下一行的行首。
        /// 3.如果在页模式或标签模式下,则把需要打印的数据设置在指定的位置,同时把打印位置移动到下一个行首,
        /// 但是并不立即进纸并打印,而是一直到调用 POS_PL_Print 函数时才打印。
        /// </summary>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_FeedLine();
        /// <summary>
        /// 打印头换n行 
        /// </summary>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_FeedLines(uint nLines);
        
        /// <summary>
        /// 切纸
        /// </summary>
        /// <param name="nMode">模式编号 半切或是全切</param>
        /// <param name="nDistance">走位的距离</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_CutPaper(uint nMode, uint nDistance);

        /// <summary>
        /// 设置右边距
        /// </summary>
        /// <param name="nDistance">右边距</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_SetRightSpacing(uint nDistance);
        /// <summary>
        /// 预下载一幅位图到打印机的 RAM 中,同时指定此位图的 ID 号。
        /// </summary>
        /// <param name="pszPath">指向以 null 结尾的表示位图路径及其文件名的字符串。</param>
        /// <param name="nID">指定将要下载的位图的 ID 号。可以为 0 到 7。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PreDownloadBmpToRAM([MarshalAs(UnmanagedType.LPStr)]string pszPath, uint nID);
        /// <summary>
        /// 下载并打印位图
        /// </summary>
        /// <param name="pszPath">指向以null 结尾的包含位图文件路径及其名称的字符串。</param>
        /// <param name="nOrgx">指定将要打印的位图和左边界的距离点数。可以为 0到 65535 点。</param>
        /// <param name="nMode">指定位图的打印模式。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_S_DownloadAndPrintBmp([MarshalAs(UnmanagedType.LPStr)]string pszPath, uint nOrgx, uint nMode);

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_S_PrintBmpInRAM(uint nID, uint nOrgx, uint nMode);

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_S_PrintBmpInFlash(uint nID, uint nOrgx, uint nMode);

        /// <summary>
        /// 通过串口返回当前打印机的状态。此函数是实时的。
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_RTQueryStatus(byte[] address);

        /// <summary>
        /// 通过串口查询打印机当前的状态。此函数是非实时的。
        /// </summary>
        /// <param name="pszStatus">
        /// 指向返回的状态数据的缓冲区,缓冲区大小为 1 个字节。
        /// 0,1 0/1 容纸器中有纸 / 纸将用尽 2,3 0/1 打印头处有纸 / 无纸 
        /// 4,5 0/1 钱箱连接器引脚 3 的电平为低 / 高(表示打开或关闭) 
        /// 6,7 0 保留(固定为0) 
        /// </param>
        /// <param name="nTimeouts">设置查询状态时大约的超时时间(毫秒)。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_QueryStatus(byte[] pszStatus, int nTimeouts);
        /// <summary>
        /// 通过网络接口查询返回当前打印机的状态。
        /// </summary>
        /// <param name="ipAddress">设备IP地址。如“192.168.10.251”。</param>
        /// <param name="pszStatus">
        /// 指向接收返回状态的缓冲区,缓冲区大小为 1 个字节。 
        /// 0 0/1 钱箱连接器引脚 3 的电平为低/高(表示打开或关闭) 
        /// 1 0/1 打印机联机/脱机 
        /// 2 0/1 上盖关闭/打开 
        /// 3 0/1 没有/正在由Feed键按下而进纸 
        /// 4 0/1 打印机没有/有出错 
        /// 5 0/1 切刀没有/有出错 
        /// 6 0/1 有纸/纸将尽(纸将尽传感器探测) 
        /// 7 0/1 有纸/纸用尽(纸传感器探测) 
        /// </param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern int POS_NETQueryStatus([MarshalAs(UnmanagedType.LPStr)]string ipAddress, out Byte pszStatus);

        
        /// <summary>
        /// 设置并打印条码。
        /// </summary>
        /// <param name="pszInfo">指向以 null 结尾的字符串。每个字符允许的范围和格式与具体条码类型有关。</param>
        /// <param name="nOrgx">指定将要打印的条码的水平起始点与左边界的距离点数。可以为 0 到65535。</param>
        /// <param name="nType">
        /// 指定条码的类型。可以为以下列表中所列值之一。
        /// POS_BARCODE_TYPE_UPC_A 0x41 UPC-A POS_BARCODE_TYPE_UPC_E 0x42 UPC-C 
        /// POS_BARCODE_TYPE_JAN13 0x43 JAN13(EAN13) POS_BARCODE_TYPE_JAN8 0x44 JAN8(EAN8) 
        /// POS_BARCODE_TYPE_CODE39 0x45 CODE39 POS_BARCODE_TYPE_ITF 0x46 INTERLEAVED 2 OF 5 
        /// POS_BARCODE_TYPE_CODEBAR 0x47 CODEBAR POS_BARCODE_TYPE_CODE93 0x48 25 
        /// POS_BARCODE_TYPE_CODE128 0x49 CODE 128 </param>
        /// <param name="nWidthX">
        /// 指定条码的基本元素宽度。
        /// 2 0.25mm 0.25mm 0.625mm 3 0.375mm 0.375mm 1.0mm 4 0.5mm 0.5mm 1.25mm 
        /// 5 0.625mm 0.625mm 1.625mm 6 0.75mm 0.75mm 1.875mm 
        /// </param>
        /// <param name="nheight">指定条码的高度点数。可以为 1 到 255 。默认值为162 点。</param>
        /// <param name="nHriFontType">
        /// 指定 HRI(Human Readable Interpretation)字符的字体类型。可以为以下列表中所列值之一。
        /// POS_FONT_TYPE_STANDARD 0x00 标准ASCII POS_FONT_TYPE_COMPRESSED 0x01 压缩ASCII 
        /// </param>
        /// <param name="nHriFontPosition">
        /// 指定HRI(Human Readable Interpretation)字符的位置。
        /// POS_HRI_POSITION_NONE  0x00 不打印 POS_HRI_POSITION_ABOVE 0x01 只在条码上方打印 
        /// POS_HRI_POSITION_BELOW 0x02 只在条码下方打印 POS_HRI_POSITION_BOTH  0x03 条码上、下方都打印 
        /// </param>
        /// <param name="nBytesOfInfo">指定由参数 pszInfoBuffer指向的字符串个数,即将要发送给打印机的字符总数。具体值与条码类型有关。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_S_SetBarcode([MarshalAs(UnmanagedType.LPStr)]string pszInfo,
                                                      uint nOrgx,uint nType,uint nWidthX,uint nheight,
                                                      uint nHriFontType,uint nHriFontPosition,uint nBytesOfInfo);


        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PL_SetArea(uint nOrgx , uint nOrgY , uint nWidth , uint nheight , uint nDirection );

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PL_TextOut([MarshalAs(UnmanagedType.LPStr)]string pszString,uint nOrgx,uint nOrgY, 
                                                   uint nWidthTimes, uint nHeightTimes, uint nFontType, uint nFontStyle);

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PL_PrintBmpInRAM(uint nID , uint nOrgx , uint nOrgY , uint nMode );

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PL_PrintBmpInFlash(uint nID, uint nOrgx, uint nOrgY, uint nMode);

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PL_SetBarcode([MarshalAs(UnmanagedType.LPStr)]string pszInfo, 
                                                       uint nOrgx , uint nOrgY , uint nType , uint nWidthX,uint nheight,
                                                       uint nHriFontType,uint nHriFontPosition,uint nBytesOfInfo);

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PL_Clear();

        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_PL_Print();
        /// <summary>
        /// 往钱箱引脚发送脉冲以打开钱箱。
        /// </summary>
        /// <param name="nID">指定钱箱的引脚。0x00 钱箱连接器引脚2 0x01 钱箱连接器引脚5 </param>
        /// <param name="nOnTimes">指定往钱箱发送的高电平脉冲保持时间,即 nOnTimes × 2 毫秒。可以为1 到 255。</param>
        /// <param name="nOffTimes">指定往钱箱发送的低电平脉冲保持时间,即 nOffTimes × 2 毫秒。可以为1 到 255。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_KickOutDrawer(uint nID, uint nOnTimes, uint nOffTimes);
        /// <summary>
        /// 新建一个打印作业。
        /// </summary>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern bool POS_StartDoc();
        /// <summary>
        /// 结束一个打印作业。
        /// </summary>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern bool POS_EndDoc();
        /// <summary>
        /// 发送数据到端口或文件。通用端口打印可以使用此函数 一般不能设置字体大小样式等
        /// </summary>
        /// <param name="hPort">端口或文件句柄。可以通过POS_Open来获取</param>
        /// <param name="pszData">指向将要发送的数据缓冲区。</param>
        /// <param name="nBytesToWrite">指定将要发送的数据的字节数。</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_WriteFile(IntPtr hPort, byte[] pszData, uint nBytesToWrite);
        /// <summary>
        /// 从串口,或USB端口或文件读数据到指定的缓冲区。
        /// </summary>
        /// <param name="hPort">端口或文件句柄。可以通过POS_Open来获取</param>
        /// <param name="pszData">指向将要读取的数据缓冲区。</param>
        /// <param name="nBytesToRead">数据的字节数</param>
        /// <param name="nTimeouts">可能是读取数据的间隔时间</param>
        /// <returns></returns>
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_ReadFile(IntPtr hPort, byte[] pszData, uint nBytesToRead, uint nTimeouts);

        /// <summary>
        /// 打开打印设备的串口
        /// </summary>
        /// <param name="PrintSerialPort">串口对象(需要先初始化并测试参数都有效的情况下,传进来)</param>
        /// <returns>是否打开成功</returns>
        public bool OpenComPort(ref SerialPort PrintSerialPort)
        { 
            uint i_stopbits=0;
            if (PrintSerialPort.StopBits== StopBits.One)
                i_stopbits=POS_COM_ONESTOPBIT;
            if (PrintSerialPort.StopBits== StopBits.OnePointFive)
                i_stopbits=POS_COM_ONE5STOPBITS;
            if (PrintSerialPort.StopBits== StopBits.Two)
                i_stopbits=POS_COM_TWOSTOPBITS;

            uint i_nComParity=0;
            if (PrintSerialPort.Parity== Parity.None)
                i_nComParity=POS_COM_NOPARITY;
            if (PrintSerialPort.Parity== Parity.Even)
                i_nComParity=POS_COM_EVENPARITY;
            if (PrintSerialPort.Parity== Parity.Odd)
                i_nComParity=POS_COM_ODDPARITY;
            if (PrintSerialPort.Parity== Parity.Space)
                i_nComParity=POS_COM_SPACEPARITY;
            if (PrintSerialPort.Parity== Parity.Mark)
                i_nComParity=POS_COM_MARKPARITY;

            uint i_para=0;
            if (PrintSerialPort.Handshake== Handshake.None)
                i_para=POS_COM_NO_HANDSHAKE;
            if (PrintSerialPort.Handshake== Handshake.RequestToSend)
                i_para=POS_COM_DTR_DSR;
            if (PrintSerialPort.Handshake== Handshake.RequestToSendXOnXOff)
                i_para=POS_COM_RTS_CTS;
            if (PrintSerialPort.Handshake== Handshake.XOnXOff)
                i_para=POS_COM_XON_XOFF;

            POS_IntPtr = POS_Open(PrintSerialPort.PortName, 
                                 (uint)PrintSerialPort.BaudRate,
                                 (uint)PrintSerialPort.DataBits,
                                 i_stopbits, i_nComParity, i_para);

            if ((int)POS_IntPtr != -1)
                return true;
            else
                return false;
        }
        /// <summary>
        /// 打开打印设备并口
        /// </summary>
        /// <param name="LPTPortName">并口名称</param>
        /// <returns>是否打开成功</returns>
        public bool OpenLPTPort(string LPTPortName)
        {
            POS_IntPtr = POS_Open(LPTPortName, 0, 0, 0, 0, POS_OPEN_PARALLEL_PORT);
            if ((int)POS_IntPtr != -1)
                return true;
            else
                return false;
        }
        /// <summary>
        /// 打开打印设备的网口
        /// </summary>
        /// <param name="IPAddress">设备的IP地址</param>
        /// <returns>是否打开成功</returns>
        public bool OpenNetPort(string IPAddress)
        {
            POS_IntPtr = POS_Open(IPAddress, 0, 0, 0, 0, POS_OPEN_NETPORT);
            if ((int)POS_IntPtr != -1)
                return true;
            else
                return false;
        }
        /// <summary>
        /// 打开打印设备的USB端口
        /// </summary>
        /// <param name="USBPortName">“BYUSB-0”、“BYUSB-1”、“BYUSB-2”、“BYUSB-3”</param>
        /// <returns>是否打开成功</returns>
        public bool OpenUSBPort(string USBPortName)
        {
            POS_IntPtr = POS_Open(USBPortName, 0, 0, 0, 0, POS_OPEN_BYUSB_PORT);
            if ((int)POS_IntPtr != -1)
                return true;
            else
                return false;
        }
        /// <summary>
        /// 使用windows打印驱动程序来驱动OPOS设备
        /// </summary>
        /// <param name="PrintName">打印驱动程序对应的打印机名称</param>
        /// <returns>是否打开成功</returns>
        public bool OpenPrinter(string PrintName)
        {
            POS_IntPtr = POS_Open(PrintName, 0, 0, 0, 0, POS_OPEN_PRINTNAME);
            if ((int)POS_IntPtr != -1)
                return true;
            else
                return false;
        }
        /// <summary>
        /// 关闭设备端口
        /// </summary>
        /// <returns>是否关闭成功</returns>
        public bool ClosePrinterPort()
        {
            IntPtr tmpIntPtr = POS_Close();
            return ((uint)tmpIntPtr == POS_SUCCESS);
        }
    }
}

tsclib.dll(GP3120条形码打印机API)

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Com.DataCool.GP3120API
{
    /// <summary>
    /// GP 3120条形码打印机API 分辨率:203 DPI
    /// (单位换算:200 DPI,1 点=1/8 mm, 300 DPI,1 点=1/12 mm)
    /// </summary>
    public class TSC_Lib_API
    {
        /// <summary>
        /// 指定计算机端的输出端口 单机打印时,请指定打印机驱动程序名称,例如: TSC TDP-245
        /// 打开端口 独占打印机
        /// </summary>
        /// <param name="PrinterName"></param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int openport(string PrinterName);

        /// <summary>
        /// 关闭指定的计算机端输出端口 结束端口的独占
        /// </summary>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int closeport();

        /// <summary>
        /// 发送指令
        /// </summary>
        /// <param name="Command">内建指令见指令集pdf</param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int sendcommand(string Command);

        /// <summary>
        /// 清空打印机的缓冲区
        /// </summary>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int clearbuffer();

        /// <summary>
        /// 跳页,该函数需在setup 后使用
        /// </summary>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int formfeed();

        /// <summary>
        /// 设定纸张不回吐
        /// </summary>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int nobackfeed();

        /// <summary>
        /// 设定标签的宽度、高度、打印速度、打印浓度、传感器类别、gap/black mark 垂直间距、gap/black mark 偏移距离)
        /// </summary>
        /// <param name="LabelWidth">标签宽度,单位mm</param>
        /// <param name="LabelHeight">标签高度,单位mm</param>
        /// <param name="Speed">打印速度  1.0: 每秒1.0 英寸打印速度 1.0,1.5,2.0,3.0,4.0,5.0,6.0</param>
        /// <param name="Density">打印浓度 0~15,数字越大打印结果越黑</param>
        /// <param name="Sensor">传感器类别 0 表示使用垂直间距传感器(gap sensor) 1 表示使用黑标传感器(black mark sensor) f垂直间距高度,g偏移距离 mm</param>
        //                       f: 字符串型别,设定gap/black mark 垂直间距高度,单位: mm
        //                       g: 字符串型别,设定gap/black mark 偏移距离,单位: mm,此参数若使用一般标签 时均设为0
        /// <param name="Vertical">?</param>
        /// <param name="Offset">设定gap/black mark 偏移距离,单位: mm,此参数若使用一般标签时均设为0</param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int setup(string LabelWidth, string LabelHeight, string Speed, string Density, string Sensor, string Vertical, string Offset);

        /// <summary>
        /// 下载单色PCX 格式图文件至打印机
        /// </summary>
        /// <param name="Filename">文件名(可包含路径)</param>
        /// <param name="ImageName">下载至打印机内存内之文件名(请使用大写文件名)</param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int downloadpcx(string Filename, string ImageName);

        /// <summary>
        /// 使用条形码机内建条形码打印
        /// </summary>
        /// <param name="X">条形码X 方向起始点</param>
        /// <param name="Y">条形码Y 方向起始点</param>
        /// <param name="CodeType">一维条码类型 128 128M EAN128 25 25C 39 39C 93 EAN13 ...</param>
        ////// </param>
        /// <param name="Height">条形码高度,高度以点来表示</param>
        /// <param name="Readable">是否打印条形码码文0: 不打印码文1: 打印码文</param>
        /// <param name="Rotation">条形码旋转角度0: 旋转0 度90: 旋转90 度180: 旋转180 度270: 旋转270 度</param>
        /// <param name="Narrow">条形码窄bar 比例因子 请参考编程手册</param>
        /// <param name="Wide">设定条形码窄bar 比例因子 请参考编程手册</param>
        /// <param name="Code">条形码内容</param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int barcode(string X, string Y, string CodeType, string Height, string Readable, string Rotation, string Narrow, string Wide, string Code);

        /// <summary>
        /// 使用条形码机内建文字打印 (打印机硬字库)
        /// </summary>
        /// <param name="X">文字X 方向起始点</param>
        /// <param name="Y">文字Y 方向起始点</param>
        /// <param name="FontName">内建字型名称 1~5 TST24.BF2 TSS24.BF2 K</param>      
        /// <param name="Rotation">文字旋转角度 0~270(90的倍数)</param>
        /// <param name="Xmul">文字X 方向放大倍数,1~8</param>
        /// <param name="Ymul">文字Y 方向放大倍数,1~8</param>
        /// <param name="Content">文字内容</param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int printerfont(string X, string Y, string FontName, string Rotation, string Xmul, string Ymul, string Content);

        /// <summary>
        /// 打印条形码 (调用缓冲区设置的条码)
        /// </summary>
        /// <param name="NumberOfSet">打印标签个数(set)</param>
        /// <param name="NumberOfCopoy">打印标签份数(copy)</param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int printlabel(string NumberOfSet, string NumberOfCopoy);

        /// <summary>
        /// 使用Windows TTF 字型打印文字
        /// </summary>
        /// <param name="X">X 方向起始点</param>
        /// <param name="Y">Y 方向起始点</param>
        /// <param name="FontHeight">字体高度</param>
        /// <param name="Rotation">旋转的角度 0~270(90的倍数)</param>
        /// <param name="FontStyle">字体外形 0-> 标准(Normal) 1-> 斜体(Italic) 2-> 粗体(Bold) 3-> 粗斜体(Bold and Italic)</param>
        /// <param name="FontUnderline">底线0-> 无底线 1-> 加底线</param>
        /// <param name="FaceName">字体名称。如: Arial, Times new Roman, 细名体, 标楷体</param>
        /// <param name="TextContect">文字内容</param>
        /// <returns></returns>
        [DllImport("tsclib.dll")]
        public static extern int windowsfont(int X, int Y, int FontHeight, int Rotation, int FontStyle, int FontUnderline, string FaceName, string TextContect);
    }
}

umf.dll(明泰非接触式RF读写器)

public class S9Dll
    {
        /// <summary>
        /// 初始化通讯口
        /// </summary>
        /// <param name="port">USB通讯口,取值0-99</param>
        /// <param name="baud">通讯波特率,9600-115200</param>
        /// <returns>成功返回串口标识符值,失败返回-1</returns>
        [DllImport("umf.dll", EntryPoint = "fw_init")]
        public static extern Int32 fw_init(Int16 port, Int32 baud);

        /// <summary>
        /// 关闭端口
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <returns></returns>
        [DllImport("umf.dll", EntryPoint = "fw_exit")]
        public static extern Int32 fw_exit(Int32 icdev);

        /// <summary>
        /// 寻卡,能返回在工作区域内某张卡的序列号
        /// </summary>
        /// <param name="icdev">通讯标识符</param>
        /// <param name="_Bcnt">寻卡模式,0---表示IDLE模式,一次只对一张卡;1---表示ALL模式,一次可对应多张卡</param>
        /// <param name="_Snr">返回的卡序列号</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_card")]
        public static extern Int32 fw_card(Int32 icdev, Byte _Mode, ref ulong _Snr);

        /// <summary>
        /// 寻卡,能返回在工作区域内某张卡的序列号(16进制)
        /// </summary>
        /// <param name="icdev">通讯标识符</param>
        /// <param name="_Mode">寻卡模式,0---表示IDLE模式,一次只对一张卡;1---表示ALL模式,一次可对应多张卡</param>
        /// <param name="_Snr">返回的卡序列号</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_card_hex")]
        public static extern Int32 fw_card_hex(Int32 icdev, Byte _Mode, ref Byte _Snr);

        /// <summary>
        /// 寻卡,能返回在工作区域内某张卡的序列号(10进制)
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Mode">寻卡模式,0---表示IDLE模式,一次只对一张卡;1---表示ALL模式,一次可对应多张卡</param>
        /// <param name="_Snr">返回的卡序列号</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_card_str")]
        public static extern Int32 fw_card_str(Int32 icdev, Byte _Mode, ref Byte _Snr);

        /// <summary>
        /// 寻卡请求
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Mode">寻卡模式,0---表示IDLE模式,一次只对一张卡;1---表示ALL模式,一次可对应多张卡</param>
        /// <param name="_TagType">返回卡的类型值,4--MIFARE ONE(M1);2--S70;8--MIFARE PRO;68--ULTRA  LIGHT</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_request")]
        public static extern Int32 fw_request(Int32 icdev, Byte _Mode, ref UInt32 _TagType);

        /// <summary>
        /// 防卡冲突,返回卡的序列号
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Bcnt">防卡冲突的级别,这里值为0</param>
        /// <param name="_Snr">返回卡序列号地址</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_anticoll")]
        public static extern Int32 fw_anticoll(Int32 icdev, Byte _Bcnt, ref ulong _Snr);

        /// <summary>
        /// 从多个卡中选取一个给定序列号的卡
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Snr">卡序列号</param>
        /// <param name="_Size">指向返回的卡容量数据</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_select")]
        public static extern Int32 fw_select(Int32 icdev, ulong _Snr, Byte _Size);

        /// <summary>
        /// 将密码装入读写模块RAM中
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Mode">装入密码模式,0--KEYA,4--KEYB</param>
        /// <param name="_SecNr">扇区号(M1卡:0-15;ML卡:0)</param>
        /// <param name="_NKey">写入读写器中的卡密码</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_load_key")]
        public static extern Int32 fw_load_key(Int32 icdev, Byte _Mode, Byte _SecNr, Byte[] _NKey);

        /// <summary>
        /// 核对密码函数
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Mode">装入密码模式,0--KEYA,4--KEYB</param>
        /// <param name="_SecNr">要验证密码的扇区号</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_authentication")]
        public static extern Int32 fw_authentication(Int32 icdev, Byte _Mode, Byte _SecNr);

        /// <summary>
        /// 核对密码函数,用此函数时,可以不用执行fw_load_key函数
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Mode">装入密码模式,0--KEYA,4--KEYB</param>
        /// <param name="_Addr">要验证密码的扇区号</param>
        /// <param name="_PassBuff">扇区密码(6字节)</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_authentication_pass")]
        public static extern Int32 fw_authentication_pass(Int32 icdev, Byte _Mode, Byte _Addr, Byte[] _PassBuff);

        /// <summary>
        /// 读取卡中数据
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">M1卡---块地址(0-63),MS70(0-255)</param>
        /// <param name="_Data">读出数据,字符串是ASCII码</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_read")]
        public static extern Int32 fw_read(Int32 icdev, Byte _Addr, ref Byte _Data);

        /// <summary>
        /// 读取卡中数据
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">M1卡---块地址(0-63),MS70(0-255)</param>
        /// <param name="_Data">读出数据,字符串是十六进制</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_read_hex")]
        public static extern Int32 fw_read_hex(Int32 icdev, Byte _Addr, ref Byte _Data);

        /// <summary>
        /// 向卡中写入数据
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">M1卡---块地址(1-63),MS70(1-255)</param>
        /// <param name="_Data">要写入的数据(字符串是ASCII码)</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_write")]
        public static extern Int32 fw_write(Int32 icdev, Byte _Addr, ref Byte _Data);

        /// <summary>
        /// 向卡中写入数据
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">M1卡---块地址(1-63),MS70(1-255)</param>
        /// <param name="_Data">要写入的数据(十六进制)</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_write_hex")]
        public static extern Int32 fw_write_hex(Int32 icdev, Byte _Addr, ref Byte _Data);

        /// <summary>
        /// 中止对该卡操作
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_halt")]
        public static extern Int32 fw_halt(Int32 icdev);

        /// <summary>
        /// DES算法加解密函数
        /// </summary>
        /// <param name="_Key">密钥</param>
        /// <param name="_Sour">要加解密的数据</param>
        /// <param name="_Dest">加解密后的数据</param>
        /// <param name="_M">加解密模式,M=1时,为加密;M=0时,为解密</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_des")]
        public static extern Int32 fw_des(ref Byte _Key, ref Byte _Sour, ref Byte _Dest, Int32 _M);

        /// <summary>
        /// 修改块3的数据
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_SecNr">扇区号(M1:0-15,S70:0-39)</param>
        /// <param name="_KeyA">密码A</param>
        /// <param name="_CtrlW">密码控制块</param>
        /// <param name="_Bk">保留参数,取值位0</param>
        /// <param name="_KeyB">密码B</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_changeb3")]
        public static extern Int32 fw_changeb3(Int32 icdev, Byte _SecNr, ref Byte _KeyA, ref Byte _CtrlW, Byte _Bk, ref Byte _KeyB);

        /// <summary>
        /// 初始化块值
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">块地址</param>
        /// <param name="_Value">初始值</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_initval")]
        public static extern Int32 fw_initval(Int32 icdev, Byte _Addr, ulong _Value);

        /// <summary>
        /// 块加值
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">块地址</param>
        /// <param name="_Value">要增加的值</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_increment")]
        public static extern Int32 fw_increment(Int32 icdev, Byte _Addr, ulong _Value);

        /// <summary>
        /// 读块值
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">块地址</param>
        /// <param name="_Value">读出值的地址</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_readval")]
        public static extern Int32 fw_readval(Int32 icdev, Byte _Addr, ref ulong _Value);

        /// <summary>
        /// 块减值
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">块地址</param>
        /// <param name="_Value">要减值</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_decrement")]
        public static extern Int32 fw_decrement(Int32 icdev, Byte _Addr, ulong _Value);

        /// <summary>
        /// 回传函数,将EEPROM中的内容传入卡的内部寄存器
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">要进行回传的块地址</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_restore")]
        public static extern Int32 fw_restore(Int32 icdev, Byte _Addr);

        /// <summary>
        /// 传送,将寄存器的内容传送到EEPROM中
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Addr">要传送的块地址</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_transfer")]
        public static extern Int32 fw_transfer(Int32 icdev, Byte _Addr);

        /// <summary>
        /// 操作卡配置
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Flag">设定要操作的卡类型(0x41=TYPEA,0x42=TYPEB,0x31=IS015693)</param>
        /// <returns>成功返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_config_card")]
        public static extern Int16 fw_config_card(Int32 icdev, Byte _Flag);

        /// <summary>
        /// 字符串转换函数,十六进制字符转普通字符
        /// </summary>
        /// <param name="_A">转换后的无符号字节数组</param>
        /// <param name="_Hex">待转换的16进制字符串</param>
        /// <param name="len">要转换的无符号字节个数</param>
        /// <returns></returns>
        [DllImport("umf.dll", EntryPoint = "a_hex")]
        public static extern Int16 a_hex(Byte[] _A, Byte[] _Hex, Int16 len);

        /// <summary>
        /// 字符串转换函数,普通字符转十六进制字符
        /// </summary>
        /// <param name="_Hex">转换后的无符号字节数组</param>
        /// <param name="_A">待转换的无符号字节数组</param>
        /// <param name="len">转换后的hex字符串的长度</param>
        [DllImport("umf.dll", EntryPoint = "hex_a")]
        public static extern void hex_a(Byte[] _Hex, Byte[] _A, Int16 len);

        /// <summary>
        /// 蜂鸣
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Msec">蜂鸣时间,单位是10毫秒</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll",EntryPoint="fw_beep")]
        public static extern Int32 fw_beep(Int32 icdev,UInt32 _Msec);

        /// <summary>
        /// 读取硬件版本号
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Buff">存放版本号的缓冲区,字符串形式</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_getver")]
        public static extern Int32 fw_getver(Int32 icdev,StringBuilder _Buff);

        /// <summary>
        /// 设置读写器数码管显示模式,关机后可保存设置值
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Mode">显示模式,0--日期(格式"年yy-月mm-日dd");1--时间(格式"时hh-分mm-秒ss)</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_disp_mode")]
        public static extern Int32 fw_disp_mode(Int32 icdev, Byte _Mode);

        /// <summary>
        /// 读取读写器日期、星期、时间
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Time">返回数据,长度为7个字节,格式"年、星期、月、日、时、分、秒"</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_gettime")]
        public static extern Int32 fw_gettime(Int32 icdev, ref Byte _Time);

        /// <summary>
        /// 设置读写器时间
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Time">长度为7个字节,长度为7个字节,格式"年、星期、月、日、时、分、秒"</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_settime")]
        public static extern Int32 fw_settime(Int32 icdev, ref Byte _Time);

        /// <summary>
        /// 设置读写器数码管的控制模式
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Mode">显示模式,0--计算机控制,1--读写器控制</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_ctl_mode")]
        public static extern Int32 fw_ctl_mode(Int32 icdev, Byte _Mode);

        /// <summary>
        /// LED数码管显示任意数字
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Len">显示数字的个数</param>
        /// <param name="_DispStr">要显示的数字</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_LED_disp8")]
        public static extern Int32 fw_LED_disp8(Int32 icdev, Byte _Len, ref Byte _DispStr);

        /// <summary>
        /// 设置LCD背光点亮或熄灭
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Bright">点亮或熄灭的标志,15-点亮,0-熄灭</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_lcd_setbright")]
        public static extern Int32 fw_lcd_setbright(Int32 icdev, Byte _Bright);

        /// <summary>
        /// 设置LCD显示的字符串
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <param name="_Digit">要显示的字符串</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_lcd_dispstr")]
        public static extern Int32 fw_lcd_dispstr(Int32 icdev, ref Byte _Digit);

        /// <summary>
        /// 清空LCD显示的字符
        /// </summary>
        /// <param name="icdev">通讯设备标识符</param>
        /// <returns>成功则返回0</returns>
        [DllImport("umf.dll", EntryPoint = "fw_lcd_dispclear")]
        public static extern Int32 fw_lcd_dispclear(Int32 icdev);
    }

 

那些年,用C#调用过的外部Dll

标签:har   签名   bitmap   序列号   进制   one   编程   dll导出   direction   

原文地址:http://www.cnblogs.com/datacool/p/datacool_dll_017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!