473,587 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::Re adByte
// Description : Reads a byte from the selected port
// Return type : BOOL
// Argument : BYTE& by
///////////////////////////////////////////////////////
BOOL CSerialComm::Re adByte(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 7925
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.program mer.win32 ?
--
SM
rot13 for email
Aug 1 '07 #3
"fulltime" <Pi*******@gmai l.comwrote in message
news:11******** ************@i1 3g2000prf.googl egroups.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::Re adByte
// Description : Reads a byte from the selected port
// Return type : BOOL
// Argument : BYTE& by
///////////////////////////////////////////////////////
BOOL CSerialComm::Re adByte(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
8793
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 sent - successful/unsuccessful) data throught the serial port (RS232) in MFC? Some sample code would be most appreciated! Regards, F.
7
2745
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 while, the serial port seems corrupted because when my data is sent, it doesn't go through the serial port, so as same to receive process. In order to...
3
2720
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 studio .net 2000)...kindly guide me plz... thank, r.hema malini --
5
3808
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, offset) and data to be transferred. Would anybody please tell me where I can find the Serial COM port driver, especially the driver that...
19
11211
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 happen, and how can I send it right ? I'm using vb.net 2005 express with framework 2.0 Thanks for an answear ...
0
1284
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 is that in C# there is very convenient class for rs323c communication called SerialPort. It only uses byte date type ( 8 byte unsigned value) or...
0
1984
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 for toll.. here, there have a device name TFI (Toll Fare Indicator)..This device has to display 3 things (vehicle class, fare, and message).. now,...
2
7840
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 server to send and recieve data. please tell me step by step procedure. regards shamik
5
2674
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 and save into a file. But here is the problem : I have a copy of the MS-DOS KERMIT communication program.
0
7923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.