Help Required StreamReader.dll in C#?

drhans

Member
Joined
Oct 5, 2009
Messages
45
Reaction score
43
Points
18
Age
44
Website
drhans.tv
My Satellite Setup
C-band: CM 240cm PF 34W-50W linear Avcomm feedring & OMT + 2x Astrotel Precision LNB & circular Avcomm polarizer + Zinwell LNBF, IRTE 180 cm 1W-34W + ESX241. DM820HD, VU+ Zero, DM500HDv2, Cisco D9865 AFN, TBS 5925 & 6983, XFinder
My Location
Prague
Hello

I'm trying to write an application using streamreader.dll to simply stream filtered transponder data over HTTP once a client requests that specific data. The client could be a Dreambox or OSEmu for example. Basically anything that will further process the data. After some not so great results in C++ I decided to use C# instead because I'm hoping the handling of client connections and threads plus the GUI will be somewhat easier.

streamreader.dll should work, right? And in part it does - i can tune in to a frequency and set filter, but the problem I'm having is with the callback function which is supposed to read the data. The problem is that I'm only getting one byte in the buffer, it's byte 0x47, which means it works in part, but where are the other 187 bytes? The len parameter clearly shows the streamingCB function got 188 bytes, yet the buffer contains just one. I'm stuck here and I have no idea if this is my c# coding error or incorrect use of the streamreader.dll.

Here's my code. And a screenshot of what I get is attached. Any help would be much appreciated. I think such application would be quite helpful, so far I don't think anything like this exists!

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
namespace SimpleSatServer
{
 /// <summary>
 /// Interaction logic for MainWindow.xaml
 /// </summary>
 /// 
 public class DVB_card
 {
 public DVB_card(string name, int id)
 {
 this.Name = name; this.Id = id;
 }
 public string Name
 { get; set; }
 public int Id
 { get; set; }
 }
 public partial class MainWindow : Window
 {
 public static MainWindow GUI { get; private set; }
 //[DllImport("dlltest.dll", CallingConvention = CallingConvention.Cdecl)]
 //public static extern void StreamingCB2(byte[] buffer, Int32 len);
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern bool StartDVBEx(Int32 index);
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern bool StopDVB();
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern bool CheckForDVB();
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern UInt32 GetCaps();
 public delegate void DVBCallbackFunc(int index, String name);
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern bool CheckForDVBEx(DVBCallbackFunc func);
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern bool GetSignal(ulong Level, ulong Quality);
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public static extern bool SetChannelEx(Int32 freq, Int32 symbrate, Int32 pol, Int32 fec, Int32 lof1, Int32 lof2, Int32 lofsw, Int32 mod);
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public unsafe static extern bool GetSignalExEx(bool* pPresent, bool* pLock, int* pRFLevel, float* pSNR, float* pBER);
 public unsafe delegate void StreamingCallbackFunc(byte[] buffer, int len);
 [DllImport("StreamReader.dll", CallingConvention = CallingConvention.Cdecl)]
 public unsafe static extern bool SetFilter(int pid, StreamingCallbackFunc lpFunc, Int32 CallBackType, Int32 size, Int32* lpfilter_num);
 
 
 public MainWindow()
 {
 InitializeComponent();
 log("Looking for DVB tuners... ");
 CheckForDVBEx(InfoCB);
 dvb_dev_list.SelectedIndex = 0;
 }
 
 public void InfoCB(int index, String name)
 {
 dvb_dev_list.Items.Add(new DVB_card(name, index));
 log("Found DVB tuner " + name);
 }
 
 public void StreamingCB(byte[] buffer, int len)
 {
 log("BUFFER LEN: " + buffer.Length);
 log("LEN: " + len.ToString());
 log("BUFFER: " + BitConverter.ToString(buffer));
 //System.IO.File.WriteAllBytes("file.ts", buffer);
 }
 
 public void log(string tolog)
 {
 try { 
 this.Dispatcher.Invoke(() =>
 {
 log_window.AppendText(DateTime.Now.ToString("H:mm:ss") + ": " + tolog + "\n");
 log_window.ScrollToEnd();
 });
 }
 catch
 {
 }
 
 }

 private void Button_Click(object sender, RoutedEventArgs e)
 {
 //public static extern void DisplayHelloFromDLL();
 Int32 nr = dvb_dev_list.SelectedIndex;
 if (!StartDVBEx(nr))
 {
 log(string.Format("StartDVBEx({0}) fail", nr));
 dvb_dev_list.Background = Brushes.Red;
 }
 else
 {
 log(string.Format("StartDVBEx({0}) OK", nr));
 dvb_dev_list.Background = Brushes.Green;
 dvb_deb_stop.IsEnabled = true;
 dvb_deb_start.IsEnabled = false;
 dvb_dev_list.IsEnabled = false; 
 } 
 }
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
 
 if (!StopDVB())
 {
 log(string.Format("StopDVB err"));
 }
 else
 {
 log(string.Format("StopDVB OK"));
 dvb_dev_list.ClearValue(Button.BackgroundProperty);
 dvb_dev_list.IsEnabled = true;
 dvb_deb_start.IsEnabled = true;
 dvb_deb_stop.IsEnabled = false;
 sig_info_lock.ClearValue(Button.BackgroundProperty);
 sig_info_snr.Content = "";
 }
 }
 private unsafe void btn_signal_info_Click(object sender, RoutedEventArgs e)
 {
 sig_info_lock.ClearValue(Button.BackgroundProperty);
 sig_info_snr.Content = "";
 if (!SetChannelEx(11804000, 27500000, 1, 0, 97500000, 10600000, 11700000, 0))
 {
 log(string.Format("SetChannelEx err"));
 }
 bool pPresent;
 bool pLock;
 int pRFLevel;
 float pSNR;
 float pBER;
 GetSignalExEx(&pPresent, &pLock, &pRFLevel, &pSNR, &pBER);
 log("Signal Present: " + pPresent.ToString());
 log("Signal Lock: " + pLock.ToString());
 log("Signal SNR: " + pSNR.ToString());
 log("Signal BER: " + pBER.ToString());
 log("Signal RF: " + pRFLevel.ToString());
 if (pLock)
 {
 sig_info_lock.Background = Brushes.Green;
 sig_info_snr.Content = pSNR.ToString() + " dB";
 }
 int filter1;
 StreamingCallbackFunc sh = StreamingCB;
 if (!SetFilter(17, sh, 4, 1, &filter1))
 {
 log("Filter fail");
 }
 else
 {
 log("Filter set");
 }
 }
 }
}
 

Attachments

  • stream.PNG
    stream.PNG
    15.4 KB · Views: 9

Captain Jack

Burnt out human
Joined
Oct 21, 2006
Messages
11,797
Reaction score
7,980
Points
113
My Satellite Setup
See signature
My Location
North Somerset
I would get in touch with @CrazyCat directly for some help or @tempo who has contact with him.
 

CrazyCat

Regular Member
Joined
Oct 18, 2012
Messages
136
Reaction score
208
Points
43
Website
crazycat69.narod.ru
My Satellite Setup
13E 4.8E 4W: Dish Variant CA-902 0.95m + 3xLNB Ku-Universal DreamSat DS8 + DiseqC 1.0
30W-95E: Dish Strong 0.95m + LNB Ku-Universal ALPS BSTE8-751B + Motor PowerTech DG240
OpenBox X-800
TT S-1401 PCI
Omicom S2 PCI
TBS 5980 USB2.0
My Location
Ukraine, Kharkov
For C# interface ask Cjcr ( EBSPro written with C#).

I am old system programmer and hate any virtual machine languages like C#, VB or Java :)
 

drhans

Member
Joined
Oct 5, 2009
Messages
45
Reaction score
43
Points
18
Age
44
Website
drhans.tv
My Satellite Setup
C-band: CM 240cm PF 34W-50W linear Avcomm feedring & OMT + 2x Astrotel Precision LNB & circular Avcomm polarizer + Zinwell LNBF, IRTE 180 cm 1W-34W + ESX241. DM820HD, VU+ Zero, DM500HDv2, Cisco D9865 AFN, TBS 5925 & 6983, XFinder
My Location
Prague
For C# interface ask Cjcr ( EBSPro written with C#).

I am old system programmer and hate any virtual machine languages like C#, VB or Java :)

I understand, and now it's looking that it will be better to use c++ because I got nowhere with the DLL alone, Cjcr won't help, he makes money on EBSPro (including from me :) so he won't share his know how with potential competitors :)
 
Top