

Код: Выделить всё
unit StreamReader;
{UnitStreamReaderImport copyright by CBArts(CBArts@tripod.de)}
interface
uses Windows;
const DISEQC_HIGH_NIBLE=$F0;
DISEQC_LOW_BAND =$00;
DISEQC_HIGH_BAND =$01;
DISEQC_VERTICAL =$00;
DISEQC_HORIZONTAL=$02;
DISEQC_POSITION_A=$00;
DISEQC_POSITION_B=$04;
DISEQC_OPTION_A =$00;
DISEQC_OPTION_B =$08;
type BytePointer=^Byte;
{$EXTERNALSYM CheckForDVB}
function CheckForDVB:boolean;cdecl;
{$EXTERNALSYM StartDVB}
function StartDVB:boolean;cdecl;
{$EXTERNALSYM StopDVB}
function StopDVB:boolean;cdecl;
{$EXTERNALSYM SendDiSEqC}
function SendDiSEqC(DiSEqCType:DWord;data:Byte):boolean;cdecl;
{$EXTERNALSYM SetChannel}
function SetChannel(freq,symb,pol,fec,lof1,lof2,lofsw:DWord):boolean;cdecl;
{$EXTERNALSYM SetFilter}
function SetFilter(pid:Word;DVBCALLBACK:Pointer;CallBackType,
Size:DWord;lpdwReserved:Pointer):boolean;cdecl;
{$EXTERNALSYM SetBitFilter}
function SetBitFilter(pid:Word;FilterData,FilterMask:BytePointer;
FilterLength:Byte; DVBCALLBACK:Pointer;
lpdwReserved:Pointer):boolean;cdecl;
{$EXTERNALSYM DelFilter}
function DelFilter(dwReserved:DWord):boolean;cdecl;
implementation
const srdll='StreamReader.dll';
function CheckForDVB; external srdll name 'CheckForDVB';
function StartDVB; external srdll name 'StartDVB';
function StopDVB; external srdll name 'StopDVB';
function SendDiSEqC; external srdll name 'SendDiSEqC';
function SetChannel; external srdll name 'SetChannel';
function SetFilter; external srdll name 'SetFilter';
function SetBitFilter;external srdll name 'SetBitFilter';
function DelFilter; external srdll name 'DelFilter';
end.
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Threading;
using System.Collections;
using System.IO;
namespace SkyLaboratory
{
public partial class Form1 : Form
{
FileStream f = null;
delegate void Log(string txt);
private void log(string txt)
{
if (logBox.InvokeRequired)
{
Log d = new Log(log);
logBox.Invoke(d, new object[] { txt });
}
else
{
logBox.Items.Add(txt);
}
Thread.Sleep(TimeSpan.FromTicks(1));
}
public delegate void CallbackStr(IntPtr pByteArray, UInt16 l);
public void str(IntPtr pByteArray, UInt16 l)
{
if (l == 0)
{
log("l len = 0");
return;
}
byte[] buff = new byte[l];
Marshal.Copy(pByteArray, buff, 0, l);
if (buff[0] != 0x47)
{
log("bad sync byte 0x47");
return;
}
if (buff[1] > 0x80)
{
log("bad sync byte 0x80");
return;
}
int i = 0;
f.Write(buff, i, l);
return;
}
[DllImport("streamreader.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool CheckForDVB();
[DllImport("streamreader.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool StartDVB();
[DllImport("streamreader.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool StopDVB();
[DllImport("streamreader.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SetChannel(uint frec, uint smyb, uint pol, uint fec, uint lof1, uint lof2, uint lofsw);
[DllImport("streamreader.dll", SetLastError = true, CharSet = CharSet.None)]
public static extern bool SetFilter(uint pid, CallbackStr lpFunc, uint CallBackType, uint size, ref uint lpfilter_num);
[DllImport("streamreader.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool DelFilter(uint filter_num);
[DllImport("streamreader.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool GetSignal(ref int sig);
uint FilterHandle;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
f = new FileStream("stream.dat", FileMode.Append);
}
private void button1_Click(object sender, EventArgs e)
{
CallbackStr callback = new CallbackStr(str);
log("start - ok");
if (!CheckForDVB()) { log("CheckForDVB - failed"); }
else
{
log("CheckForDVB - ok");
if (!StartDVB()) { log("StartDVB - failed"); }
else
{
log("StartDVB - ok");
uint lof1 = 9750000;
uint lof2 = 10600000;
uint lofsw = 11700000;
uint freq = 10845000;
uint sr = 27500000;
uint pol = 1;
uint fec = 0;
if (!SetChannel(freq, sr, pol, fec, lof1, lof2, lofsw)) { log("SetChannel - failed"); }
else
{
log("SetChannel - ok");
if (!SetFilter(8192, callback, 2, 0, ref FilterHandle))
{
log("SetFilter - failed");
}
else
{
log("SetFilter - ok");
}
}
}
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
f.Close();
}
}
}