|
-
August 18th, 2005, 08:06 AM
#1
Serial comm over BT serial port does not work?
Hi,
I am just trying to monitor the Bt serial port for any activity.
Later I want to read and write data over it.
This code does the same,but nothing happens,it just keeps on waiting
for event to take place.I am sending a file using the BT dongle and
expect this code to work when the file transfer happens.
Can somebody pls point out what am I doing wrong.
Thanks in advance.
--eminemence.
:
Code:
#define BT_PORT_NUM "COM3"
HANDLE hCommHandle;
OVERLAPPED ovp;
DWORD dWtEvent;
DWORD WINAPI CommReadThread (LPVOID lpvoid);
void show_menu()
{
printf("\n\t\t1. Start Discovery");
printf("\n\t\t2. Exit.");
printf("\n\t\tSelect choice : ");
}
int OpenPort(char* portNum)
{
if(portNum!=NULL){
hCommHandle = CreateFile(portNum,
GENERIC_READ| GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
NULL,
0);
if(hCommHandle == INVALID_HANDLE_VALUE){
printf("\n\t\tError : Error opening port...");
return false;
}
else{
printf("\n\t\tOpening port...success..");
return true;
}
}
else
printf("\n\t\tError : Invalid port number...");
return false;
}
void WriteToPort()
{
}
void StartBtDiscovery()
{
if(OpenPort(BT_PORT_NUM)){
DCB dcb;
if (!GetCommState (hCommHandle, &dcb)){
printf("\n\t\tError1 : GetCommState error.");
return;
}
dcb.BaudRate = CBR_9600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit
if (!SetCommState (hCommHandle, &dcb)){
printf("\n\t\tError1 : SetCommState error.");
return;
}
COMMTIMEOUTS timeOuts;
timeOuts.ReadIntervalTimeout = 0;
timeOuts.ReadTotalTimeoutConstant = 0;
timeOuts.ReadTotalTimeoutMultiplier = 0;
timeOuts.WriteTotalTimeoutConstant = 0;
timeOuts.WriteTotalTimeoutMultiplier = 0;
if(!SetCommTimeouts(hCommHandle,&timeOuts)){
printf("\n\t\tError : Comm port init error.");
return;
}
else{
printf("\n\t\tSuccess setting comm timeout...");
if(SetCommMask(hCommHandle, EV_CTS | EV_DSR)){
//comm mask setting success..
ovp.hEvent = CreateEvent(
NULL, // no security attributes
FALSE, // auto reset event
FALSE, // not signaled
NULL // no name
);
printf("\n\t\tWaiting for some event..");
while(WaitCommEvent(hCommHandle, &dWtEvent, &ovp))
{
printf("\n\t\tSome event on port....");
if (dWtEvent & EV_DSR){
printf("\n\t\tDSR event flagged...");
}
if (dWtEvent & EV_CTS){
printf("\n\t\tCTS event flagged...");
}
}
}
else{
printf("\n\t\tError : Comm port mask init error.");
return;
}
}
}
printf("\n\t\tError : Error in opening port..");
return;
}
int main(int argc, char* argv[])
{
char ch;
while(1){
show_menu();
ch = getchar();
switch(ch){
case '1':
StartBtDiscovery();
break;
case '2':
exit(0);
break;
}
}
return 0;
}
-
August 19th, 2005, 02:21 AM
#2
Re: Serial comm over BT serial port does not work?
From what I see, your are just opening the port. If you want to read and write to it, I think u need to use ReadFile and WriteFile method.
-
August 19th, 2005, 10:14 AM
#3
Re: Serial comm over BT serial port does not work?
What's a "Bt serial port?"
Viggy
-
August 19th, 2005, 11:00 AM
#4
Re: Serial comm over BT serial port does not work?
Forget that, I just found out that by "BT" you mean BlueTooth!
Sorry!!!
Viggy
-
August 19th, 2005, 02:48 PM
#5
Re: Serial comm over BT serial port does not work?
what kind of BT device aer you using?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|