Samsung / TizenFX

C# Device APIs for Tizen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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?

/cc @wootak, @dh79pyun Please take a look this issue.

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);

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