I am trying to send message to my arduino through bluetooth
audrino seems to be working bluetooth because i test it with Blueterm android app and it successfully communicate with it
but my c# code was unable to connect to arduino
my simple code is
/////////////////////////////////////////////
BluetoothAddress addr = BluetoothAddress.Parse("20:13:04:27:43:06");
Guid serviceClass;
serviceClass = BluetoothService.SerialPort;
// - or - etc
// serviceClass = MyConsts.MyServiceUuid
//
var ep = new BluetoothEndPoint(addr, serviceClass,12);
var cli = new BluetoothClient();
cli.Connect(ep);
Stream peerStream = cli.GetStream();
while (true)
{
byte[] buf = new byte[1000];
int readLen = peerStream.Read(buf, 0, buf.Length);
if (readLen == 0)
{
Console.WriteLine("Connection is closed");
}
else
{
Console.WriteLine(Encoding.ASCII.GetString(buf));
}
}
}
private void BluetoothClientConnectCallback(IAsyncResult result)
{
BluetoothClient client = (BluetoothClient)result.AsyncState;
client.EndConnect(result);
Stream stream = client.GetStream();
while(true)
{
byte[] receive = new byte[1024];
stream.Read(receive, 0, receive.Length);
Console.WriteLine(Encoding.ASCII.GetString(receive));
}
}
//////////////////////////////////////////////////////////////
what seems to be the problem
please help me