GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Mar-2006, 03:04
eng_girl eng_girl is offline
New Member
 
Join Date: Mar 2006
Posts: 3
eng_girl is on a distinguished road
Question

How to read from serial port in C


hi, I want to know how can I read data through serial port in C using the Dev-C++ program ?

which libraries to use ?

any hint may help , thanks..........
  #2  
Old 27-Mar-2006, 07:57
davis
 
Posts: n/a

Re: How to read from serial port in C


Quote:
Originally Posted by eng_girl
hi, I want to know how can I read data through serial port in C using the Dev-C++ program ?

which libraries to use ?

any hint may help , thanks..........

Basically, under Windows, you open a serial port with the CreateFile Win32 API specifying the serial port in the args list of the function.

The MSDN has a source example called mtty.c or something along those lines that is basically a Win32 terminal app.

In C (and C++), you'll find that there are no "devices" handling capability outside of basic file I/O and (usually console) stream I/O. Accessing a USB device, talking to a tape drive, running a serial or parallel port, networking, etc. are all device interfaces provided by specific operating system implementations. In other words, you have to use whatever "services" your operating system exposes to you to gain access to "low-level" devices.


:davis:
  #3  
Old 27-Mar-2006, 17:04
eng_girl eng_girl is offline
New Member
 
Join Date: Mar 2006
Posts: 3
eng_girl is on a distinguished road

Re: How to read from serial port in C


Thanks for replying I saw an example in
www.boondog.com
go to-->tutorials---->GPS and Serial Interfacing

it uses some libraries to communicate with the serial port . I tried this example but I got so many errors . can anyone see this example and how to compile and run it?

PLz help!!!!!!!!!
  #4  
Old 25-Feb-2008, 00:51
tirtho tirtho is offline
New Member
 
Join Date: Feb 2008
Posts: 1
tirtho is on a distinguished road

Re: How to read from serial port in C


Hi this is tirtho I have suffered from the same problem you have. I have some solution for it here is the code.

CPP / C++ / C Code:
#include <bios.h>
#include <conio.h>
#define COM1       0
#define DATA_READY 0x100
#define SETTINGS ( 0xC0 | 0x02 | 0x00 | 0x00)
int main(void)
{
   int in, out, status;
   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*/
              putch(out);
           if (kbhit())
           {
              if ((in = getch()) == 27)   /* ASCII of Esc*/
                 break;
              bioscom(1, in, COM1);   /*output a data*/
           }
   }
   return 0;
}

If you have some problem regarding this program you can mail me I will help my best. This program is excellent for reading data of serial port. Better to use this program in DOS version C compiler.
Last edited by admin : 25-Feb-2008 at 04:52. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a Program to Program travis134 C++ Forum 1 09-Mar-2006 20:50
Programming for serial port Chucara C++ Forum 2 03-Nov-2005 05:18
Serial port problem chirayu MS Visual C++ / MFC Forum 0 07-Jul-2005 04:52
Problem to read on a serial port collinm C Programming Language 2 30-Mar-2005 02:42
Problem with string and serial port collinm C Programming Language 13 25-Mar-2005 08:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:33.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.