コード例 #1
0
ファイル: DDI_EZLinkDongle.cs プロジェクト: x893/WDS
 public unsafe int write(DeviceHandle handle, DataBuffer data)
 {
     byte* numPtr = stackalloc byte[0x100];
     if (handle.isInvalid())
     {
         GlobalServices.ErrMsg("DDI_EZLinkDongle.write()", "called with INVALID handle");
         return -1;
     }
     Protocol protocol2 = data.ddi_getProtocol();
     if (protocol2 == Protocol.Write)
     {
         string str;
         data.ddi_getCommand_Transmit(out str);
         numPtr[0] = (byte) (str.Length + 4);
         numPtr[1] = 170;
         numPtr[2] = 0x2d;
         numPtr[3] = 0xd4;
         numPtr[4] = (byte) str.Length;
         for (int i = 0; i < str.Length; i++)
         {
             numPtr[i + 5] = (byte) str[i];
         }
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Transmit_Start;
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLink_Transmit_End;
     }
     else if (protocol2 == Protocol.WriteRegister)
     {
         uint num;
         uint num2;
         data.ddi_getCommand_WriteRegister(out num, out num2);
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLinkReg_Write_Start;
         this._ddi_EZLinkDLL_State = DDI_EZLinkDLL_State.EZLinkReg_Write_End;
     }
     else
     {
         GlobalServices.ErrMsg("DDI_EZLinkDongle.write()", "Unexpected protocol received");
     }
     return 0;
 }
コード例 #2
0
ファイル: DDI_EZLinkDongle.cs プロジェクト: x893/WDS
        public unsafe int read(DeviceHandle handle, DataBuffer data, int bytesToRead)
        {
            int num4;
            byte* numPtr = stackalloc byte[0x100];
            uint regData = 0;
            int num3 = -1;
            if (handle.isInvalid())
            {
                GlobalServices.ErrMsg("DDI_EZLinkDongle.read()", "called with INVALID handle");
                return -1;
            }
            switch (data.ddi_getProtocol())
            {
                case Protocol.ReadRegister:
                    uint num;
                    data.ddi_getCommand_ReadRegister(out num);
                    data.ddi_setReply_ReadRegister(num, regData);
                    return num3;

                case Protocol.ReadStatus:
                    data.NumItems = 14;
                    num4 = 0;
                    while (num4 < data.NumItems)
                    {
                        data.Buf[num4] = numPtr[num4];
                        num4++;
                    }
                    return num3;

                case Protocol.Read:
                    if (num3 == 0)
                    {
                        data.NumItems = numPtr[4];
                        for (num4 = 0; num4 < data.NumItems; num4++)
                        {
                            data.Buf[num4] = numPtr[num4 + 5];
                        }
                    }
                    return num3;
            }
            GlobalServices.ErrMsg("DDI_EZLinkDongle.read()", "Unexpected protocol received");
            return num3;
        }