473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Aug 1 '07 #1
3 7875
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

Aug 1 '07 #2
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
Aug 1 '07 #3
"fulltime" <Pi*******@gmail.comwrote in message
news:11********************@i13g2000prf.googlegrou ps.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.
Aug 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: fdunne2 | last post by:
Hi, I need to interface a signal generator with my computer's serial port ( to set the frequency, level etc using the appropriate byte codes). How can I send and receive (acknowledge the message...
7
by: Michael Chong | last post by:
I wrote a program that communicate with SerialComm. In every 300 milliseconds, my program continuously send & receive data via the serial port once the program starts. My program is once in a...
3
by: Hema Malini Rajanthiran | last post by:
to whom may concern...im final year student doing a project using handphone to create wireless communication. im finding difficulties to get the codes to connect to serial port using c#(visual...
5
by: Fiesta | last post by:
Hi All, I am working on a project regarding the serial COM port. I have to design my own protocol for the serial communication. In the protocol there are some bits for Read/Write, address(bank,...
19
by: ... | last post by:
Hi I need to send a chr(255) to a serial port. When I send it, through comm.write (chr(255)) it sends a chr(63) ... in Hex, I write chr(&FF) and it actually sends chr(&3F) ... why does this...
0
by: Back 9 | last post by:
Hello, I am converting c++ codes to C# now. When I get to serial communication parts, I found the data types used in C++ are different from C# which is not at all supprising at me. But problem...
0
by: usagimys | last post by:
Hi all, i'm very new in serial port communication.. here i got some problem in writing to the serial port.. i have done the connection successfully.. let me explain my situation.. i'm doing a system...
2
by: shamik | last post by:
hii friends does anybody know how to do serial communication (through) serial port in linux using c++? I am using redhat-9. it would be better if someone can provide with eg. codes of client and...
5
by: chapeau_melon | last post by:
Hello, I'm basicly not a programmer... I found some C++ codes on the net that almost satisfy me needs, wich is to communicate with an other device that sends data to me, wich I have to receive...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.