473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

problem in serial communication between pc and mobile

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, &amp;timeouts))
{
return false;
}
else
{
return true;
}
}

void BluetoothConnection::ReadPort()
{
memset(chRead, '\x91', 250);
Sleep(1000L);
ReadFile(hcomm, chRead, 250, &amp;dwRead, NULL);
}

void BluetoothConnection::display()
{
printf("%s\n", chRead);
}
int main()
{
BluetoothConnection *bth1 = new BluetoothConnection();
if (bth1 != NULL)
{
if (bth1-&gt;openPort("COM4"))
{
if (bth1-&gt;initPort())
{
bth1-&gt;ReadPort();
printf("the data from com4 is ....\n");
bth1-&gt;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..
Sep 4 '08 #1
1 2083
weaknessforcats
9,208 Expert Mod 8TB
hcomm = CreateFile((LPCWSTR)portNum, GENERIC_READ | GENERIC_WRITE, 0, 0,
portNum is a char*. Typecasting the address as a LPCWSTR does not make it a Unicode string.

You should be using the TCHAR mappings in tchar.h (Google MSDN for this).

If you don't want to do this, then you have to create a Unicode string from your char* string using MultiByteToWideChar. That will give you a WSTR string. Now you can cast the WSTR string to an LPCWSTR and off you go.
Sep 4 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: carmen | last post by:
I'm working in an aplication for a Smart Device that need to "talk" with a printer continuosly through the serial port. I'm trying to use the John Hint's sample code "Use P/Invoke to develop a .NET...
4
by: Vidya Bhagwath | last post by:
Hello Experts, I am porting the C++ code into the Visual C#.NET. My C++ code is mainly based on the serial communication. So I am using the windows structure such as DCB.. etc and the windows...
7
by: Michael Chong | last post by:
I wrote a program that communicate with SerialComm. In every 300 milliseconds, my program continuously send & receive data via the serial port once the program starts. My program is once in a...
4
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. ...
4
by: Lonifasiko | last post by:
Hi, I've been able to communicate using HyperTerminal with my device via serial port COM1. I just send a command and device switches on. I just need that to start playing with it. This way, I...
2
by: Mihai Popescu | last post by:
I wrote a simple application in MFC that uses MSComm ActiveX Control for serial communication. This app works just fine but I have to port it to Pocket PC. So, I wrote another simple application in...
4
by: max_mont | last post by:
Hi all, I'm a newbie in .NET technology. I've already developed Serial communication applications in C++ (WIN32). And I wanted to migrate to .NET technology. There is a serial component in...
2
by: Adrian Chen | last post by:
please help me! I come across a problem. Now I develop a finger print management system which is based on B/S.When users click a button in the web pages, a device connected to the COM1 serial port...
0
by: lakshmiRam | last post by:
hi i have a code which was supposed to read data from serial com (bluetooth) and save in a file. but when i send a audio file from my mobile to pc the program will not read the port i have ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.