I have Arduino Uno R3 with Wireless Proto Shield and I want to communicate with Windows Phone 8.
I am using the base from the example : http://katastrophos.net/nokia-wiki/www.developer.nokia.com/Community/Wiki/Windows_Phone_8_communicating_with_Arduino_using_Bluetooth.html
This is an asynchronous receiving method:
private async void ReceiveMessages(object sender, DoWorkEventArgs e)
{
try
{
while (true)
{
// Read first byte (length of the subsequent message, 255 or less).
uint sizeFieldCount = await dataReader.LoadAsync(1);
if (sizeFieldCount != 1)
{
// The underlying socket was closed before we were able to read the whole data.
return;
}
// Read the message.
uint messageLength = dataReader.ReadByte();
uint actualMessageLength = await dataReader.LoadAsync(messageLength);
if (messageLength != actualMessageLength)
{
// The underlying socket was closed before we were able to read the whole data.
return;
}
// Read the message and process it.
string message = dataReader.ReadString(actualMessageLength);
MessageReceived(message);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
I have some methods that sends me back info from the Arduino, (SendCarId, SendRideId)
If I try to send each of this commands by itself it will send me back (from the Arduino) the right data.
But when I send the requests one after other it only response to the first and not to the second. (it never get the second time to the method ReceiveMessages )
Anyone have idea what is the problem?