Exemple #1
0
        public void GetCAMStatus(out uint CIState, out uint MMIState)
        {
            CIState  = 0;
            MMIState = 0;
            IPin pin = DsFindPin.ByDirection(captureFilter, PinDirection.Input, 0);

            if (pin != null)
            {
                DirectShowLib.IKsPropertySet propertySet = pin as DirectShowLib.IKsPropertySet;
                if (propertySet != null)
                {
                    Guid   propertyGuid       = THBDA_TUNER;
                    IntPtr thbdaBuf           = Marshal.AllocCoTaskMem(1024);
                    IntPtr ptrDwBytesReturned = Marshal.AllocCoTaskMem(4);
                    IntPtr ptrOutBuffer       = Marshal.AllocCoTaskMem(4096);
                    try
                    {
                        int thbdaLen = 0x28;
                        Marshal.WriteInt32(thbdaBuf, 0, 0x255e0082);
                        //GUID_THBDA_CMD  = new Guid( "255E0082-2017-4b03-90F8-856A62CB3D67" );
                        Marshal.WriteInt16(thbdaBuf, 4, 0x2017);
                        Marshal.WriteInt16(thbdaBuf, 6, 0x4b03);
                        Marshal.WriteByte(thbdaBuf, 8, 0x90);
                        Marshal.WriteByte(thbdaBuf, 9, 0xf8);
                        Marshal.WriteByte(thbdaBuf, 10, 0x85);
                        Marshal.WriteByte(thbdaBuf, 11, 0x6a);
                        Marshal.WriteByte(thbdaBuf, 12, 0x62);
                        Marshal.WriteByte(thbdaBuf, 13, 0xcb);
                        Marshal.WriteByte(thbdaBuf, 14, 0x3d);
                        Marshal.WriteByte(thbdaBuf, 15, 0x67);
                        Marshal.WriteInt32(thbdaBuf, 16, (int)THBDA_IOCTL_CI_GET_STATE); //control code
                        Marshal.WriteInt32(thbdaBuf, 20, (int)IntPtr.Zero);              //LPVOID inbuffer
                        Marshal.WriteInt32(thbdaBuf, 24, 0);                             //DWORD inbuffersize
                        Marshal.WriteInt32(thbdaBuf, 28, ptrOutBuffer.ToInt32());        //LPVOID outbuffer
                        Marshal.WriteInt32(thbdaBuf, 32, 4096);                          //DWORD outbuffersize
                        Marshal.WriteInt32(thbdaBuf, 36, (int)ptrDwBytesReturned);       //LPVOID bytesreturned

                        int hr = propertySet.Set(propertyGuid, 0, thbdaBuf, thbdaLen, thbdaBuf, thbdaLen);
                        if (hr == 0)
                        {
                            int bytesReturned = Marshal.ReadInt32(ptrDwBytesReturned);
                            CIState  = (uint)Marshal.ReadInt32(ptrOutBuffer, 0);
                            MMIState = (uint)Marshal.ReadInt32(ptrOutBuffer, 4);
                            //throw new ApplicationException("Twinhan: CI State:{0:X} MMI State:{1:X}", CIState, MMIState);
                        }
                        else
                        {
                            //throw new ApplicationException("Twinhan: unable to get CI State hr:{0:X}", hr);
                        }
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(thbdaBuf);
                        Marshal.FreeCoTaskMem(ptrDwBytesReturned);
                        Marshal.FreeCoTaskMem(ptrOutBuffer);
                    }
                }
                ReleaseComObject(pin);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sends the DiSEqC command.
        /// </summary>
        /// <param name="diSEqC">The DiSEqC command.</param>
        /// <returns>true if succeeded, otherwise false</returns>

        public bool SendDiSEqCCommand(byte[] diSEqC)
        {
            int thbdaLen  = 0x28;
            int disEqcLen = 16;

            for (int i = 0; i < 12; ++i)
            {
                Marshal.WriteByte(_ptrDiseqc, 4 + i, 0);
            }
            Marshal.WriteInt32(_ptrDiseqc, 0, (int)diSEqC.Length); //command len
            for (int i = 0; i < diSEqC.Length; ++i)
            {
                Marshal.WriteByte(_ptrDiseqc, 4 + i, diSEqC[i]);
            }
            string line = "";

            for (int i = 0; i < disEqcLen; ++i)
            {
                byte k = Marshal.ReadByte(_ptrDiseqc, i);
                line += String.Format("{0:X} ", k);
            }
            Marshal.WriteInt32(_thbdaBuf, 0, 0x255e0082);
            //GUID_THBDA_CMD  = new Guid( "255E0082-2017-4b03-90F8-856A62CB3D67" );
            Marshal.WriteInt16(_thbdaBuf, 4, 0x2017);
            Marshal.WriteInt16(_thbdaBuf, 6, 0x4b03);
            Marshal.WriteByte(_thbdaBuf, 8, 0x90);
            Marshal.WriteByte(_thbdaBuf, 9, 0xf8);
            Marshal.WriteByte(_thbdaBuf, 10, 0x85);
            Marshal.WriteByte(_thbdaBuf, 11, 0x6a);
            Marshal.WriteByte(_thbdaBuf, 12, 0x62);
            Marshal.WriteByte(_thbdaBuf, 13, 0xcb);
            Marshal.WriteByte(_thbdaBuf, 14, 0x3d);
            Marshal.WriteByte(_thbdaBuf, 15, 0x67);
            Marshal.WriteInt32(_thbdaBuf, 16, (int)THBDA_IOCTL_SET_DiSEqC); //dwIoControlCode
            Marshal.WriteInt32(_thbdaBuf, 20, (int)_ptrDiseqc.ToInt32());   //lpInBuffer
            Marshal.WriteInt32(_thbdaBuf, 24, disEqcLen);                   //nInBufferSize
            Marshal.WriteInt32(_thbdaBuf, 28, (int)IntPtr.Zero);            //lpOutBuffer
            Marshal.WriteInt32(_thbdaBuf, 32, 0);                           //nOutBufferSize
            Marshal.WriteInt32(_thbdaBuf, 36, (int)_ptrDwBytesReturned);    //lpBytesReturned

            bool success = false;
            IPin pin     = DsFindPin.ByDirection(_captureFilter, PinDirection.Input, 0);

            if (pin != null)
            {
                DirectShowLib.IKsPropertySet propertySet = pin as DirectShowLib.IKsPropertySet;
                if (propertySet != null)
                {
                    Guid propertyGuid = THBDA_TUNER;
                    int  hr           = propertySet.Set(propertyGuid, 0, _ptrOutBuffer2, 0x18, _thbdaBuf, thbdaLen);
                    if (hr != 0)
                    {
                        //throw new ApplicationException("TwinHan DiSEqC cmd:{0} failed 0x{1:X}", line, hr);
                    }
                    else
                    {
                        //throw new ApplicationException("TwinHan DiSEqC cmd:{0} succeeded", line);
                        success = true;
                    }
                    ReleaseComObject(propertySet);
                }
                ReleaseComObject(pin);
            }
            return(success);
        }
Exemple #3
0
        private void SetLnbData(bool lnbPower, int LNBLOFLowBand, int LNBLOFHighBand, int LNBLOFHiLoSW, int turnon22Khz,
                                int disEqcPort)
        {
            //throw new ApplicationException("Twinhan: SetLnb diseqc port:{0} 22khz:{1} low:{2} hi:{3} switch:{4} power:{5}", disEqcPort, turnon22Khz,
            // LNBLOFLowBand, LNBLOFHighBand, LNBLOFHiLoSW, lnbPower);
            int thbdaLen  = 0x28;
            int disEqcLen = 20;

            Marshal.WriteByte(_ptrDiseqc, 0, (byte)(lnbPower ? 1 : 0)); // 0: LNB_POWER
            Marshal.WriteByte(_ptrDiseqc, 1, 0);                        // 1: Tone_Data_Burst (Tone_Data_OFF:0 | Tone_Burst_ON:1 | Data_Burst_ON:2)
            Marshal.WriteByte(_ptrDiseqc, 2, 0);
            Marshal.WriteByte(_ptrDiseqc, 3, 0);
            Marshal.WriteInt32(_ptrDiseqc, 4, LNBLOFLowBand);  // 4: ulLNBLOFLowBand   LNBLOF LowBand MHz
            Marshal.WriteInt32(_ptrDiseqc, 8, LNBLOFHighBand); // 8: ulLNBLOFHighBand  LNBLOF HighBand MHz
            Marshal.WriteInt32(_ptrDiseqc, 12, LNBLOFHiLoSW);  //12: ulLNBLOFHiLoSW   LNBLOF HiLoSW MHz
            Marshal.WriteByte(_ptrDiseqc, 16, (byte)turnon22Khz);
            //16: f22K_Output (F22K_Output_HiLo:0 | F22K_Output_Off:1 | F22K_Output_On:2
            Marshal.WriteByte(_ptrDiseqc, 17, (byte)disEqcPort); //17: DiSEqC_Port
            Marshal.WriteByte(_ptrDiseqc, 18, 0);
            Marshal.WriteByte(_ptrDiseqc, 19, 0);
            Marshal.WriteInt32(_thbdaBuf, 0, 0x255e0082);
            //GUID_THBDA_CMD  = new Guid( "255E0082-2017-4b03-90F8-856A62CB3D67" );
            Marshal.WriteInt16(_thbdaBuf, 4, 0x2017);
            Marshal.WriteInt16(_thbdaBuf, 6, 0x4b03);
            Marshal.WriteByte(_thbdaBuf, 8, 0x90);
            Marshal.WriteByte(_thbdaBuf, 9, 0xf8);
            Marshal.WriteByte(_thbdaBuf, 10, 0x85);
            Marshal.WriteByte(_thbdaBuf, 11, 0x6a);
            Marshal.WriteByte(_thbdaBuf, 12, 0x62);
            Marshal.WriteByte(_thbdaBuf, 13, 0xcb);
            Marshal.WriteByte(_thbdaBuf, 14, 0x3d);
            Marshal.WriteByte(_thbdaBuf, 15, 0x67);
            Marshal.WriteInt32(_thbdaBuf, 16, (int)THBDA_IOCTL_SET_LNB_DATA); //dwIoControlCode
            Marshal.WriteInt32(_thbdaBuf, 20, (int)_ptrDiseqc.ToInt32());     //lpInBuffer
            Marshal.WriteInt32(_thbdaBuf, 24, disEqcLen);                     //nInBufferSize
            Marshal.WriteInt32(_thbdaBuf, 28, (int)IntPtr.Zero);              //lpOutBuffer
            Marshal.WriteInt32(_thbdaBuf, 32, 0);                             //nOutBufferSize
            Marshal.WriteInt32(_thbdaBuf, 36, (int)_ptrDwBytesReturned);      //lpBytesReturned

            IPin pin = DsFindPin.ByDirection(_captureFilter, PinDirection.Input, 0);

            if (pin != null)
            {
                DirectShowLib.IKsPropertySet propertySet = pin as DirectShowLib.IKsPropertySet;
                if (propertySet != null)
                {
                    Guid propertyGuid = THBDA_TUNER;
                    int  hr           = propertySet.Set(propertyGuid, 0, _ptrOutBuffer2, 0x18, _thbdaBuf, thbdaLen);
                    if (hr != 0)
                    {
                        //throw new ApplicationException("TwinHan SetLNB failed 0x{0:X}", hr);
                    }
                    else
                    {
                        //throw new ApplicationException("TwinHan SetLNB ok 0x{0:X}", hr);
                    }
                    ReleaseComObject(propertySet);
                }
                ReleaseComObject(pin);
            }
        }
Exemple #4
0
        public bool IsTwinhanCard()
        {
            if (_initialized)
            {
                return(_isTwinHanCard);
            }
            bool   success            = false;
            IntPtr ptrDwBytesReturned = Marshal.AllocCoTaskMem(4);

            try
            {
                int    thbdaLen = 0x28;
                IntPtr thbdaBuf = Marshal.AllocCoTaskMem(thbdaLen);
                try
                {
                    Marshal.WriteInt32(thbdaBuf, 0, 0x255e0082);
                    //GUID_THBDA_CMD  = new Guid( "255E0082-2017-4b03-90F8-856A62CB3D67" );
                    Marshal.WriteInt16(thbdaBuf, 4, 0x2017);
                    Marshal.WriteInt16(thbdaBuf, 6, 0x4b03);
                    Marshal.WriteByte(thbdaBuf, 8, 0x90);
                    Marshal.WriteByte(thbdaBuf, 9, 0xf8);
                    Marshal.WriteByte(thbdaBuf, 10, 0x85);
                    Marshal.WriteByte(thbdaBuf, 11, 0x6a);
                    Marshal.WriteByte(thbdaBuf, 12, 0x62);
                    Marshal.WriteByte(thbdaBuf, 13, 0xcb);
                    Marshal.WriteByte(thbdaBuf, 14, 0x3d);
                    Marshal.WriteByte(thbdaBuf, 15, 0x67);
                    Marshal.WriteInt32(thbdaBuf, 16, (int)THBDA_IOCTL_CHECK_INTERFACE); //control code
                    Marshal.WriteInt32(thbdaBuf, 20, (int)IntPtr.Zero);
                    Marshal.WriteInt32(thbdaBuf, 24, 0);
                    Marshal.WriteInt32(thbdaBuf, 28, (int)IntPtr.Zero);
                    Marshal.WriteInt32(thbdaBuf, 32, 0);
                    Marshal.WriteInt32(thbdaBuf, 36, (int)ptrDwBytesReturned);

                    IPin pin = DsFindPin.ByDirection(captureFilter, PinDirection.Input, 0);
                    if (pin != null)
                    {
                        DirectShowLib.IKsPropertySet propertySet = pin as DirectShowLib.IKsPropertySet;
                        if (propertySet != null)
                        {
                            Guid propertyGuid = THBDA_TUNER;

                            int hr = propertySet.Set(propertyGuid, 0, thbdaBuf, thbdaLen, thbdaBuf, thbdaLen);
                            if (hr == 0)
                            {
                                //throw new ApplicationException("Twinhan card detected");
                                success = true;
                            }
                            ReleaseComObject(propertySet);
                        }
                        ReleaseComObject(pin);
                    }
                }
                finally
                {
                    Marshal.FreeCoTaskMem(thbdaBuf);
                }
            }
            finally
            {
                Marshal.FreeCoTaskMem(ptrDwBytesReturned);
            }
            return(success);
        }