Click to See Complete Forum and Search --> : Port and RS232, please help


funniest
April 7th, 2002, 05:59 PM
I'm trying to import an old program to VC++, this program has some functions to deal with RS232 and ports. The program has a function called init8250, and this is a piece of code from it:

chan = 0;
unsigned far *prs232_base = ( unsigned far * )0x400000L;
register unsigned port;
port50[ chan ] = port = *( prs232_base + chan );
...
outpfunc( port + MCR50, 0 ); /* MCR50 = 5*/

When I run it, I got the "Exception Privileged.." error, which I know it's about the access permision for com port on Win2K.. So, I'm using an additional tool to permit the port access, and I still got that error.
When I display the "port" variable above, it is: 9460301 (I think this number is too big and it generates the error).
So, can someone please tell me why this old piece of code is like that and what should I change it to work for the new compilers like VC++.
Thanks in advance.

ltachna
April 8th, 2002, 05:43 AM
you are looking at a c program written for DOS that is accessing memory directly via a pointer you cant do that in windows. you will need to totally rewrite new code if you want to use the serial port with windows there are some good example on codeguru

funniest
April 8th, 2002, 11:02 AM
That piece of code is in a function "init_8250". What should I change it to work with new compiler? looks like 400000L generates a large value and causes error. I've seen some other sample set the port like 3F8 to init the 8250. Should I use that value instead?
Thanks

ltachna
April 8th, 2002, 08:45 PM
i am not sure how much plainer i can put this that code will not run under windows. the 400000L is a memory address the line it is in is an assigment of that memory address to a pointer for reading and or writing. 3f8 is a port address under windows you can not directly write to a port or memory address like you can in DOS. to use the serial port in windows you treat it like a file and use the CreateFile API. in othher words the changes you will need to make begin with discarding the code you have and starting from scratch or using one of the excellent comm port examples here on code guru. sorry if this sounds harsh but its the way it is