Help Serial Port

Discussion in 'Programmer's Corner' started by Xeeshan Qureshi, May 4, 2009.

  1. Xeeshan Qureshi

    Thread Starter Member

    Jan 13, 2009
    14
    0
    Hi!
    I want to transmit and receive data on serial port (currently i'm working on a single PC with its Tx and Rx pins short). I'm using following program (in Turbo C), but to no use. Can anyone help me out with this code?


    #include <bios.h>
    #include<stdio.h>
    #include<iostream.h>
    #include <conio.h>
    #define COM1 0
    #define DATA_READY 0x100
    #define SETTINGS ( 0xE0 | 0x08 | 0x00 | 0x03) //(baud_9600 | ODD_PARITY | COM_STOP1 | COM_CHR8)
    int main(void)
    {
    clrscr();
    int out, status;
    char in,x;
    bioscom(0, SETTINGS, COM1); /*initialize the port*/
    cprintf("Data sent to you: ");
    while (1)

    {

    status = bioscom(3, 0, COM1); /*wait until get a data*/
    if (status & DATA_READY)
    if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) /*input a data*/
    {
    cout<<"the data received is "<<out<<endl;
    putch(out);
    }
    if (in=getch())
    { cout<<"key was pressed"<<in<<endl;
    if (in == 27) /* ASCII of Esc*/
    {
    break;
    }
    else
    {cout<<"we are aobut to transmit"<<endl<<in<<endl;
    bioscom(1, in , COM1); /*output a data*/}
    }


    }
    return 0;
    }


    Thanx
     
  2. Xeeshan Qureshi

    Thread Starter Member

    Jan 13, 2009
    14
    0
    Please help me
     
  3. davebee

    Well-Known Member

    Oct 22, 2008
    539
    46
    Most PCs that I've used have had hardware handshaking set on by default.

    I guess you've connected the RX pin 2 to the TX pin 3 on the 9-pin serial port, is that right?

    Try also connecting pin 4 DTR to pin 6 DSR to enable the handshaking.
     
  4. Xeeshan Qureshi

    Thread Starter Member

    Jan 13, 2009
    14
    0
    I've tried by shorting Pin 6 and 4 as well, but it didn't work.
    I wonder if the code is correct. Please give it a look.
     
  5. davebee

    Well-Known Member

    Oct 22, 2008
    539
    46
    I've never personally used bioscom to talk to the ports but this looks right, as compared to another example of code I found that does use bioscom.

    Are you sure you're connecting to COM1? Some computers have several serial ports;
    maybe your loopback is plugged into COM2.

    When you first call bioscom to connect to the port, does it return a status telling you whether it succeeded or failed? It might be good to get and print a return status; maybe the initial open is failing.

    Another thing you could do is try a terminal program like HyperTerminal or TeraTerm to do the same thing - that might help verify which COM your connector is mapped to, and can help test your loopback plug.
     
Loading...