-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CharacteristicValueChanged doesn't work with indicate for Zebra label printer #420
Comments
Hello @markat1 ! var readValueFromDescriptor = await descriptor.ReadValueAsync();
await descriptor.WriteValueAsync(readValueFromDescriptor); if I am correct, it seems like you're reading something from a descriptor, then write it back again? |
Hello @SydneyOwl ! Thank you so much for your reply! I was just experimenting with the descriptor, because I read that "indicate" characteristic require acknowledge by the client. The server does not send indication until it gets the acknowledgement back from the client. If it was just a "notification" characteristic, then I didn't have to do anything other than register a callback function. But how I "acknowledge" my client, I'm not sure how yet. Mobile phones does acknowledge "automatically", but I'm using WPF so I kinda have to do that manually I think. callback function like this right?
I'm not sure if ZD621 sends any data back, but question is: How am I able to receive information back from ZD621, that it has been turned off via Device_GattServerDisconnected? Because this works:
|
Sorry for the late reply! |
No worries @SydneyOwl I'm wondering:
Maybe answers to these questions would lead me to an answer on how/when Characteristic_CharacteristicValueChanged Next question would be:
because if I'm not able to detect wether GATT server is accessible otherwise, then I would have to make a while loop where I repeately call device.Gatt.ConnectAsync until it's connected?
Reason why I do this? because when I turn off Zebra zd621 and then turns it on again I want my program to reconnect to the device automatically |
I'm not entirely sure about the underlying principles, but polling the connection status should be feasible...However, continuously using task.run in a loop can incur significant overhead. You can blockingly call the connection method within the while loop instead. |
no worries @SydneyOwl I have a couple of extra question - I hope you don't mind :) So when I write to my device, I can choose between WriteValueWithResponseAsync and WriteValueWithoutResponseAsync. In the implementation, you can see that both methods doesn't return directly any value other than Task. Question
Why do you want a response?
|
WriteWithResponse doesn't mean you have to do anything on the receiving side as it's handled in the stack. The operation will require a response from the remote Bluetooth device so may take longer but it should pass through any errors rather than being a fire-and-forget approach. You need to check the Properties of the characteristic to see which methods it supports, and only use the supported write type. |
Thank you so much for your reply @peterfoot I have the following 4 properties I can use I was wondering how I can make use of Indicate in order to receive information from the device (here it's zebra zd621). What is critical for me to know is what state device is in, and wether I'm capable of writing to the device. Sometimes what I experience is that suddently I lose connection to the read and write characteristics, and I don't know why. Odd thing is that I can receive the service via _bluetoothDevice!.Gatt.GetPrimaryServiceAsync , but sometimes I can't receive it's characteristics by calling service.GetCharacteristicAsync. Only way I solve it right now is restarting the device and my application - but that's not ideal for me Could I write att commands and get reply back?
|
If the property lists Write that means a WriteWithResponse. The library abstracts the difference between Notify and Indicate properties - you have to add an event handler for the CharacteristicValueChanged event on the Characteristic and call StartNotificationsAsync(). |
@peterfoot
Anyway someone from zebra is suppose to call me this week - hopefully they can tell me if the zebra zd621 is responding back |
library: InTheHand.Net.Bluetooth version 4.1.43.
framework: .net 6 (also possible to use .net 8)
target version: 10.0.22621.0
target os: windows
application: WPF
application framework: prism
I'm trying to receive information from the gatt server via CharacteristicValueChanged, but it doesn't seem to work.
Characteristic is a "indicate", so it need client to "accept" the responses coming from the gattserver before it proceed. Correct me if I'm wrong.
I'm not sure what to do with descriptor here, but maybe this is where I should do my acknowledge?
Rest of the code
The text was updated successfully, but these errors were encountered: