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 11-Dec-2007, 14:35
damy damy is offline
New Member
 
Join Date: Aug 2007
Location: Romania,Timisoara
Posts: 24
damy is an unknown quantity at this point

Access to RS232


Hi,

I want to make a C# program that will show if the pc have a rs232 or not,and if the response is positive to acces it.

Questions:
-can I play with rs232(com1) if it has nothing conected to it(writing/reading)
-where can I start to find informations about programming rs232

In the future I want to connect a circuit with a controller on it made by me and I want to learn how to transmit data through rs232 first.

10x
  #2  
Old 11-Dec-2007, 15:18
inevitable inevitable is offline
Junior Member
 
Join Date: Nov 2007
Posts: 53
inevitable is on a distinguished road

Re: accsesing rs232


I dont know about, c#,
but there is definetely in 'c' and c++ on windows and linux.
Linux you can use "outb" for writing to the port and "inb" for reading from the port;
  #3  
Old 12-Dec-2007, 14:33
damy damy is offline
New Member
 
Join Date: Aug 2007
Location: Romania,Timisoara
Posts: 24
damy is an unknown quantity at this point

Re: Access to RS232


Hi,

I didn't find outb and inb but I found inport and outport commands and I made this program but when I read the port at address 0x3f8(com1 address) it returns 0x0 even though I sent caracter 'C' to the com1 port.

Why it returns 0x0 and not 'C' correspondent in ascii code?

CPP / C++ / C Code:
#include <stdio.h>
#include <dos.h>

int main(void)
{
   unsigned char result;

   int value='C';

   int port =0x3f8;           /* serial port 1 */


   outport(port,value);
   printf("Value %d send to port %d\n", value,port );
   result=inport(port);
   printf("Byte read from port %d=0x%X\n",port , result);
   return 0;
}
Last edited by admin : 13-Dec-2007 at 07:46. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #4  
Old 13-Dec-2007, 04:19
seprich seprich is offline
Member
 
Join Date: Jun 2007
Posts: 110
seprich has a spectacular aura aboutseprich has a spectacular aura about

Re: accsesing rs232


Quote:
Originally Posted by damy
Hi,


I didn't find outb and inb but I found inport and outport comands and I made this program
so you are probably programming to windows using Borland(??) compiler ? And in fact the code you posted is C not C#.
Background info such as operating system is very important to know. The functions which <dos.h> provides for i/o port programming are very low level functions. There is no inbuilt flow control or buffering.
Quote:
Originally Posted by damy
but when I read the port at address 0x3f8(com1 address) it returns 0x0 even though I sent caracter 'C' to the com1 port.

Why it returns 0x0 and not 'C' corespondent in ascii code?
What are your assumptions about COM ports i.e. serial i/o ports ?
Why did you expect to get " 'C' corespondent in ascii code " ? COM ports are not loopback-devices so they don't echo the stuff you sent back to you.

This article : http://www.beyondlogic.org/serial/serial1.htm#30
provides very good explanations about serial ports and of their programming in certain pc environments (Part 3). There you can see that using <dos.h> is very low level programming.

I think the easiest way to program for COM ports is in linux where you can access serial ports just like a normal file in /dev/ folder COM1 = ttyS0 etc.. This kind of access is buffered and the behaviour of reading would be in a blocking mode with associated timeout.
  #5  
Old 13-Dec-2007, 09:26
damy damy is offline
New Member
 
Join Date: Aug 2007
Location: Romania,Timisoara
Posts: 24
damy is an unknown quantity at this point

Re: Access to RS232


You were right,my o.s is windows and I use a turbo C compiler.

I read the article you recomanded and I have seen there that rs232 can be transformed in a loopback device by conecting some pins toghether. I don't know if that is good for motherboard.Now I'm thinking if to do it or not.

Thanks
  #6  
Old 13-Dec-2007, 18:46
ahbi82 ahbi82 is offline
Member
 
Join Date: Jul 2006
Posts: 114
ahbi82 will become famous soon enough

Re: Access to RS232


Quote:
Originally Posted by damy
You were right,my o.s is windows and I use a turbo C compiler.

I read the article you recomanded and I have seen there that rs232 can be transformed in a loopback device by conecting some pins toghether. I don't know if that is good for motherboard.Now I'm thinking if to do it or not.

Thanks

For RS232 port, they actually have internal ersistors to limit the current. Don't worry........ try to find some technical specifications of RS232 port.




One simple and trivial test u wanna try is to, use a switch and and LED.
Set the switch (the pin u connected to) as the input and set the LED (the pin you connected to) as output. The RS 232 port also has 5V and Ground.

Play around......... its fun. Furthermore you can try connect senros and buzzers. BCD LED......... so many more.
  #7  
Old 14-Dec-2007, 02:27
inevitable inevitable is offline
Junior Member
 
Join Date: Nov 2007
Posts: 53
inevitable is on a distinguished road

Re: Access to RS232


As an alternative to loopback, a system generally has more than two comports, then connect both the commports with RS232 cable. Then for reading open one ttsy and for other another ttsy.

This will help you.
 
 

Recent GIDBlogObservations of Iraq 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
c program for rs232 interface knallkopf66 C Programming Language 1 04-Mar-2004 10:03

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

All times are GMT -6. The time now is 11:34.


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