// the "connection_status" event occurs when a new connection is established public void ConnectionStatusEvent(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { String log = String.Format("ble_evt_connection_status: connection={0}, flags={1}, address=[ {2}], address_type={3}, conn_interval={4}, timeout={5}, latency={6}, bonding={7}" + Environment.NewLine, e.connection, e.flags, ByteArrayToHexString(e.address), e.address_type, e.conn_interval, e.timeout, e.latency, e.bonding ); Console.Write(log); ThreadSafeDelegate(delegate { txtLog.AppendText(log); }); if ((e.flags & 0x05) == 0x05) { // connected, now perform service discovery connection_handle = e.connection; ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("Connected to {0}", ByteArrayToHexString(e.address)) + Environment.NewLine); }); Byte[] cmd = bglib.BLECommandATTClientReadByGroupType(e.connection, 0x0001, 0xFFFF, new Byte[] { 0x00, 0x28 }); // "service" UUID is 0x2800 (little-endian for UUID uint8array) #if PRINT_DEBUG ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); }); #endif bglib.SendCommand(serialAPI, cmd); // update state app_state = STATE_FINDING_SERVICES; } }
public void ConnectionStatusEvent(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { if ((e.flags & 0x01) != 0) // connection_connected { this.ErrorValue.Text = ""; this.ErrorMessage.Text = ""; this.bleSemaphore.Release(); } }
//ble_evt_connection_status connection public void ConnectionStatusEvent(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { String log = string.Format("Connection: {0}, Flags: {1}, Addr: {2}\r\n", e.connection, e.flags, e.address[0]); Log = log; int add = 0; RcvByte[add++] = e.connection; RcvByte[add++] = e.flags; for (int i = 0; i < e.address.Length; i++) { RcvByte[add++] = e.address[i]; } RcvEventType = EventConnSts; RcvResponseType = -1; }
public void ConnectionStatusEvent(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { String log = String.Format("ble_evt_connection_status: connection={0}, flags={1}, address=[ {2}], address_type={3}, conn_interval={4}, timeout={5}, latency={6}, bonding={7}" + Environment.NewLine, e.connection, e.flags, ByteArrayToHexString(e.address), e.address_type, e.conn_interval, e.timeout, e.latency, e.bonding ); Console.Write(log); if ((e.flags & 0x05) == 0x05) { // connected, now perform service discovery Tool t; if (!localTools.TryGetValue(ByteArrayToHexString(e.address), out t)) { Console.WriteLine("Tool not found on connection!"); return; } // connected, now perform service discovery connection_handle = e.connection; byte[] payload = new byte[] { 0x01, //Message type -- LOCAL_MEM_ACCESS (write) 0x01, //Sequence ID 0x03, //Data length 0xA0, 0x23, //Local data address 0x01, //Data to write 0x00, //Checksum MSB 0xc9 //Checksum LSB }; Byte[] cmd = bglib.BLECommandATTClientAttributeWrite(e.connection, 0x000F, payload); bglib.SendCommand(serialAPI, cmd); Console.WriteLine("Connected now discovering services"); } }
//------------------------------------------------------------------------------------------------------------- // Event handler for the ConnectionStatus event. // The "Connection_Status" event occurs when a new connection is established. public void ConnectionStatusEvent(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { String log = String.Format("ble_evt_connection_status: connection={0}, flags={1}, address=[ {2}], address_type={3}, conn_interval={4}, timeout={5}, latency={6}, bonding={7}" + Environment.NewLine, e.connection, e.flags, ByteArrayToHexString(e.address), e.address_type, e.conn_interval, e.timeout, e.latency, e.bonding ); Console.Write(log); ThreadSafeDelegate(delegate { txtLog.AppendText(log); }); // Check the flags to see if a connection was completed. // Ref: p. 41 for links, see p. 96 for flag values if ((e.flags & 0x05) == 0x05) { // Connected, now perform service discovery. // Save the connection_handle value. connection_handle = e.connection; ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("Connected to {0}", ByteArrayToHexString(e.address)) + Environment.NewLine); }); // Create the ATTClientReadByGroup command. // "service" UUID is 0x2800 (little-endian for UUID uint8array). // Ref: https://www.bluetooth.com/specifications/gatt/declarations // Get a "list" of all services provided. Byte[] cmd = bglib.BLECommandATTClientReadByGroupType( e.connection, 0x0001, 0xFFFF, new Byte[] { 0x00, 0x28 }); // DEBUG: display bytes written ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); }); // Send the command, triggering the ATTClientGroupFoundEvent and // the ProcedureCompleted event. Ref. p. 53. bglib.SendCommand(serialAPI, cmd); // Update the application state. app_state = STATE_FINDING_SERVICES; } }
// the "connection_status" event occurs when a new connection is established //连接事件 //This event indicates the connection status and parameters. //Data field //[4]=uint8, connection handle; //[5]=uint8,flags;connection status flags use connstatus-enumerator. //[6~11]=ad_addr,address;remote device bluetooth address. //[12]=uint8,address_type; Remote address type. //[13~14]=uint16,conn_interval; Current connection interval(units of 1.25ms); //[15~16]=uint16,timeout; Current supervision timeout(units of 10ms); //[17~18]=uint16,latency; Slave latency which tells how many connection intervals the slave may skip. //[19]=uint8,bonding; Bonding handle if the device has been bonded with. Otherwise:0xFF; public void EventConnectStatus(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { if (comDev.IsOpen == false) { return; } //flags: //bit.0 = connection_connected; the connection exists to a remote device. //bit.1 = connection_encrypted; the connection is encrypted. //bit.2 = connection_completed flag, which is used to tell a new connection has been created. //bit.3 = connection_parameters_change; the connection parameters have changed and. It is set when connection parameters have changed due to a link layer operation. if ((e.flags & 0x05) != 0) { // DEBUG: display bytes written ThreadSafeDelegate(delegate { splitTab1_Main.Panel1Collapsed = true; splitTab1_Main.Panel2Collapsed = false; btConnect.Image = Properties.Resources.BMP_GREEN; stsLb_ConnSts.Image = Properties.Resources.BMP_GREEN; }); // "find primary service" UUID is 0x2800 (little-endian for UUID uint8array) //Byte[] cmd = bglib.BLECommandATTClientReadByGroupType(e.connection, 0x0001, 0xFFFF, new Byte[] { 0x00, 0x28 }); // bglib.SendCommand(comDev, cmd); // connected, now perform service discovery c_BleDev.ConnHandle = e.connection; c_BleDev.MacAddr = e.address.ToString(); c_BleDev.AddrType = e.address_type; c_BleDev.State = GhpBle.ACTTION_SCAN_PRIMSRV; c_BleDev.Bonding = e.bonding; //if(e.bonding == 0xFF) //{ // byte[] cmd2 = bglib.BLECommandSMEncryptStart(e.connection, 1); // bglib.SendCommand(comDev, cmd2); //} } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void BLEConnectionStatusEvent(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { Application.Current.Dispatcher.Invoke(delegate { MessageWriter.LogWrite("ble_evt_connection_status: ", string.Format("connection={0}, flags={1}, address=[ {2}], address_type={3}, conn_interval={4}, timeout={5}, latency={6}, bonding={7}", e.connection, e.flags, BitConverter.ToString(e.address), e.address_type, e.conn_interval, e.timeout, e.latency, e.bonding)); // Identify peripheral BLEPeripheral peripheral = FindDiscoveredPeripheral(e.address); if (peripheral == null) { return; } // Has a new connection been established? if ((e.flags & 0x05) == 0x05) { // Add to collection if (!connectedDevices.Contains(peripheral)) { connectedDevices.Add(peripheral); } // The connection is established peripheral.ConnectionState = BLEPeripheral.ConnState.Connected; MessageWriter.LogWrite("Connected to " + peripheral.Name); BLEPerformNextTask(peripheral); } }); }
//ble_evt_connection_status connection public void ConnectionStatusEvent(object sender, Bluegiga.BLE.Events.Connection.StatusEventArgs e) { String log = string.Format("Connection: {0}, Flags: {1}, Addr: {2}\r\n", e.connection, e.flags, e.address[0]); ThreadSafeDelegate(delegate { rtxtLog.Text = ""; rtxtLog.AppendText(log); }); }