Thread: Serial port reading data

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    8

    Serial port reading data

    Hello,

    I'm trying to read a single byte from a com port using _bios_serialcom function. I'm using windows vista and borland C++ 5.02 compiler. Here is my code:

    Code:
    /* PC-to-AVR communication – by sakis papamichalis */
    /* An application for PC which receives a single byte from a mikrocontroller */ 
    
    #include <stdio.h>
    #include <conio.h>
    #include <bios.h>
    #define SETTINGS (_COM_9600 | _COM_CHR8 | _COM_NOPARITY | _COM_STOP1)
    /* baud rate = 9600, 8 data bits, no parity bit, 1 stop bit */
    
    void main(void)
    {
    unsigned in,out,status;
    int port;
    
    printf("Select Port (Enter 0 for COM1 and 1 for COM2):");
    scanf("%d",&port);
    
    //_bios_serialcom(_COM_INIT,port,SETTINGS);
    
    out=_bios_serialcom(_COM_RECEIVE,port,0);
    printf("\nData Received:");
    
    for(;;)
    {
    
    }
    
    }
    A microcontroller send the byte to com port of PC but the result is nothing.(I have checked that microcontroller sends the byte right with hyper terminal). I need to use it in a larger program which will read data from com port and then shows them to the monitor. So, you think that is something wrong in my code?
    I have seen that _bios_serialcom works only in DOS OS. Is there any other way to read data from com port in borland?
    I'm a little bit confused with comuter programming because i'm familiar with C programming for microcontrollers.

    Thanks for any help

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I've never worked with "bios.h" before, but I have used code I found on a thread from this site a while back.

    I believe it was here: Communication using RS232 port
    See post #11

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yes, get a real compiler for your real OS (not some ancient fossil running in an emulation layer).
    Visual Studio Express 2012 Products | Microsoft Visual Studio
    smorgasbordet - Pelles C
    Code::Blocks
    Orwell Dev-C++ | Free Development software downloads at SourceForge.net

    Then read up on how to do serial port programming using the win32 API (which is what the working hyperterminal will be using).
    win32 serial port - Google Search
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    8
    Thanks for your help,

    I have already downloaded DEV C++ from sourceforge. Besides, i would like to ask that if i implement a C code for win32 OS (vista), could operate in any other OS like windows xp and windows 7?.
    I start to work with the new compiler.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Besides, i would like to ask that if i implement a C code for win32 OS (vista), could operate in any other OS like windows xp and windows 7?.
    Take a function like CreateFile (as used in the other thread).

    Read the manual page
    CreateFile function (Windows)

    Scroll down to the end, where it says "Minimum supported client: Windows XP"

    So long as you only use functions that were introduced in XP, then you'll be OK.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    8
    I installed DEV-C++ in another PC (windows xp) and tried to write a simple code for a test:

    #include <stdio.h>

    void main(void)
    {

  7. #7
    Registered User
    Join Date
    Nov 2012
    Posts
    8
    I installed DEV-C++ in another PC (windows xp) and tried to write a simple code for a test:
    Code:
    #include <stdio.h>
    int main(void)
    {
    printf("This is C!");
    return 0;
    }

    but i received the error below:
    internal compile E:\RESTORE\C\Dev-Cpp\Examples\cc1plus.exe [Error] Illegal instruction

    what is the cc1plus. I can't find it in this directory.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. serial port reading
    By pavan_85 in forum Linux Programming
    Replies: 1
    Last Post: 08-11-2010, 08:46 PM
  2. Data structure for storing serial port data in firmware
    By james457 in forum C Programming
    Replies: 4
    Last Post: 06-15-2009, 09:28 AM
  3. my serial port data reading program isn't working
    By gnychis in forum C Programming
    Replies: 5
    Last Post: 06-02-2005, 08:40 AM
  4. Serial port reading
    By gargamel in forum C# Programming
    Replies: 1
    Last Post: 05-18-2005, 08:19 PM
  5. how to get data from the serial port?
    By Jasonymk in forum C++ Programming
    Replies: 1
    Last Post: 02-26-2003, 07:31 AM