Yrag
asked on
Problems with ReadFile in Win 98
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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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 (https://www.experts-exchange.com/help.jsp#hi73).
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
-bcl (bcladd)
EE Cleanup Volunteer
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 (https://www.experts-exchange.com/help.jsp#hi73).
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
-bcl (bcladd)
EE Cleanup Volunteer
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