Skip to content
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

Problem to Send data to BLE device with Write function #2

Open
jym92 opened this issue Jan 15, 2020 · 1 comment
Open

Problem to Send data to BLE device with Write function #2

jym92 opened this issue Jan 15, 2020 · 1 comment

Comments

@jym92
Copy link

jym92 commented Jan 15, 2020

hi ,

Thanks for your api !

It's work fine to recept data from a BLE device !

But Now I need to send a character to my BLE device to control it (I use HM-10).

to do this, I write this specific code :

`
// On click :
void Disconnect_Clicked(object sender, System.EventArgs e)
{
Console.WriteLine("Disconnect");

        ReadCharacteristics();
        Task.Delay(200);
        Ble_sendMessage("S");
        Task.Delay(200);
    }

void ReadCharacteristics()
{
BLEconnect.ConnectDevice.CharacteristicsDiscovered(cha =>
{
Device.BeginInvokeOnMainThread(() => {
AllCharacteristics.Add(cha);
CharacteristicsList.Add(new CharacteristicsList(cha.Uuid, cha.CanRead(), cha.CanWrite(), cha.CanNotify()));
});
});
}

void Ble_sendMessage(String str)
{
foreach (var c in AllCharacteristics)
{
Console.WriteLine("Characteristic test :" + c.Uuid);
// search my specific charac :
if (c.Uuid == "0000ffe1-0000-1000-8000-00805f9b34fb")
{
//var bytes = StringToByteArray(str);
var bytes = Encoding.ASCII.GetBytesstr);
if (bytes != null) c.Write(bytes);
else Console.WriteLine("message empty !");
Console.WriteLine("message send !");

            }
        }
    }

`

But when I try this code, I have an fatal error on "c.Write(bytes);", bytes is not empty but he don't find reference ...

Do you have an idea to solve this issue ?

Thanks !

@ghost ghost mentioned this issue Sep 1, 2020
@jojan5
Copy link

jojan5 commented Sep 28, 2020

did you solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants