RS422 Serial Communication Codes in C++

F

fulltime

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
 
A

Alf P. Steinbach

* 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
 
F

fulltime

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
 
J

Jim Langston

fulltime said:
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.
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top