|
Hmm..
To simplify things: does the BT stack offer the COM4 port even if the device wasn't connected ? I mean, regardless of the availability of the device, the port can always be opened ?
But, when a device is not connected, the port does open but no timeouts occur ?
One solution would be to use a custom timer. On the first attempt to communicate with the device, open the port, create a custom timer, and send a predefined command to the device, to which you know a response. This could be something like querying the serial number or software version. If your custom timer expires before a response is received, it is safe to assume that there is no device connected, and handle this as "No device available" -situation in the application.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi !
Thanks for your response.
Ok, here is what happens:
1) if no dongle is connected to the computer, the port can be opened without problem
2) Same thing happens when the dongle is connected but the device is not powered (so still no communication).
In both cases, the WriteFile function hangs !! So I cannot use a timer because this instruction waits that all the data is transmitted and so my program is 'suspended'.
And I also tried to check the DTR line but it is always at 1 even if the dongle is disconnected !!
The only solution I've found for now is that the device need to send always data. When my program starts, I open the port and first check if I receive data (ReadFile doesnt' hang if no device is connected). If yes, the device is connected. If no, no device is connected.
But now I want to change the protocol so that the device send data only when I ask for them (yes, the device is made by us also, so we have access to the code)...
Any solution ??? I'm lost here
|
|
|
|
|
Solution: overlapped I/O.
The last parameter of WriteFile is a pointer to an OVERLAPPED structure that specifies the semantics of an overlapped write operation. This type of an operation is event-driven: when the WriteFile begins, it clears the event flag. When WriteFile finishes, it returns. When the I/O transaction is completed (bytes written), the overlapped flag is raised.
The only necessity is that you open the COM port by using FILE_FLAG_OVERLAPPED specification. Overlapped port access is a tid-bit different from the standard one, but needs to be used in this case. See the OVERLAPPED structure in MSDN for more information.
The basic approach is
1. Create an event object by using CreateEvent
2. Set this event handle into the OVERLAPPED::hEvent member
3. Open the communications port, specifying FILE_FLAG_OVERLAPPED
4. Call WriteFile , specifying the OVERLAPPED structure as the last parameter. WriteFile returns immediately.
5. To determine if the writing was succesfull (if there is a device), call WaitForSingleObject , specifying a suitable time-out. If the event is fired (WaitForSingleObject returns WAIT_OBJECT_0 ), then the writing was succesfull. If return value is WAIT_TIMEOUT , the timeout was reached.
6. Take appropriate action.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi Antti !
Ok, thank you for your response but I just found the solution to my problem. In fact, if the BT and serial ports behave differently, it is because the BT do not send any data when the device is not connected and in a serial communication, the data is sent over the port even if no device is connected. So, I was so stuck by this thing that I didn't watch my timeout values. In fact, the timeout for write operations was set to MAXDWORD that means I wait till the data is sent !! So, I just changed this to another value and now that works fine .
Anyway thank you for your time
|
|
|
|
|
This is not strictly a c++ question. Feel free to flame me
We have an app running at a customer site. They are having intermitent crashes and the stack trace that we dump is always different. I cant reproduce the error in our testing environment and I think this may be beacuse the customer is using a dual CPU machine. I would like them to attempt to reproduce this issue using only one CPU. Is it posible to specify thread affinity on the command line when starting an app so I can force all the apps threads to run on one processor only?
|
|
|
|
|
There is no doubt that problems show up on multi-processor machines that don't on a single cpu. You could add a cmd line option to your app to force it to use a single cpu.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
I had thought of that but I really want to do it without recompiling because this is our customers production environment
|
|
|
|
|
I m using MFC dialog based application.
i want to make it skinable with GIF images
in CP there are Exampls but thay use BMP files
wts the way for GIF to use
thnx
Regards.
|
|
|
|
|
The approach for using GIF as skin images is precisely similar as to using BMPs. The difference is that you must first run the GIF data stream through a decompressor to get actual image data. BMP images are not encoded, they are simply raw image data. Thus they don't need a decompressor.
So, find a tutorial that uses file-based images to skin the dialog. Then implement this procedure, but include a GIF-decompressor routine.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
i search but not find good one.
can u plz tell me any link or help
thanx
Regards.
|
|
|
|
|
Sorry, none that I know of..
You'd first need to learn how to use a bitmap as a skin (lots of examples available at CP). Then, following the same approach, just add a GIF file and the decoding as part of the process.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hello, I'm getting this error:
Run-Time Check Failure #2 - Stack around the variable 'UniqueID' was corrupted.
Here's the function that generates it
<br />
__declspec( dllexport ) BYTE* LaunchMe(BYTE* id)<br />
{<br />
SERIAL *serial=NULL;<br />
BYTE ProductID[BUFFER_LENGHT];<br />
BYTE UniqueID[16];<br />
char *ProductID_Processed=(char*)malloc(BUFFER_LENGHT);<br />
<br />
serial=(SERIAL*)malloc(sizeof(SERIAL));<br />
<br />
memset(serial, 0, sizeof(SERIAL));<br />
memset(&ProductID, 0, BUFFER_LENGHT);<br />
memset(&UniqueID, 0, 24);<br />
<br />
getHardDriveComputerID (serial);<br />
<br />
if ( GetProductID(ProductID, BUFFER_LENGHT) == false) return false;<br />
ProductID_Processed=ProcessProductID(ProductID, BUFFER_LENGHT);<br />
<br />
if (ProductID_Processed == NULL) return false; <br />
CalculateUniqueID(serial->serial, ProductID_Processed,UniqueID);<br />
<br />
memcpy(id, UniqueID, 16);<br />
<br />
return NULL;<br />
<br />
}<br />
Which is the cause of that error? What "around" means?? I get this error some other time also, and google wasn't able to help me, thanks in advance
Paolo
|
|
|
|
|
Don't know whether this is the same as your case, but I once had a similar problem and it turned out the cause is because of stack overflow. Maybe you can check whether you have enough stack space to hold ProductID? What's the value of BUFFER_LENGTH?
|
|
|
|
|
Hi,
The problem is pretty straight forward. You are declaring UniqueId[16] and in
memset you are using 24.
Change it to
memset(UniqueID, 0, 16);
That should solve the problem.
Regards,
Mahadevan
|
|
|
|
|
hi,
i want the source code to the desktop sharing application in vc++.net
can anybody help me.
|
|
|
|
|
I would like to switch IP address for my pc, can someone help?
|
|
|
|
|
On the network ? Programatically ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I have this notebook that is for office and home and of different subnet and DNS. I know that script can do it but I would prefer VC++.
|
|
|
|
|
Let's say my application needs to read some configuration information from a file. I would like that file to be stored in the same folder as the executable. How do I tell the application to look in its own "home" folder for the config file? I expected that that folder would be the default if no path is specified in the file name, but it doesn't always work. (For instance, Visual C++ saves the executable in the "Release" subfolder of my project folder, but if I use the "Execute" command to run it, it looks for the config file in the project folder, not the Release subfolder!
I can't hardcode the full path of the config file, because I want to let the user install the application in a folder of his choice. Help!
|
|
|
|
|
GetModuleFileName()
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi,
We know XP supports hibernating the whole system(when you power it off). I wonder if it is possible by programming to hibernate a specific application without powering the XP off? If so, generally, how to do that? What apis to call?
Any help will be highly appreciated.
Thanks!
duckpond@2004
|
|
|
|
|
|
it is really a very good reference. Thanks a lot
|
|
|
|
|
I have a win32 dll, and I want to use GetModuleFileName in it. But if I go to include stdafx.h or windows.h, I get bizarre compile errors. I have another win32 dll in which theres no problem. This one has a bunch of static ints and I get errors like:
error C2062: type 'int' unexpected
error C2062: type 'int' unexpected
error C2059: syntax error : ')'
error C2062: type 'int' unexpected
error C2062: type 'int' unexpected
etc.
The file has a ton of forward declares like:
static int
acf_llrt( float *hfdata, param_type *prm_type, int *m, int *n,
float *dtemp, int *idat1);
As soon as I remove the #include all is well.
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
|
|
|
|
|
hi folks
i'm interessted to develop (C++ with Visual C++ as IDE) a plugin for the MSN Messenger that will be integrated in the messenger and started with the messenger. does anyone know how to develop a plugin for the MSN messenger?
|
|
|
|