static void Main(string[] args) { const int frameSize = 128 * 32; var bridge = new ProPinballBridge.ProPinballDmd(392); Console.WriteLine("Bridge status: {0}", bridge.Status); if (bridge.Status != 0) { unsafe { Console.WriteLine("Error: {0}", new string(bridge.Error)); } } else { Console.WriteLine("Subscribing to Pro Pinball's message queue..."); unsafe { bridge.GetFrames(frame => { Console.WriteLine("Got frame!"); var f = new byte[frameSize]; Marshal.Copy((IntPtr)frame, f, 0, frameSize); }, err => { Console.WriteLine("Error: {0}", new string(err)); }, () => { Console.WriteLine("Done!"); }); } } }
public IObservable <DMDFrame> GetGray4Frames() { if (_framesGray4 != null) { return(_framesGray4); } CreateBridge(); Logger.Info("Subscribing to Pro Pinball's message queue..."); _framesGray4 = Observable.Create <DMDFrame>(o => { var len = Dimensions.Value.Width * Dimensions.Value.Height; // this is blocking, so use a new thread var thread = new Thread(() => { unsafe { _bridge.GetFrames(frame => { var arr = _dmdFrame.Update(Dimensions.Value.Width, Dimensions.Value.Height, new byte[len]); Marshal.Copy((IntPtr)frame, arr.Data, 0, len); o.OnNext(arr); }, err => { throw new ProPinballSlaveException(new string(err)); }, () => { Logger.Debug("Received exit signal from Pro Pinball, closing."); Process.GetCurrentProcess().Kill(); }); } }); thread.Start(); Logger.Debug("Subscribed to Pro Pinball's message queue."); return(Disposable.Create(() => { thread.Abort(); Logger.Debug("Disposing Pro Pinball's message queue..."); })); }); return(_framesGray4); }