public IList <BluetoothDevice> GetListOfNotConnectedDevices() { var btClient = new InTheHand.Net.Sockets.BluetoothClient(); InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = btClient.DiscoverDevices(); var devices = (IList <BluetoothDevice>)array.Where(a => !a.Connected).Select(a => new BluetoothDevice(a)).ToList(); return(devices); }
private void menuItem1_Click(object sender, EventArgs e) { InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient(); InTheHand.Net.Sockets.BluetoothDeviceInfo[] devices = bc.DiscoverDevices(); if (devices.Length > 0) { /* * object o = InTheHand.ActivatorHelper.CreateInstance(typeof(InTheHand.Net.Bluetooth.SdpStream)); * * InTheHand.Net.Bluetooth.ISdpStream ss = (InTheHand.Net.Bluetooth.ISdpStream)o; // new InTheHand.Net.Bluetooth.SdpStream(); * * foreach (InTheHand.Net.Sockets.BluetoothDeviceInfo d in devices) * { * if (MessageBox.Show(d.DeviceName,"Device", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.Yes) * { * byte[] record = devices[0].GetServiceRecordsUnparsed(InTheHand.Net.Bluetooth.BluetoothService.L2CapProtocol)[0]; * * //uint err; * //ss.Validate(pRecord, record.Length, out err); * int found; * ss.VerifySequenceOf(record, record.Length, InTheHand.Net.Bluetooth.SDP_TYPE.SEQUENCE, null, out found); * * int numrecs = found; * IntPtr[] recs = new IntPtr[found]; * * ss.RetrieveRecords(record, record.Length, recs, ref numrecs); * InTheHand.Net.Bluetooth.ISdpRecord[] records = new InTheHand.Net.Bluetooth.ISdpRecord[numrecs]; * for (int i = 0; i < numrecs; i++) * { * InTheHand.Net.Bluetooth.SdpWalker w = new InTheHand.Net.Bluetooth.SdpWalker(); * * records[i] = (InTheHand.Net.Bluetooth.ISdpRecord)InTheHand.Runtime.InteropServices.MarshalHelper.GetTypedObjectForIUnknown(recs[i], typeof(InTheHand.Net.Bluetooth.ISdpRecord)); * records[i].Walk(w); * //InTheHand.Net.Bluetooth.NodeData n; * IntPtr n = System.Runtime.InteropServices.Marshal.AllocHGlobal(32); * Guid g; * records[i].GetServiceClass(out g); * if (g == InTheHand.Net.Bluetooth.BluetoothService.SerialPort) * { * records[i].GetAttribute((ushort)InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ProtocolDescriptorList, n); * Console.Write(System.Runtime.InteropServices.Marshal.ReadInt16(n).ToString()); * } * else * { * Console.Write(g.ToString()); * } * //records[i].GetAttribute((ushort)InTheHand.Net.Bluetooth.AttributeIds.ServiceDiscoveryServerAttributeId.ServiceDatabaseState, n); * //InTheHand.Net.Bluetooth.SDP_SPECIFICTYPE st = (InTheHand.Net.Bluetooth.SDP_SPECIFICTYPE)BitConverter.ToInt16(n, 2); * * * } * } * }*/ } }
private void btnDiscover_Click(object sender, EventArgs e) { InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient(); InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices(); for (int i = 0; i < array.Length; i++) { this.address_array[i] = array[i].DeviceAddress; this.lstDevices.Items.Add(array[i].DeviceName); } }
void bg_DoWork(object sender, DoWorkEventArgs e) { List<Device> devices = new List<Device>(); InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient(); InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices(); int count = array.Length; for (int i = 0; i < count; i++) { Device device = new Device(array[i]); devices.Add(device); } e.Result = devices; }
void bg_DoWork(object sender, DoWorkEventArgs e) { List <Device> devices = new List <Device>(); InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient(); InTheHand.Net.Sockets.BluetoothDeviceInfo[] array = bc.DiscoverDevices(); int count = array.Length; for (int i = 0; i < count; i++) { Device device = new Device(array[i]); devices.Add(device); } e.Result = devices; }
private void Form1_Load(object sender, EventArgs e) { InTheHand.Net.Sockets.BluetoothClient bc = new InTheHand.Net.Sockets.BluetoothClient(); }
public static bool InterfaceConnect(string port, object parameter) { if (IsInterfaceOpen()) { return(true); } FastInit = false; ConvertBaudResponse = false; AutoKeyByteResponse = false; AdapterType = -1; AdapterVersion = -1; LastCommTick = DateTime.MinValue.Ticks; if (!port.StartsWith(PortId, StringComparison.OrdinalIgnoreCase)) { InterfaceDisconnect(); return(false); } _connectPort = port; _reconnectRequired = false; try { string portData = port.Remove(0, PortId.Length); if ((portData.Length > 0) && (portData[0] == ':')) { // special id string portName = portData.Remove(0, 1); string[] stringList = portName.Split('#', ';'); if (stringList.Length == 1) { SerialPort.PortName = portName; SerialPort.BaudRate = 115200; SerialPort.DataBits = 8; SerialPort.Parity = System.IO.Ports.Parity.None; SerialPort.StopBits = System.IO.Ports.StopBits.One; SerialPort.Handshake = System.IO.Ports.Handshake.None; SerialPort.DtrEnable = false; SerialPort.RtsEnable = false; SerialPort.ReadTimeout = 1; SerialPort.Open(); } #if BLUETOOTH else if (stringList.Length == 2) { InTheHand.Net.BluetoothEndPoint ep = new InTheHand.Net.BluetoothEndPoint(InTheHand.Net.BluetoothAddress.Parse(stringList[0]), InTheHand.Net.Bluetooth.BluetoothService.SerialPort); InTheHand.Net.Sockets.BluetoothClient cli = new InTheHand.Net.Sockets.BluetoothClient(); cli.SetPin(stringList[1]); cli.Connect(ep); BtStream = cli.GetStream(); BtStream.ReadTimeout = 1; } #endif else { InterfaceDisconnect(); return(false); } } else { InterfaceDisconnect(); return(false); } } catch (Exception ex) { Ediabas?.LogFormat(EdiabasNet.EdLogLevel.Ifh, "*** Connect failure: {0}", ex.Message); InterfaceDisconnect(); return(false); } return(true); }