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 "bluetoothConne ction.h"
bool BluetoothConnec tion::openPort( char *portNum)
{
if (portNum != NULL)
{
hcomm = CreateFile((LPC WSTR)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 BluetoothConnec tion::initPort( )
{
dcb.fOutxCtsFlo w = false;
dcb.fOutxDsrFlo w = false;
dcb.fDtrControl = DTR_CONTROL_DIS ABLE;
dcb.fOutX = false;
dcb.fInX = false;
dcb.fRtsControl = RTS_CONTROL_DIS ABLE;
//time settings
timeouts.ReadIn tervalTimeout = 20;
timeouts.ReadTo talTimeoutMulti plier = 10;
timeouts.ReadTo talTimeoutConst ant = 100;
if (!SetCommTimeou ts(hcomm, &timeout s))
{
return false;
}
else
{
return true;
}
}
void BluetoothConnec tion::ReadPort( )
{
memset(chRead, '\x91', 250);
Sleep(1000L);
ReadFile(hcomm, chRead, 250, &dwRead, NULL);
}
void BluetoothConnec tion::display()
{
printf("%s\n", chRead);
}
int main()
{
BluetoothConnec tion *bth1 = new BluetoothConnec tion();
if (bth1 != NULL)
{
if (bth1->openPort("C OM4"))
{
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..
1 2103
hcomm = CreateFile((LPC WSTR)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 MultiByteToWide Char. That will give you a WSTR string. Now you can cast the WSTR string to an LPCWSTR and off you go.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 Base Class Library for
Serial Device Communication" but I'm new with VC# and need some basic rules
because I have a lot of compilation errors.
Where should I create my inherited class?
Thank you
|
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 functions frequently in my
C++ code. I came to know how to import the windows functions into
Visual C#.NET. But what is the method to import windows structure into
Visual C#.NET?
It will be very helpful for me if anybody can give me the WebID that...
|
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 while, the serial port seems corrupted because when
my data is sent, it doesn't go through the serial port, so as same to
receive process. In order to fix this, I have to close the port and reopen
the port again.
Why?!! Is there any way to fix...
|
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. What I would like to do is make
the serial port accessible via a web service.
The web service and the legacy application would be running on the same
machine. The mobile application would access the web service via a network
connection. It...
|
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 understand device and
serial communication work wihout problems.
Now I want to do the same with C# code. As simple as that.
I open the serial port with the configuration manufacturer gives me,
| |
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 C# for Pocket PC
now using a System.IO.Ports.SerialPort object with the same
communication parameters as the former: 19200,n,8,1 and on COM4.
The problem is that the latter app generates an IO exception
System.IO.FileNotFoundException cause...
|
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 framework to read and write on serial
port.
I would like to make asynchronous reception. I saw that we can pass a
delegate to the serial class which is call when some data is readen on
the port.
|
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 of the client machine starts to work.
Now I wrote the code which is in charge of serial communication in the
..aspx.cx pages, but then I found that when uses click the button, it is the
server's serial port that starts to work,not the clients!!
...
|
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
configured the bluetooth connection for serial communication (i.e from system stray selecting bluetooth icon and from quick connect selecting serial connection). instead it shows that connection is succesfull for PIM transfer, so do i need to write a...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |