private void ConnectToDevice() { if (curDeviceAddress == null) { DataGridViewRow selectedRow = dgvDeviceDiscovery.SelectedRows[0]; selectedDevice = (BtDevice)dgvDeviceDiscovery.CurrentCell.Value; curDeviceAddress = selectedDevice.DeviceAddress; } BtConnectionParameters cxParam = new BtConnectionParameters(); cxParam.ConnectionIntervalMs = 30; //cxParam.SlaveLatency = 0; //cxParam.SupervisionTimeoutMs = 10000; try { if (false && isBonded) { masterEmulator.Connect(curDeviceAddress, cxParam); } else { if (masterEmulator.Connect(curDeviceAddress, cxParam)) { //masterEmulator.Bond(); DiscoverPipes(); } } } catch (Exception ex) { DisplayErrorMessage(ex); } }
/// <summary> /// This event handler is called when a connection update request has been received. /// A connection update must be responded to in two steps: sending a connection update /// response, and performing the actual update. /// </summary> void OnConnectionUpdateRequest(object sender, ConnectionUpdateRequestEventArgs arguments) { Task.Factory.StartNew(() => { masterEmulator.SendConnectionUpdateResponse(arguments.Identifier, ConnectionUpdateResponse.Accepted); BtConnectionParameters updateParams = new BtConnectionParameters(); updateParams.ConnectionIntervalMs = arguments.ConnectionIntervalMinMs; updateParams.SupervisionTimeoutMs = arguments.ConnectionSupervisionTimeoutMs; updateParams.SlaveLatency = arguments.SlaveLatency; masterEmulator.UpdateConnectionParameters(updateParams); }); }
bool Connect(BtDevice device) { if (masterEmulator.IsDeviceDiscoveryOngoing) { masterEmulator.StopDeviceDiscovery(); } deviceName = GetDeviceName(device.DeviceInfo); AddToLog(string.Format("Connecting to {0}, Device name: {1}", device.DeviceAddress.ToString(), deviceName)); BtConnectionParameters connectionParams = new BtConnectionParameters(); connectionParams.ConnectionIntervalMs = 11.25; connectionParams.ScanIntervalMs = 250; connectionParams.ScanWindowMs = 200; bool connectSuccess = masterEmulator.Connect(device.DeviceAddress, connectionParams); return(connectSuccess); }
//===================================================================== //===================================================================== //===================================================================== //===================================================================== //===================================================================== public bool Connect_to_device(BtDevice device) { bool bStatus; //if (masterEmulator.IsDeviceDiscoveryOngoing) while (masterEmulator.IsDeviceDiscoveryOngoing) // TODO (maybe need this during debug run { masterEmulator.StopDeviceDiscovery(); } karelDumpDevice(device); //karel string deviceName = GetDeviceName(device.DeviceInfo); AddToLog(string.Format("Connecting to {0}, Device name: {1}", device.DeviceAddress.ToString(), deviceName)); BtConnectionParameters connectionParams = new BtConnectionParameters(); //TODO _nRFTD1 connection parameters may be different than for _nRFUart connectionParams.ConnectionIntervalMs = 11.25; connectionParams.ScanIntervalMs = 250; connectionParams.ScanWindowMs = 200; //TODO _nRFTD1 connection parameters may be different than for _nRFUart FLAG_connectionInProgress = true; bStatus = masterEmulator.Connect(device.DeviceAddress, connectionParams); if (bStatus == false) { FLAG_connectionInProgress = false; } return (bStatus); }
/// <summary> /// This event handler is called when a connection update request has been received. /// A connection update must be responded to in two steps: sending a connection update /// response, and performing the actual update. /// </summary> void meEv_OnConnectionUpdateRequest(object sender, ConnectionUpdateRequestEventArgs arguments) { Task.Factory.StartNew(() => { masterEmulator.SendConnectionUpdateResponse(arguments.Identifier, ConnectionUpdateResponse.Accepted); BtConnectionParameters updateParams = new BtConnectionParameters(); updateParams.ConnectionIntervalMs = arguments.ConnectionIntervalMinMs; updateParams.SupervisionTimeoutMs = arguments.ConnectionSupervisionTimeoutMs; updateParams.SlaveLatency = arguments.SlaveLatency; masterEmulator.UpdateConnectionParameters(updateParams); }); }
/// <summary> /// Connecting to the given device, and with the given connection parameters. /// </summary> /// <param name="device">Device to connect to.</param> /// <returns>Returns success indication.</returns> //bool Connect(BtDevice device) bool Connect_nRFUart(BtDevice device) { if (masterEmulator.IsDeviceDiscoveryOngoing) { masterEmulator.StopDeviceDiscovery(); } karelDumpDevice(device); //karel /* NG here*/ //karel - from Documentation karelLog("\r\n"); karelLog("\r\n"); karelLog("========== TESTING masterEmulator.DiscoverServices() ================\r\n"); karelLog("\r\n"); var attributes = masterEmulator.DiscoverServices(); foreach (var item in attributes) { Trace.WriteLine(item.ToString()); karelLog("-----> " + item.ToString()); } /**/ string deviceName = GetDeviceName(device.DeviceInfo); AddToLog(string.Format("Connecting to {0}, Device name: {1}", device.DeviceAddress.ToString(), deviceName)); BtConnectionParameters connectionParams = new BtConnectionParameters(); connectionParams.ConnectionIntervalMs = 11.25; connectionParams.ScanIntervalMs = 250; connectionParams.ScanWindowMs = 200; bool connectSuccess = masterEmulator.Connect(device.DeviceAddress, connectionParams); return connectSuccess; } #endif #if true /*_nRFTD1*/ bool Connect(BtDevice device) { //if (masterEmulator.IsDeviceDiscoveryOngoing) while (masterEmulator.IsDeviceDiscoveryOngoing) // TODO (maybe need this during debug run { masterEmulator.StopDeviceDiscovery(); } karelDumpDevice(device); //karel string deviceName = GetDeviceName(device.DeviceInfo); AddToLog(string.Format("Connecting to {0}, Device name: {1}", device.DeviceAddress.ToString(), deviceName)); BtConnectionParameters connectionParams = new BtConnectionParameters(); //TODO _nRFTD1 connection parameters may be different than for _nRFUart connectionParams.ConnectionIntervalMs = 11.25; connectionParams.ScanIntervalMs = 250; connectionParams.ScanWindowMs = 200; //TODO _nRFTD1 connection parameters may be different than for _nRFUart bool connectSuccess; connectSuccess = masterEmulator.Connect(device.DeviceAddress, connectionParams); return connectSuccess; } #endif }
public void Connect(BtDevice device) { if (masterEmulator.IsDeviceDiscoveryOngoing) masterEmulator.StopDeviceDiscovery(); BtConnectionParameters connParams = new BtConnectionParameters(); connParams.ConnectionIntervalMs = 7.5; connParams.SlaveLatency = 0; connParams.SupervisionTimeoutMs = 100; connectedDevice = device; masterEmulator.Connect(device.DeviceAddress, connParams); }