reading com port

W

wanes98

Hello
I am connecting a device to one of the com ports.
could some one help in getting some code to communicat with a device and
read its status
I am sure there some code around...

gest regards
wayne
 
D

Default User

wanes98 said:
Hello
I am connecting a device to one of the com ports.
could some one help in getting some code to communicat with a device and
read its status
I am sure there some code around...


How you connect to a com port is completely dependent on your platform.
What works for Windows won't work for UNIX. Find a newsgroup dedicated
to your platform.



Brian Rodenborn
 
M

Martin Ambuhl

wanes98 said:
Hello
I am connecting a device to one of the com ports.
could some one help in getting some code to communicat with a device and
read its status
I am sure there some code around...

There is plenty of code around, but it is _all_ tied to specific
platforms and requires system-specific hooks. The system-specific
nature of this problem makes it unsuitable for discussion in a newsgroup
concerned with a platform-independent language like C. comp.lang.c is
such a newsgroup. You need to check newsgroups, mailing lists,
documentation, or technical support for your platform. Google is your
friend: all of www.google.com (for web searches), dir.google.com (for a
web directory), and groups.google.com (for newsgroups) could be useful.
 
T

Thomas Matthews

wanes98 said:
Hello
I am connecting a device to one of the com ports.
could some one help in getting some code to communicat with a device and
read its status
I am sure there some code around...

gest regards
wayne

Since you insist:
volatile int * const COM_STATUS_REGISTER =
(volatile int * const) 0x40000;
volatile unsigned char * const COM_RECV_REG =
(volatile unsigned char * const) 0x40004;
volatile unsigned char * const COM_XMIT_REG =
(volatile unsigned char * const) 0x40008;

const unsigned int CHAR_RECEIVED = 0x01;
const unsigned int XMIT_BUFFER_EMPTY = 0x02;

unsigned char Read_Com_Port(void)
{
while (*COM_STATUS_REGISTER & CHAR_RECIEVED == 0)
{
;
}
return *COM_RECV_REG;
}

void Send_Com_Port(unsigned char c)
{
while (*COM_STATUS_REGISTER & XMIT_BUFFER_EMPTY == 0)
{
;
}
*COM_XMIT_REG = c;
return;
}


For other variations, see: For more appropriate help, post to a newsgroup that
deals with your platform or operating system.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
D

Dan Pop

In said:
Since you insist:
volatile int * const COM_STATUS_REGISTER =
(volatile int * const) 0x40000;
volatile unsigned char * const COM_RECV_REG =
(volatile unsigned char * const) 0x40004;
volatile unsigned char * const COM_XMIT_REG =
(volatile unsigned char * const) 0x40008;

const unsigned int CHAR_RECEIVED = 0x01;
const unsigned int XMIT_BUFFER_EMPTY = 0x02;

unsigned char Read_Com_Port(void)
{
while (*COM_STATUS_REGISTER & CHAR_RECIEVED == 0)
{
;
}
return *COM_RECV_REG;
}

void Send_Com_Port(unsigned char c)
{
while (*COM_STATUS_REGISTER & XMIT_BUFFER_EMPTY == 0)
{
;
}
*COM_XMIT_REG = c;
return;
}

Please don't post garbage code.
For other variations, see: news:comp.arch.embedded.

What has comp.arch.embedded to do with PC programming?
For more appropriate help, post to a newsgroup that
deals with your platform or operating system.

The only sensible advice in the whole post. The term "com port" strongly
suggests a PC as the hardware platform, but the correct solution is still
heavily OS dependent.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,828
Members
47,374
Latest member
anuragag27

Latest Threads

Top