problem in connection to serial port
-
hi i have written the following code to receive data from mobile using bluetooth through serial communication. but it is not working
#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; }
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.. -
hi i have written the following code to receive data from mobile using bluetooth through serial communication. but it is not working
#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; }
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..First, are you sure the COM4 port exist ? Are you developping for winCE ? If yes, then if I remember well, you have to append a ':' after the port name (thus "COM4:"). Not sure anymore, try it and tell me if it works.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
First, are you sure the COM4 port exist ? Are you developping for winCE ? If yes, then if I remember well, you have to append a ':' after the port name (thus "COM4:"). Not sure anymore, try it and tell me if it works.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++iam not using for windows CE its PC to mobile VC++ 2005 and appending of : has not solved, plz give me some soln..
-
iam not using for windows CE its PC to mobile VC++ 2005 and appending of : has not solved, plz give me some soln..
Does this port exist at least ? Did you try to open it with hyperterminal ?
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Does this port exist at least ? Did you try to open it with hyperterminal ?
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++no i am a begginer and i used AT command to test a while long back but now i dont remember it plz.. which is the command to type in and check for the status... and one thing when i open hyperterminal and select com4 and try to type some thing then my mobile disconnects the bluetooth connection...