internal static void Assert_IsConnected(IsConnectedState expected, CommonRfcommStream conn, IBluetoothClient cli, string descr) { switch (expected) { case IsConnectedState.Closed: Assert.IsFalse(conn.LiveConnected, "conn.LiveConnected " + descr); Assert.IsFalse(conn.Connected, "conn.Connected " + descr); Assert.IsFalse(cli.Connected, "cli.Connected " + descr); break; case IsConnectedState.Connected: Assert.IsTrue(conn.LiveConnected, "conn.LiveConnected " + descr); Assert.IsTrue(conn.Connected, "conn.Connected " + descr); Assert.IsTrue(cli.Connected, "cli.Connected " + descr); break; case IsConnectedState.RemoteCloseAndBeforeAnyIOMethod: Assert.IsFalse(conn.LiveConnected, "conn.LiveConnected " + descr); // These two aren't strict through........... Assert.IsTrue(conn.Connected, "conn.Connected " + descr); Assert.IsTrue(cli.Connected, "cli.Connected " + descr); break; default: break; } }
public MainView() { InitializeComponent(); _bluetoothClient = DependencyService.Get <IBluetoothClient>(); /* * _bluetoothClient.DeviceDiscoveryStarted += (o, t) => * { * * }; * _bluetoothClient.DeviceDiscovered += (o, t) => * { * var query = DiscoveredDevices.FirstOrDefault(x => x.Name == t.Device.Name && x.Address == t.Device.Address); * * if (query == null) * { * DiscoveredDevices.Add(t.Device); * } * * }; * _bluetoothClient.DeviceDiscoverEnded += (o, t) => * { * * };*/ listViewPaired.ItemsSource = PairedDevices; //listViewDiscovered.ItemsSource = DiscoveredDevices; }
/// <summary> /// Accepts a pending connection request. /// </summary> /// - /// <remarks>AcceptClient is a blocking method that returns a /// <see cref="T:InTheHand.Net.Sockets.L2CapClient"/> that you can use to send and receive data. /// Use the <see cref="Pending"/> method to determine if connection /// requests are available in the incoming connection queue if you want /// to avoid blocking. /// <para>Use the <see cref="L2CapClient.GetStream"/> method to obtain /// the underlying <see cref="System.IO.Stream"/> of the returned /// <see cref="T:InTheHand.Net.Sockets.L2CapClient"/>. /// The <see cref="System.IO.Stream"/> will provide you with methods for /// sending and receiving with the remote host. /// When you are through with the <see cref="T:InTheHand.Net.Sockets.L2CapClient"/>, be sure /// to call its <see cref="L2CapClient.Close"/> method. /// </para> /// </remarks> /// - /// <returns>A <see cref="T:InTheHand.Net.Sockets.L2CapClient"/> used to send and receive data.</returns> /// - /// <exception cref="T:System.InvalidOperationException">Listener is stopped.</exception> public L2CapClient AcceptClient() { IBluetoothClient cli0 = m_impl.AcceptBluetoothClient(); var cli = new L2CapClient(cli0); return(cli); }
public BTPairPage() { InitializeComponent(); this.Title = "Bluetooth Setting"; ButtonGetPaired.Clicked += ButtonGetPaired_OnClicked; _bluetoothClient = DependencyService.Get <IBluetoothClient>(); listViewPaired.ItemsSource = PairedDevices; }
public App(IBluetoothClient bluetoothClient) { InitializeComponent(); BluetoothClient = bluetoothClient; MainPage = new NavigationPage(new ConnectionPage()); }
public IBluetoothClient EndAcceptBluetoothClient(IAsyncResult asyncResult) { AsyncResult_BABc ar2 = (AsyncResult_BABc)asyncResult; CommonRfcommStream strm = ar2.EndInvoke(); IBluetoothClient cli0 = GetBluetoothClientForListener(strm); Debug.Assert(cli0.Connected, "cli0.Connected"); return(cli0); }
//-------- private static void Create_BtCli(out Mockery mkry, out IBluesoleilApi api, out BluesoleilFactory fcty, out IBluetoothClient cli) { mkry = new Mockery(); api = mkry.NewMock <IBluesoleilApi>(); // Expect.Exactly(2).On(api).Method("Btsdk_IsSDKInitialized") .WithAnyArguments() .Will(Return.Value(false)); Expect.Once.On(api).Method("Btsdk_IsServerConnected") .WithAnyArguments() .Will(Return.Value(false)); // Expect.AtLeastOnce.On(api).Method("Btsdk_Init") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); // //Expect.AtLeastOnce.On(api).Method("Btsdk_IsBluetoothReady") // .WithAnyArguments() // .Will(Return.Value(true)); Expect.Once.On(api).Method("Btsdk_IsServerConnected") .WithAnyArguments() .Will(Return.Value(true)); Expect.Once.On(api).Method("Btsdk_IsBluetoothHardwareExisted") .WithAnyArguments() .Will(Return.Value(true)); Expect.AtLeastOnce.On(api).Method("Btsdk_IsSDKInitialized") .WithAnyArguments() .Will(Return.Value(true)); Expect.AtLeastOnce.On(api).Method("Btsdk_IsServerConnected") .WithAnyArguments() .Will(Return.Value(true)); // Expect.Once.On(api).Method("Btsdk_GetLocalDeviceAddress") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); Expect.Once.On(api).Method("Btsdk_GetLocalName") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); Expect.Once.On(api).Method("Btsdk_GetLocalDeviceClass") .With(Is.Out) .Will(Return.Value(BtSdkError.OK), new NMock2.Actions.SetIndexedParameterAction(0, (uint)0)); Expect.Once.On(api).Method("Btsdk_GetLocalLMPInfo") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); // fcty = new BluesoleilFactory(api); mkry.VerifyAllExpectationsHaveBeenMet(); cli = fcty.DoGetBluetoothClient(); mkry.VerifyAllExpectationsHaveBeenMet(); }
internal BluetoothClient(IBluetoothClient impl) { m_impl = impl; }
protected virtual IBluetoothClient GetBluetoothClientForListener(CommonRfcommStream strm) { IBluetoothClient cli0 = m_factory.DoGetBluetoothClientForListener(strm); return(cli0); }
internal SerialPortNetworkStream(ISerialPortWrapper port, IBluetoothClient cli) : base(port.BaseStream) { _port = port; }
internal SerialPortNetworkStream(SerialPort port, IBluetoothClient cli) : this(new SerialPortWrapper(port), cli) { }
public static async Task <List <PCLBluetooth.BluetoothPrinter.BluetoothPrinter> > FindPrinters(this IBluetoothClient client) { const string generalPrinterIdentifier = "00001101-0000-1000-8000-00805f9b34fb"; var printers = (await client.FindDevicesWithIdentifier(generalPrinterIdentifier)).Select(x => new PCLBluetooth.BluetoothPrinter.BluetoothPrinter(x)).ToList(); return(printers); }
internal L2CapClient(IBluetoothClient impl) { var impl2 = (IL2CapClient)impl; m_impl = impl2; }
private void ExpectNewWay(bool doMockSerialPort, out Mockery mkry, out IBluesoleilApi api, out BluesoleilFactory fcty, out IBluetoothClient cli, out UInt32 comSerialNum, out byte comPort8) { Create_BtCli(out mkry, out api, out fcty, out cli); if (doMockSerialPort) { ((BluesoleilClient)cli).CreateSerialPortMethod = delegate() { //var sp = mkry.NewMock<ISerialPortWrapper>(); var sp = new InTheHand.Net.Tests.BlueSoleil.TestSerialPortWrapper(); return(sp); }; } // ExpectConnectSetup(api); // UInt32 hDev = 0x123; ExpectGetDeviceInfo(api, hDev); //-- comSerialNum = 0x1000; UInt32 comPort = 250; comPort8 = checked ((byte)comPort); UInt32 hConn = 0x1000000; // Expect.Once.On(api).Method("Btsdk_GetASerialNum") .WithNoArguments() .Will(Return.Value(comSerialNum)); Expect.Once.On(api).Method("Btsdk_PlugInVComm") .WithAnyArguments() .Will(Return.Value(true), new NMock2.Actions.SetIndexedParameterAction(1, comPort)); Expect.Once.On(api).Method("Btsdk_InitCommObj") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK)); Expect.Once.On(api).Method("Btsdk_ConnectEx") .WithAnyArguments() .Will(Return.Value(BtSdkError.OK), new NMock2.Actions.SetIndexedParameterAction(3, hConn) ); }
public void One() { var stuff = BluetopiaTesting.InitMockery_Client(new ClientTestingBluetopia.Behaviour()); // const uint NullPeriodLengths = 0; const uint InquiryLen = 12; const uint CallbackParameter = 0; const uint MaximumResponses = 255; var callback = stuff.GetFactory()._inquiryEventCallback; Expect.Once.On(stuff.MockedApi).Method("GAP_Perform_Inquiry") .With(stuff.StackId, StackConsts.GAP_Inquiry_Type.GeneralInquiry, NullPeriodLengths, NullPeriodLengths, InquiryLen, MaximumResponses, callback, CallbackParameter) .Will(Return.Value(BluetopiaError.OK)); // IBluetoothClient cli = stuff.CreateBluetoothClient(); var ar = cli.BeginDiscoverDevices(255, false, false, false, true, null, null); Assert.IsFalse(ar.IsCompleted, "IsCompleted 0"); // IntPtr pItemData = IntPtr.Zero; IntPtr pCompleteData = IntPtr.Zero; try { Structs.GAP_Inquiry_Entry_Event_Data itemData = new Structs.GAP_Inquiry_Entry_Event_Data( Addr1Bytes, new byte[] { 0x03, 0x02, 0x01 } ); pItemData = Marshal.AllocHGlobal(Marshal.SizeOf(itemData)); Marshal.StructureToPtr(itemData, pItemData, false); Structs.GAP_Event_Data item1 = new Structs.GAP_Event_Data( StackConsts.GAP_Event_Type.Inquiry_Entry_Result, pItemData); // const ushort NumDevices = 1; Structs.GAP_Inquiry_Event_Data completeData = new Structs.GAP_Inquiry_Event_Data( NumDevices /*, pCompleteDeviceData*/); pCompleteData = Marshal.AllocHGlobal(Marshal.SizeOf(completeData)); Marshal.StructureToPtr(completeData, pCompleteData, false); Structs.GAP_Event_Data complete = new Structs.GAP_Event_Data( StackConsts.GAP_Event_Type.Inquiry_Result, pCompleteData); // // using (var done = new ManualResetEvent(false)) { ThreadPool.QueueUserWorkItem(delegate { try { callback(stuff.StackId, ref item1, CallbackParameter); callback(stuff.StackId, ref complete, CallbackParameter); } finally { done.Set(); } }); bool signalled = done.WaitOne(30000); Debug.Assert(signalled, "NOT signalled"); } } finally { if (pItemData != IntPtr.Zero) { Marshal.FreeHGlobal(pItemData); } if (pCompleteData != IntPtr.Zero) { Marshal.FreeHGlobal(pCompleteData); } } // Thread.Sleep(200); Assert.IsFalse(ar.IsCompleted, "notIsCompleted2 before rnr"); Thread.Sleep(2500); // Space for (possible!) name queries Thread.Sleep(200); Assert.IsTrue(ar.IsCompleted, "IsCompleted3"); var deviceList = cli.EndDiscoverDevices(ar); Assert.AreEqual(1, deviceList.Length, "deviceList.Length"); var dev = deviceList[0]; Assert.AreEqual(BluetoothAddress.Parse("001122334455"), dev.DeviceAddress, "dev.DeviceAddress"); Assert.AreEqual(new ClassOfDevice(0x010203), dev.ClassOfDevice, "dev.ClassOfDevice"); // stuff.Mockery_VerifyAllExpectationsHaveBeenMet(); }
internal void SetDut(IBluetoothClient cli, BluetopiaRfcommStream conn) { _cli = cli; _conn = conn; }