您当前位置:闸机 >> 产品展示 >> 二次开发 >> 浏览产品 |(闸机二次开发包C#类库全部源码)|关键词: 闸机SDK 闸机开发包 C#开发包
  • 闸机二次开发包C#类库全部源码
  • 型号: SJKJ_PC2MAC_CS_DLL
  • 规格: C#托管动态库
  • 单位: 套
  • 推荐:
    闸机二次开发包C#类库全部源码

    我公司闸机有独立的通用二次开发包,考虑到C#语言在管理中的应用相当广泛,我公司特地在win32二次开发包上做了进一步封装,将底层的c函数封装成了托管的动态库,使用时,只需要将该托管的动态库引用到自己的C#工程中,就可以建立相应的全局类,通过类的函数来控制闸机。

    由于.net框架版本较多,发展很快,我公司的托管动态是在.net2.0下编译的,应广大合作商的要求,本次我公司已经将该托管动态库的源码全部开放,大家可以打开托管动态的工程文件,编译成自己想要的版本,托管动态库不涉及复杂的底层操作,应该能在各个版本中均能不修改源码编译,如果遇到编译问题,烦请将不妥之处,发送至我公司邮箱:mail@HeroGod.com,谢谢!


    该动态库的主要代码:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    //该类是将二进制开发包中的函数,封装一下而已,最终形成C#的DLL,做到最大程序不影响上层应用
    //封装的不妥之处,请指教:QQ 5326,25825
    //请主要参考开发包中的C++头文件“sjkj_pctomac.h”


    namespace SJKJ_PC2MAC_CS_DLL
    {
        public unsafe class sjkjpc2mac
        {
            const string _sjkjdllname_ = "sjkj_pctomac.dll";

            //发送数据
            public bool sjkjsendtomac2(byte cmd, byte suid, string c1, string c2, string c3, byte dir, string macip)
            {
                StringBuilder sc1 = new StringBuilder(c1 + '\0', 50);
                StringBuilder sc2 = new StringBuilder(c2 + '\0', 50);
                StringBuilder sc3 = new StringBuilder(c3 + '\0', 50);
                StringBuilder smacip = new StringBuilder(macip + '\0', 24);
                return sjkjsendtomac(cmd, suid, sc1, sc2, sc3, dir, smacip) == 1;
            }

            //////////////////////////////////////////////////////////////////////////
            //在闸机没有显示屏的情况下,可以使用下面的简单函数
            //注意,此函数并不是开发包中导出的,而是封装的特例
            //顺向开闸或转动
            public void openIN(string macip)
            {
                sjkjsendtomac2(1, 0, "a", "a", "a", 1, macip);           
            }
            //反向开闸或转动
            public void openOUT(string macip)
            {
                sjkjsendtomac2(1, 0, "a", "a", "a", 0, macip);
            }
            //询问是否在线
            public void macLE(string macip)
            {
                sjkjsendtomac2(6, 0, "a", "a", "a", 1, macip);
            }
              
            //////////////////////////////////////////////////////////////////////////

     

            //准备接收数据
            public bool sjkjstart2()
            {
                return sjkjstart() == 1;
            }
            //检测是否有数据,此函应该循环执行
            public bool sjkjhavedata2(int timeout)
            {
                return sjkjhavedata(timeout) == 1;
            }
            //读取数据
            public bool sjkjreaddata2(ref byte cmd, ref byte ctp, ref string content, ref  int len,ref byte dir, ref string remoteip)
            {
                StringBuilder scontent = new StringBuilder(content, 32);
                StringBuilder sremoteip = new StringBuilder(remoteip + '\0', 24);
                fixed (byte* pcmd = &cmd, pctp = &ctp,pdir=&dir)
                {
                    fixed (int* plen = &len)
                    {
                        if (sjkjreaddata(pcmd, pctp, scontent, plen,pdir,sremoteip) == 1)
                        {
                            content = scontent.ToString();
                            remoteip = sremoteip.ToString();
                            return true;
                        }
                        else
                        {
                            return false;
                        }

                    }

                }


            }
            //关闭读取
            public void sjkjstop2()
            {
                sjkjstop();
            }

     

     


            /*以下函数,是从开发包DLL中导出的,如果您对C#和C++的数据类型对应关系有兴趣,可以自行导出*/
            [DllImport(_sjkjdllname_, EntryPoint = "sjkjsendtomac", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
            public static extern int sjkjsendtomac(byte cmd, byte suid, StringBuilder c1, StringBuilder c2, StringBuilder c3, byte dir, StringBuilder macip);
           
            [DllImport(_sjkjdllname_, EntryPoint = "sjkjstart", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
            public static extern int sjkjstart();

           
            [DllImport(_sjkjdllname_, EntryPoint = "sjkjhavedata", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
            public static extern int sjkjhavedata(int timeout);

           
            [DllImport(_sjkjdllname_, EntryPoint = "sjkjreaddata", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
            public static extern int sjkjreaddata(byte* cmd, byte* ctp, StringBuilder content, int* len,byte* dir, StringBuilder remoteip);

           
            [DllImport(_sjkjdllname_, EntryPoint = "sjkjstop", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
            public static extern void sjkjstop(); 


        }
    }