RS422 Serial Communication Codes in C++



 DEVELOP > c-Plus-Plus > RS422 Serial Communication Codes in C++

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "fulltime"
Date: 01 Aug 2007 05:13:14 AM
Object: RS422 Serial Communication Codes in C++
Hi all,
I installed a PCI bus interface board with 2 RS422 com ports on it. I
am attempting to transfer data between these 2 com ports. (for eg. com
3 send data to com 4)
The pseudo code of my main program is as follows:
1. Configure the 2 ports
2. Open both ports
3. Call sendByte () for com 3 to send data out.
4. Call readByte () for com 4 to read in data.
5. Close both ports
However, the whole program hangs inside the readByte () which is
listed below.
///////////////////////////////////////////////////////
// Function name : CSerialComm::ReadByte
// Description : Reads a byte from the selected port
// Return type : BOOL
// Argument : BYTE& by
///////////////////////////////////////////////////////
BOOL CSerialComm::ReadByte(BYTE& by)
{
BYTE byResByte;
by=0;
DWORD dwBytesTxD=0;
if (ReadFile (m_hComm, &byResByte, 1, &dwBytesTxD, 0))
{
if (dwBytesTxD == 1)
{
by=byResByte;
return TRUE;
}
}
return FALSE;
}
/
=========================================================================
Can anyone provide me with some advice?
Since the data is first sent out via com3, My intial guess is that by
the time the receiver wants to read in the data, no more data exist
for it to be read in..
Thks alot for whatever advice u may provide.
FT
.

User: "Jim Langston"

Title: Re: RS422 Serial Communication Codes in C++ 03 Aug 2007 09:20:52 PM
"fulltime" <PiaoChieh@gmail.com> wrote in message
news:1185963194.725455.3760@i13g2000prf.googlegroups.com...

Hi all,

I installed a PCI bus interface board with 2 RS422 com ports on it. I
am attempting to transfer data between these 2 com ports. (for eg. com
3 send data to com 4)

The pseudo code of my main program is as follows:

1. Configure the 2 ports
2. Open both ports
3. Call sendByte () for com 3 to send data out.
4. Call readByte () for com 4 to read in data.
5. Close both ports

However, the whole program hangs inside the readByte () which is
listed below.

///////////////////////////////////////////////////////
// Function name : CSerialComm::ReadByte
// Description : Reads a byte from the selected port
// Return type : BOOL
// Argument : BYTE& by
///////////////////////////////////////////////////////
BOOL CSerialComm::ReadByte(BYTE& by)
{
BYTE byResByte;
by=0;

DWORD dwBytesTxD=0;

if (ReadFile (m_hComm, &byResByte, 1, &dwBytesTxD, 0))
{
if (dwBytesTxD == 1)
{
by=byResByte;
return TRUE;
}
}
return FALSE;
}

/
=========================================================================

Can anyone provide me with some advice?

Since the data is first sent out via com3, My intial guess is that by
the time the receiver wants to read in the data, no more data exist
for it to be read in..

This is mostly OT as it is OS specific, but OT in the case of why it is
hanging. Apparently ReadFile is "blocking". Blocking means it won't return
until data is ready to be read. The solution, however, is OT because you
need to find out in your OS how to determine if data is ready to be read.
.

User: "Alf P. Steinbach"

Title: Re: RS422 Serial Communication Codes in C++ 01 Aug 2007 05:45:53 AM
* fulltime:

[off topic]

Even though your question is off-topic in this group, please don't feel
unwelcome. Spend some time reading posted articles to familiarize
yourself with the group, read the FAQ. The FAQ also gives good advice
about relevant groups where you can post your Windows programming
question (the only advice relevant in this group, is to use C++ 'bool',
'true' and 'false' rather than macros for completely different purpose).
C U L8R,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.
User: "fulltime"

Title: Re: RS422 Serial Communication Codes in C++ 01 Aug 2007 08:46:45 AM
so sorry that i posted on the wrong group. :(
I was trying to search for the FAQ, as to which group shld i post my
queries on. Can any kind soul pls advise me? thks
FT
.
User: "Shadowman"

Title: Re: RS422 Serial Communication Codes in C++ 01 Aug 2007 01:06:13 PM
fulltime wrote:

so sorry that i posted on the wrong group. :(

I was trying to search for the FAQ, as to which group shld i post my
queries on. Can any kind soul pls advise me? thks


The FAQ:
http://www.parashift.com/c++-faq-lite/
As for a group suggestion, perhaps start at
comp.os.ms-windows.programmer.win32 ?
--
SM
rot13 for email
.




  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER