Expose byte transmission on Tizen.Network.Bluetooth.IBluetoothClientSocket.SendData(string)
tomh4 opened this issue · comments
The Tizen.Network.Bluetooth.IBluetoothClientSocket.SendData(string) interface is limited to string transmissions, however a much more common scenario is to send byte arrays, and you probably encode the passed string to a byte array in the background anyway, so could you expose e.g. SendData(byte[] data) or provide any alternative getting byte arrays transmitted?
I will check and discuss to provide a new interface for byte[].
One question, why you need byte arrays transmitted? SendData(string) returns the number of bytes to be sent.
We are implementing a communication with our embedded microcontroller an it is expecting a byte array as protocol
Ok. Please use string encoded from byte in current version temporarily.
string str = Encoding.Default.GetString(byte);
To send binary through string format, need to use base64 encoding
string s = Convert.ToBase64String(bytes);
byte[] newBytes = Convert.FromBase64String(s);
https://docs.microsoft.com/ko-kr/dotnet/api/system.convert.tobase64string?view=netframework-4.8#System_Convert_ToBase64String_System_Byte___
https://docs.microsoft.com/ko-kr/dotnet/api/system.convert.frombase64string?view=netframework-4.8
As far as I remember I have tried this before without success, but I will retry and let you know!
Any specific reason you are only exposing the string argument?
New API now on review.
#1390
Great, Tizen 7 though, is there any wearable available with that API Level?
Ok, so based on @wootak 's great PR, I was able to extract the native API call myself, to make the byte transmission available for lower Tizen APIs. This is tested on a Galaxy Watch with Tizen 4:
Create a new class
public static class BluetoothInterop
{
internal static partial class Libraries
{
public const string Bluetooth = "libcapi-network-bluetooth.so.0";
public const string Glib = "libglib-2.0.so.0";
public const string Libc = "libc.so.6";
}
[DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_send_data")]
internal static extern int SendData(int socketFd, byte[] data, int dataLength);
}
Then, simply use it like this :
BluetoothInterop.SendData(SocketID, writeBytes, writeBytes.Length);
Where SocketID is the socketFd received when connecting to the device an writeBytes are you bytes