Search code examples
androidc++c++builderrad-studio

Problems transferring data from Android Phone to Serial Device using Bluetooth component


sorry if my Title is not particularly precise.

I am trying to transfer byte Data from an Android Phone to a Serial Device. As you can see below, the data I want to send is a Byte Array with Hex values. if I send them the way I do right now, RealTerm the Serial port monitor display different Values than the ones I Sent (F0 F0 FC F3).

void __fastcall Blue::send(Byte * data, int len)
{
    TBytes DataToSend;
    DataToSend.set_length(1);

    for(int i = 0; i < len; i++)
    {
        DataToSend= ToBytes(data[i]);
        if(!btSocket->Connected)
            btSocket->Connect();
        btSocket->SendData(toSend);
    }
}

int Bluetooth::sendMessage(void *data, unsigned short len)
{
    Byte bff[4] = {'\AA', '\x55', '\xA5', '\x5A'};
    unsigned short crc;

    crc = util->calcCRC((unsigned long)data, len / 2);

    send(bff, 4);
    send((Byte *)data, len);
    return 0;
}

That is how I get the Connection

TBluetoothSocket* Bluetooth::getBtSocket()
{
    if(btSocket == NULL)
    {
        TBluetoothDevice * lDevice = fPairedDevices->Items[Form1->ComboBoxPairedDevices->ItemIndex];
        btSocket = lDevice->CreateClientSocket(StringToGUID(ServiceGUI), false);
    }
    return btSocket;
}

so the first thing I do is to send the bff as a start sequence and then I want to send the rest of the data using the serial communication. btSocket is just a TBluetoothSocket.

Well as stupid as it might sound, it was actually the Baud Rate.


Solution

  • Set correct baud rate on your RealTerm ;)