CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Posts
    30

    Port and RS232, please help

    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.



  2. #2
    Join Date
    Feb 2000
    Location
    Greensboro NC
    Posts
    123

    Re: Port and RS232, please help

    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


  3. #3
    Join Date
    Jul 2001
    Posts
    30

    Re: Port and RS232, please help

    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


  4. #4
    Join Date
    Feb 2000
    Location
    Greensboro NC
    Posts
    123

    Re: Port and RS232, please help

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured