public byte[] GetByte(NeiMengGps body)
        {
            //得到结构体的大小
            int size = Marshal.SizeOf(body);

            //创建byte数组
            byte[] bytes = new byte[size];
            //分配结构体大小的内存空间
            IntPtr structPtr = Marshal.AllocHGlobal(size);

            //将结构体拷到分配好的内存空间
            Marshal.StructureToPtr(body, structPtr, false);
            //从内存空间拷到byte数组
            Marshal.Copy(structPtr, bytes, 0, size);
            //释放内存空间
            Marshal.FreeHGlobal(structPtr);
            //返回byte数组
            return(bytes);
        }
示例#2
0
        public Plugin(PluginModel pModel, bool threadStart)
        {
            if (pModel == null)
            {
                throw new NullReferenceException("null reference");
            }
            byte[] boteHead = new byte[2];
            boteHead[0]  = 0x22;
            boteHead[1]  = 0x00;
            neimengPro   = new NewUdpProtocol();
            neimengGPS   = new NeiMengGps();
            neimengTHead = new NeiMengTHead();

            //neimengTHead.wHeader = 0xAAAA;
            //neimengTHead.cmdFlag = 0xCCCC;
            //neimengTHead.versionFlag = 0x2200;
            //neimengTHead.bodyLength = System.Net.IPAddress.HostToNetworkOrder(51);

            neimengTBody = new NeiMengTBody();

            TranLimit    = 1000;
            this.pModel  = pModel;
            status       = 1;
            isSlow       = 0;
            isStop       = false;
            statistics   = 0;
            enabled      = pModel.Enabled;
            debugEnabled = false;
            neimengpro   = new NewUdpProtocol();

            if (threadStart)
            {
                this.dealDataThread = new Thread(new ThreadStart(Run));
                this.dealDataThread.Start();
            }
        }