locked
serial port connection beetwen 2 cumputer? RRS feed

  • Question

  • Hi!      sory for my bad english :)
    I have asked before help for this and thx for replies.
    Now I found some  piece of code so I have a program that I want but I can't understanding how exactly working that thing.
    Here are the Codes:

    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <dos.h>
    #define PORT1 0x2F8

    void main () {
        clrscr();  
        int c, ch;   

        outportb(PORT1 + 3, 0X80);                  //NO IDEA
        outportb(PORT1, 0X0C);                       // I think thisone for speed of connection as 9600bps or something like that I m not sure.
        outportb(PORT1 + 1, 0X00);                  //NO IDEA
        outportb(PORT1 + 3, 0X03);                  //NO IDEA
        do {                                         
            c = inport(PORT1 + 5);
            if (c&1)
            {
                ch = inport(PORT1);
                printf("%c", ch);
            }
            if(kbhit())
            {
                c = getch();
                outportb(PORT1, c);
            }
            if (inportb(0X3FD & 3)) {
                printf("Error!");
                getche();
            }
            if (!(inportb(0x3FE) & 20)) {
                printf("Cable unpluged!!!");
                getche();
                break;
                }
        }while(c!=27);
    }

     

    now  here is my problem:  I need a program with these attributes

    57600    bps                  
    0           control for singleness             // can someone explain what is that control ? it is for (dual) for (single) or (no control)
    7           bit data  (which is I ll send to the other computer)
    1           stop bit

    If someone can tell me how to use that 4 definations or anywhere to find any informations about them I ll be realy grateful. thx for replies

    • Moved by Jesse Jiang Monday, October 18, 2010 6:16 AM nothing with c++ (From:Visual C++ General)
    Wednesday, October 13, 2010 1:57 PM

All replies

  • That looks like old DOS era code.  Windows doesn't allow you direct access to the hardware.  Under Windows, to open a serial port, you would call CreateFile and use the file read/write APIs to send and receive data.

    Here is a tutorial on using the serial port.  Here is a class that can simply do all the heavy lifting for you.

    Wednesday, October 13, 2010 2:13 PM