so i am using the bluetooth module that used to be available on this site and a laptop with a usb bluetooth module and a program that sends a continuous stream of data. the fez domino attached uses this code to “see” the data stream
static void uart_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
rx_data = new byte[uart.BytesToRead];
uart.Read(rx_data, 0, rx_data.Length);
s = new String(System.Text.Encoding.UTF8.GetChars(rx_data));
Debug.Print("[" + messageCount.ToString() + "] " + s);
messageCount++;
}
the problem is that i am sending chunks of data from the laptop that look like this:
“128,128” (with the newline \n) added by calling the serialPort.,WriteLine(“128,128”), but instead of getting nice “[12345] 128,128\n” data, it looks more like this:
[142192] 831
[142193] 28
[142194] ,1
[142195] 83
[142196] 1
[142197] 28
[142198] ,1
i am pretty sure that even though i am calling serialPort.WriteLine(“larger string”); the actual radio is breaking up the “larger string” into something like this: “lar” “ger” " st" “ring”. this makes it hard for me because i cant think of an efficient way to attach the strings together without doing something stupid like this:
rx_data = new byte[uart.BytesToRead];
uart.Read(rx_data, 0, rx_data.Length);
s = new String(System.Text.Encoding.UTF8.GetChars(rx_data));
//wrong below, because it eats memory
line = line + s;
if (line.IndexOf("\n") > 0)
{
ParseBTLine(line);
line = "";
}
which actually eats up memory quickly (because i think the adding of strings always creates a larger amount of memory). i would prefer is i could set the “chunk size”, so instead of it looking at “lar” “ger” it would grab "larger string " so that i could see an actual reading each time without having to compile all the chunks. anybody done anything like that?
appreciate any advice