Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problems with ReadFile in Win 98

Posted on 2003-03-07
6
Medium Priority
?
278 Views
Last Modified: 2008-03-06
Hi,
The project i'm working on is to do some serial communication for GPS receivers. I have written and executed a program using Win NT, which creates a handle to a com port and reads the data from a GPS and outputs 1: to the screen and 2: to a file. This works fine!( in NT) I have now taken said .exe and run it on Win 98 and Win 95 in both these operating systems the program hangs. When I run debug on the 98 system the program stops at the ReadFile command. This is the code:

void read_port(void* sPort, void* cfile)
{
unsigned long read_nbr;
char buffer;
read_nbr=0;
int i=1;    
do
{
     ReadFile(sPort, &buffer,1, &read_nbr,NULL);
          cout << buffer;
          write_file(buffer, cfile);      
          }while (i==1);
}

I am stuck, I need the program to run on 95 and 98 most of all, if you guys can help i would be most greatfull.

BTW it was from postings on this site that i managed to write the prog in the first place, so thanks.

0
Comment
Question by:Yrag
  • 3
5 Comments
 
LVL 12

Expert Comment

by:Salte
ID: 8087647
what filename do you give when you open that file?

Also, I don't think using 'void *' is the accepted way to refer to a handle in Win32 (even if HANDLE itself is typedef'd to it).

You should declare your function:

void read_port(HANDLE sPort, HANDLE cfile)
{
   ...
}

Not sure about cfile but I suspect that is a handle as well and so it should also be a HANDLE type. sPort is definitely of type HANDLE.

This is the Win32 type defined in the Win32 interface and that is what you should use. Microsoft may at any time of their choosing change HANDLE to be a different type and your program would break.

Alf
0
 

Author Comment

by:Yrag
ID: 8088762
Thank you Salte for pointing that out to me. I am quite new to this. Visual C++ showed errors when i did not define the file handles and it said the were constant pointers so thats how i defined then.
All that aside i changed the variable definitions to read HANDLE and it did not fix the prob the program still hangs when run on another non NT PC (ie 98).


i am trying to communicate with a serial port so the name given to the file is COM1.
0
 
LVL 12

Accepted Solution

by:
Salte earned 200 total points
ID: 8089646
ah, that explains it!

Don't use "COM1" as filename to communicate with the serial port. The filename is some other name, I can't recall the name right now but I am very sure that it starts with a special sequence of some sort...

"\\\\Device\\SerialPort\\... " or some such, as I said it is years since I worked on that kind of stuff so I can't recall the name but if you do a little search around you should find the name fast. I knwo that "COM1" isn't the right name so that should explain the hang.


Hmm..Win98 you say? I did believe that "COM1" was possible to use under Win98 though. In any case, you can use the same filename as Win2000/XP uses and is guaranteed to work.

The Win32 filename for serial port communication is not "COM1". "COM1" is a left over from old DOS and is kept in WIN95 and I thought also Win98 to be compatible with DOS.

Alf
0
 
LVL 12

Expert Comment

by:Salte
ID: 8089745
Sorry about the misinformation, I just did some research and found the following:

The name "COM1" can be used.

However, once you opened the file you cannot just start to receive or send data on it. You must first set up the communication, set up which speed etc etc etc.

Please read:

http://www.wince.org.uk/vc/intermediate/serialrw.htm

for details.

Sorry about that, The name \\devicve\.... is used to communicate with a driver and can probably be used also but it is possible that Win32 hides that name. As you possibly know Win32 operates with names that are compatible to old DOS while the underlying operating system Win2000/XP/98 etc may or may not have the same names for things. In particular Win2000 and WinXP uses different names for drivers etc compared to Win32. This is normally hidden for programmers since they can use the Win32 name which is common for all platforms but you see it when the machine boots and you see it if you write a driver and you CAN also see from Win32 if you give the non-win32 name. Win32 will then notice that this is not a Win32 name and pass it on to the underlying system - at least in some cases.

Alf
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9892875
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to Salte: Grade A

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (http://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question