RS232 Code

Greetings
I've been given the task of converting an antique QBasic program to C++(normal code) MSVC++ to be specific. The 3 lines that are giving me the most trouble are below the first one I've figured out and is working:
OPEN "com2:600,n,8,1,cd0,cs0,ds0,op0" FOR INPUT AS #3: CLOSE 3

That took awhile, the next two have me completely baffled;
OUT &H288, 3
OUT &H288, 1

How can I do that in C++, I'm not seeing any way of doing this on a single thread & that's what I gota use.

Theres also this one:
INP(&H298)
It's writing to & reading from a com port thats connected to device 'x', I just can't find a C function that'll do that the way QBasic does. I'm also not that good with hardware code...

I've been at this 13 hrs straight, any help would be appreciated.

Thank You
Stoic Joker

Comments

  • : Greetings
    : I've been given the task of converting an antique QBasic program to C++(normal code) MSVC++ to be specific. The 3 lines that are giving me the most trouble are below the first one I've figured out and is working:
    : OPEN "com2:600,n,8,1,cd0,cs0,ds0,op0" FOR INPUT AS #3: CLOSE 3
    :
    : That took awhile, the next two have me completely baffled;
    : OUT &H288, 3
    : OUT &H288, 1
    :
    : How can I do that in C++, I'm not seeing any way of doing this on a single thread & that's what I gota use.
    :
    : Theres also this one:
    : INP(&H298)
    : It's writing to & reading from a com port thats connected to device 'x', I just can't find a C function that'll do that the way QBasic does. I'm also not that good with hardware code...
    :
    : I've been at this 13 hrs straight, any help would be appreciated.
    :
    : Thank You
    : Stoic Joker
    :
    The first one means:
    __asm {
    mov dx,648
    mov al,3
    out dx,al
    mov al,1
    out dx,al
    }
    And the other is:
    __asm {
    mov dx,664
    in al,dx
    }
    This will not work under Windows NT.
    On Windows NT, hardware is accessed through device drivers only.
  • : : Greetings
    : : I've been given the task of converting an antique QBasic program to C++(normal code) MSVC++ to be specific. The 3 lines that are giving me the most trouble are below the first one I've figured out and is working:
    : : OPEN "com2:600,n,8,1,cd0,cs0,ds0,op0" FOR INPUT AS #3: CLOSE 3
    : :
    : : That took awhile, the next two have me completely baffled;
    : : OUT &H288, 3
    : : OUT &H288, 1
    : :
    : : How can I do that in C++, I'm not seeing any way of doing this on a single thread & that's what I gota use.
    : :
    : : Theres also this one:
    : : INP(&H298)
    : : It's writing to & reading from a com port thats connected to device 'x', I just can't find a C function that'll do that the way QBasic does. I'm also not that good with hardware code...
    : :
    : : I've been at this 13 hrs straight, any help would be appreciated.
    : :
    : : Thank You
    : : Stoic Joker
    : :
    : The first one means:
    : __asm {
    : mov dx,648
    : mov al,3
    : out dx,al
    : mov al,1
    : out dx,al
    : }
    : And the other is:
    : __asm {
    : mov dx,664
    : in al,dx
    : }
    : This will not work under Windows NT.
    : On Windows NT, hardware is accessed through device drivers only.
    :

    Greetings
    And thank you for the reply, I'm not sure which OS the Program is supposed to run on, but I'm working on that code in WinXP.

    I ended up using CreateFile("COM2",...) and then using SetCommState(...) to configure the port. For the I/O I'm trying WriteFile(...) & ReadFile(...) & giving them a handle to the port, it seemed to work but I've no way to test it.

    Does that sound like I'm on the right track??? I can't read(understand) ASM, can you give me a C version of you answer, ...or is there one?

    Thank You
    Stoic Joker
  • Just FYI:

    OUT is outport() in C,
    IN is inport() C.

    If you are R/W bytes then use outportb()/inportb().
    Check your compiler manual.

    Now, if you in WindowsXP - use Comm API, of course, because
    the functions above are for DOS. They wotk in Windows too, but
    for serial communication - use the API:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win32/catfunc_26m1.asp

    Click on 'Communication' link...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories