Serial port 
Author Message
 Serial port

Hello everybody!

I have a little problem with serial ports.

I'm writing a program that verifies if a serial port,
(example: Com5), is open or not. I use the function
CreateFile() trying to open the port,  if I can I close
it, but if I get the error: "ERROR_ACCESS_DENIED", (with
GetLastError()), the port is already open and I do some
stuff.
Ok, all this work fine, but I don't want to hear the
"TICK" from the modem  when I call CreateFile() and I open
the port, because I try to open the port with a timer each
2 seconds, and hear that sound, it's not nice.
There is any function that tell me if the port is open or
not?.
This is the code:

 HANDLE hComm;
 char* strPort="Com5";

 hComm = CreateFile( strPort,GENERIC_READ | GENERIC_WRITE,
0, 0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED, 0);

 if (hComm == INVALID_HANDLE_VALUE)    
 {
  if (GetLastError()!= ERROR_ACCESS_DENIED)
     ShowError(GetLastError());  //own function that show
the message error
  else
       {
         //here I make some stuff.
         ...
       }
 }
 else
 {

   //I could open the port, then, I close it.
  CloseHandle(hComm);
 }

A few years ago, I maked the same program with Visual
Basic, with the same basics: try to open the port to see
if it's already open or not; and I never heard the "TICK"
from the modem. I guess that I can do the same with VC++.

Thank you very much, and sorry about my english.  : )

Regards from Argentina.

Demian.



Sat, 07 May 2005 06:01:24 GMT  
 Serial port
Hello everybody!

I have a little problem with serial ports.

I'm writing a program that verifies if a serial port,
(example: Com5), is open or not. I use the function
CreateFile() trying to open the port,  if I can I close
it, but if I get the error: "ERROR_ACCESS_DENIED", (with
GetLastError()), the port is already open and I do some
stuff.
Ok, all this work fine, but I don't want to hear the
"TICK" from the modem  when I call CreateFile() and I open
the port, because I try to open the port with a timer each
2 seconds, and hear that sound, it's not nice.
There is any function that tell me if the port is open or
not?.
This is the code:

 HANDLE hComm;
 char* strPort="Com5";

 hComm = CreateFile( strPort,GENERIC_READ | GENERIC_WRITE,
0, 0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED, 0);

 if (hComm == INVALID_HANDLE_VALUE)    
 {
  if (GetLastError()!= ERROR_ACCESS_DENIED)
     ShowError(GetLastError());  //own function that show
the message error
  else
       {
         //here I make some stuff.
         ...
       }
 }
 else
 {

   //I could open the port, then, I close it.
  CloseHandle(hComm);
 }

A few years ago, I maked the same program with Visual
Basic, with the same basics: try to open the port to see
if it's already open or not; and I never heard the "TICK"
from the modem. I guess that I can do the same with VC++.

Tank you very much, and regards from Argentina.

Demian



Sat, 07 May 2005 19:11:18 GMT  
 Serial port

[...]

Quote:
> A few years ago, I maked the same program with Visual
> Basic, with the same basics: try to open the port to see
> if it's already open or not; and I never heard the "TICK"
> from the modem. I guess that I can do the same with VC++.

So when you run your old VB program on the same machine
with the new VC++ program, VC++ makes TICK where VB doesnt
make TICK ? Would be really a strange effect.

Otherwise you could try out other CreateFile parameters,
try to reconfigure the COM port or modem, or look for
another modem API ..

Markus.



Sun, 08 May 2005 21:36:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Serial port to serial port copying software

2. Challenge: Virtual serial ports from real serial port

3. using PC/104 serial expansion board with WinCE, 4 serial ports total

4. Parallel port/ Serial port

5. I want open the COM1 Port (serial Port)

6. Serial port access

7. Serial port drivers

8. Reading from a Serial Port with C# ???

9. open serial port with C

10. Serial port

11. Serial port hexadecimal address?

12. Serial Port Programming - Receiving Issues

 

 
Powered by phpBB® Forum Software