hi i have written the following code to receive data from mobile using bluetooth through serial communication.
but it is not working
<code>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include "stdafx.h"
#include "bluetoothConnection.h"
bool BluetoothConnection::openPort(char *portNum)
{
if (portNum != NULL)
{
hcomm = CreateFile((LPCWSTR)portNum, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, NULL, 0);
if (hcomm == INVALID_HANDLE_VALUE)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
bool BluetoothConnection::initPort()
{
dcb.fOutxCtsFlow = false;
dcb.fOutxDsrFlow = false;
dcb.fDtrControl = DTR_CONTROL_DISABLE;
dcb.fOutX = false;
dcb.fInX = false;
dcb.fRtsControl = RTS_CONTROL_DISABLE;
//time settings
timeouts.ReadIntervalTimeout = 20;
timeouts.ReadTotalTimeoutMultiplier = 10;
timeouts.ReadTotalTimeoutConstant = 100;
if (!SetCommTimeouts(hcomm, &timeouts))
{
return false;
}
else
{
return true;
}
}
void BluetoothConnection::ReadPort()
{
memset(chRead, '\x91', 250);
Sleep(1000L);
ReadFile(hcomm, chRead, 250, &dwRead, NULL);
}
void BluetoothConnection::display()
{
printf("%s\n", chRead);
}
int main()
{
BluetoothConnection *bth1 = new BluetoothConnection();
if (bth1 != NULL)
{
if (bth1->openPort("COM4"))
{
if (bth1->initPort())
{
bth1->ReadPort();
printf("the data from com4 is ....\n");
bth1->display();
}
else
{
printf("fail in init\n");
}
}
else
{
printf("unable to connect\n");
}
}
else
{
printf("unable to connect failed in initial state\n");
}
Sleep(1000L);
return 0;
}
</code>
its failing in CreateFile function coz its returns 0xffffff..
can this code be used for bluetooth coz i found such code for serial port comm and infrared.
is there any configurations between mobile and pc before running this application if there please provide me the steps..