public void Back() { for (int i = CharacterParent.childCount - 1; i >= 0; i--) { DestroyImmediate(CharacterParent.GetChild(i).gameObject); } writeCharacterInfo = null; bLEExample.DeviceInfoBackScan(); }
public void OnDiscoveryCharacteristic(CharacteristicInfo characterInfo) { Debug.Log("搜索到Character:" + characterInfo.UUID + " 所属Service:" + characterInfo.ServiceUUID + " 是否可读:" + characterInfo.CanRead + " 是否可写:" + characterInfo.CanWrite + " 是否可Notify:" + characterInfo.CanNotify); Instantiate(CharacterPrefab, CharacterParent).AddComponent <DeviceInfoCharacter>().Init(characterInfo, bLEExample); if (characterInfo.CanWrite) { writeCharacterInfo = characterInfo; } }
public void Init(CharacteristicInfo characteristicInfo, BLEExample bLEExample) { this.characteristicInfo = characteristicInfo; this.bLEExample = bLEExample; transform.GetChild(0).GetComponent <Text>().text = characteristicInfo.ServiceUUID; transform.GetChild(0).GetChild(0).GetComponent <Text>().text = characteristicInfo.UUID; transform.GetChild(3).GetComponent <Button>().onClick.AddListener(() => { this.bLEExample.DeviceInfoToCharacterInfo(characteristicInfo); }); }
public void Init(CharacteristicInfo characteristicInfo) { this.characteristicInfo = characteristicInfo; ServiceUUID.text = characteristicInfo.ServiceUUID; CharacterUUID.text = characteristicInfo.UUID; string operationStr = ""; DeviceName.text = characteristicInfo.bLEDeviceInfo.DeviceName; if (characteristicInfo.CanRead) { operationStr += "Read"; ReadBtn.SetActive(true); } else { ReadBtn.SetActive(false); } if (characteristicInfo.CanWrite) { if (operationStr != "") { operationStr += ","; } operationStr += "Write"; WriteObj.SetActive(true); writeDefault.SetActive(true); if (characteristicInfo.CanNotify || characteristicInfo.CanRead) { ReadTrans.gameObject.SetActive(true); readDefault.SetActive(true); //设置位置,有写位置则要下移 ReadTrans.anchoredPosition = new Vector2(8.5f, -620); } else { ReadTrans.gameObject.SetActive(false); readDefault.SetActive(false); } } else { WriteObj.SetActive(false); writeDefault.SetActive(false); if (characteristicInfo.CanNotify || characteristicInfo.CanRead) { ReadTrans.gameObject.SetActive(true); readDefault.SetActive(true); //设置位置,没有写位置则要上移 ReadTrans.anchoredPosition = new Vector2(8.5f, -370); } else { ReadTrans.gameObject.SetActive(false); readDefault.SetActive(false); } } if (characteristicInfo.CanNotify) { if (operationStr != "") { operationStr += ","; } operationStr += "Notify"; //默认订阅,底层会防止多次订阅 BLEManager.Instance.NotifyCharacteristic(characteristicInfo, NotifyInitResult, NotifyInfoCallback); } else { NotifyBtn.SetActive(false); } OperationText.text = operationStr; }
public void Init(CharacteristicInfo characteristicInfo, BLEExample bLEExample) { this.characteristicInfo = characteristicInfo; this.bLEExample = bLEExample; }
public void DeviceInfoToRecord(CharacteristicInfo characteristicInfo) { DeviceInfoPage.SetActive(false); RecordPage.SetActive(true); RecordPage.GetComponent <BlueRecord>().Init(characteristicInfo, this); }
public void DiscoveryCharacteristic(CharacteristicInfo characterInfo) { deviceInfo.OnDiscoveryCharacteristic(characterInfo); }
public void DeviceInfoToCharacterInfo(CharacteristicInfo characteristicInfo) { CharacterInfoPage.SetActive(true); DeviceInfoPage.SetActive(false); CharacterInfoPage.GetComponent <CharacterInfo>().Init(characteristicInfo); }
/// <summary> /// 写数据 /// </summary> /// <param name="characteristicInfo"></param> /// <param name="writeEvent"></param> /// <param name="deltaTime">一次只能发送20字节,超20字节会分次发送,deltaTime为分次发送间的间隔,一般是20-40毫秒</param> public void WriteCharacteristic(CharacteristicInfo characteristicInfo, string SendData, Action <bool, string, string> writeEvent, int deltaTime = 30) { WriteCharacteristic(characteristicInfo.bLEDeviceInfo.MacAddress, characteristicInfo.ServiceUUID, characteristicInfo.UUID, SendData, writeEvent, deltaTime); }
public void UnNotifyCharacteristic(CharacteristicInfo characteristicInfo, Action <bool, string> notifyEvent) { UnNotifyCharacteristic(characteristicInfo.bLEDeviceInfo.MacAddress, characteristicInfo.ServiceUUID, characteristicInfo.UUID, notifyEvent); }
public void ReadCharacteristic(CharacteristicInfo characteristicInfo, Action <bool, BLEDeviceInfo, string> ReadEvent) { ReadCharacteristic(characteristicInfo.bLEDeviceInfo.MacAddress, characteristicInfo.ServiceUUID, characteristicInfo.UUID, ReadEvent); }
public void Init(CharacteristicInfo characteristicInfo, string sendMsg) { this.characteristicInfo = characteristicInfo; this.sendMsg = sendMsg; transform.GetComponent <Button>().onClick.AddListener(ReWrite); }