deviceplug / btleplug

Rust Cross-Platform Host-Side Bluetooth LE Access Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different behaviors between macOS(arm) and Windows10

Sieyalixnet opened this issue · comments

It can not read anything from the device in Windows10. However, it can be read in MacOS.
Each platform can write data to the device.
Here I have a BLE device and have two characteristics, one is device's TX channel another is RX channel:

Checking characteristic Characteristic { uuid: 0000fff3-0000-1000-8000-00805f9b34fb, service_uuid: ..., properties: READ | NOTIFY, .....} }
//RX

Checking characteristic Characteristic { uuid: 0000fff4-0000-1000-8000-00805f9b34fb, service_uuid: ..., properties: READ | WRITE_WITHOUT_RESPONSE | WRITE, .... }
//TX

For the RX Characteristic I will subscribe it.

            if characteristic.uuid == RX {
                peripheral.subscribe(&characteristic).await?;
                guard.RX = Some(characteristic.clone());
                println!("found RX characteristic and connected");
            } else if characteristic.uuid == TX {
                guard.TX = Some(characteristic.clone());
                println!("found TX characteristic");
            }

And then I write something to the TX channel and read from the RX channel by a loop:

    let mut count = 0;
    loop {
        if count>=20{break;}
        count+=1;
        let __TD = Arc::clone(&_TD);
        sendValue(__TD, "GETALL\r\n").await;//just lock the Arc and use peripheral.write to the TX Characteristic
        let mut guard = _TD.lock().await;
        let mut RX: Characteristic;
        let mut peripheral: _peripheral;
        match guard.RX.clone() {
            Some(r) => {
                RX = r.clone();
            }
            None => {
                return Ok(());
            }
        };
        match guard.peripheral.clone() {
            Some(p) => {
                peripheral = p.clone();
            }
            None => {
                return Ok(());
            }
        };
        let text = peripheral.read(&RX).await?;
        match String::from_utf8(text) {
            Ok(item) => {
                println!("read: {}", item);
            }
            Err(e) => {
                println!("{}",e);

            }
        }
    }

All two platforms are succeed in writing (The device also gives the response so I know that it is succeed in writing.). However, it fails to read in Windows.

In macOS:

send: [71, 69, 84, 65, 76, 76, 13, 10]
read: SOME CONTENTS...
send: [71, 69, 84, 65, 76, 76, 13, 10]
read: 
send: [71, 69, 84, 65, 76, 76, 13, 10]
read: SOME CONTENTS...

In windows:

send: [71, 69, 84, 65, 76, 76, 13, 10]
read: 
send: [71, 69, 84, 65, 76, 76, 13, 10]
read: 
send: [71, 69, 84, 65, 76, 76, 13, 10]
read: 
send: [71, 69, 84, 65, 76, 76, 13, 10]
read: 
send: [71, 69, 84, 65, 76, 76, 13, 10]
read: 
send: [71, 69, 84, 65, 76, 76, 13, 10]
read: 

I tried in two Windows laptops but both them are the same behavior. I don't know it is a bug or the device issues or the platform differences.
Can you give me some help?

ADDITIONAL INFORMATION
macOS: Apple M2, 13.4.1
windows: 5800H, Windows 10 22H2.

I think this is a read request problem of the device. If I use notifications, it will read the same content between Windows and MacOS.