473,788 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C/C++ Sample code for Serial Communication

I have a device connected through serial port of my desk top PC
running Windows 2000. The device is sending some data as serial stream
asynchronously. I need to do the follwings:

1) Open the COM1 port of the PC
2) Read the data coming from the connected device
3) Save the data into a file
4) After writing all the data, the COM1 port should be closed

Please refer me any sample code either in C or C++ which I could run
on Windows 2000 PC side for above tasks.
Jul 22 '05 #1
3 4509
On 19 Jan 2004 19:36:26 -0800, ja************@ yahoo.com (Jamil) wrote
in comp.lang.c++:
I have a device connected through serial port of my desk top PC
running Windows 2000. The device is sending some data as serial stream
asynchronously. I need to do the follwings:

1) Open the COM1 port of the PC
2) Read the data coming from the connected device
3) Save the data into a file
4) After writing all the data, the COM1 port should be closed

Please refer me any sample code either in C or C++ which I could run
on Windows 2000 PC side for above tasks.


Sorry, but you can't do any of those things in standard C++, the topic
here. The C++ language (and the C language, for that matter) do not
define or support direct access to any hardware at all. All input and
output is defined in terms of C++ stream or C FILE objects.

You need to ask in a support group for your particular compiler to
find out what non-standard extensions it might provide to help with
this. It is a compiler and platform specific issue, not a language
one.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #2
Jamil wrote:

I have a device connected through serial port of my desk top PC
running Windows 2000. The device is sending some data as serial stream
asynchronously. I need to do the follwings:

1) Open the COM1 port of the PC
2) Read the data coming from the connected device
3) Save the data into a file
4) After writing all the data, the COM1 port should be closed

Please refer me any sample code either in C or C++ which I could run
on Windows 2000 PC side for above tasks.


What's complicated about locating information on your own?
You have the world on you finger tips, you just need to find
the information:

http://www.google.com
Search string: serial port Win C++
--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #3
>What's complicated about locating information on your own?
You have the world on you finger tips, you just need to >find the information: http://www.google.com


Karl,

I did a google search on "serial communication c++ sample code" and it found this thread.

I found this fairly useful site:
http://www.wince.org.uk/vc/intermediate/serialrw.htm

as well as (even better I think):

http://www.codeproject.com/system/serial.asp


Jul 22 '05 #4

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

Similar topics

38
3547
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser = serial.Serial()
1
8859
by: Andreas Horneff | last post by:
Hi @ all, I've got a problem with serial communication in Borland C++ Builder. I've already found a lot of stuff about serial communication in the internet, but it dosen't work. What I want to do: I want to connect only one button to my com port. If the button is pressed,
11
7098
by: sarah | last post by:
hI, I have a project. I need to realise serial communication between PC and Altera FPGA in c or c++. The function of FPGA is working well. it can send data to uart. Does anybody know how to realise it in c or c++? Thanks
1
9904
by: Jamil | last post by:
I have a target box connected to my desktop (x86 Windows 2000) PC through a serial cable (COM port). The target box running on different processor and OS. The target box needs to send a specific formatted data (2 bytes header + 128 bytes data) asynchronously through the serial port and I've to capture it at the host PC side and save those into a file. I like to have the client-server model. The PC will be a server and start a forever...
4
15829
by: Ben Zhu | last post by:
I have a small project, which need use both RS232 port and excel for data plot. I considering use excel VB macro for the entire project. Although I used serial port extensively in MFC, I am not sure how to open serial port from VB. Can anyone give me a little light? Really appreciated,
5
1367
by: Jack Black | last post by:
Hi, all! Using VS.Net '03 under Win2k3 Server; clients will be XP, Win2k... I'm just beginning to look into how I would go about building serial communication apps in VB.Net, and am not sure where to begin looking for info, libraries, etc. The applications will basically query serial devices for whatever info they contain, clear it, etc... Can someone suggest some starting points for me on this? I saw one brief blurb that suggested...
0
1320
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 char (16 bit unicode) as input parameter. Neither of them has support a negative value. The old codes...
4
2144
by: nmsreddi | last post by:
Hi friends , after a long busy work happy to back to forums, i have developed a windows application(C#2,0) for serial communication. the aim of my application is to connect to external device(energy meter in my case) and have to get data from the that device . approximately the time to read complete data frfom meter is 10 minutes(may be more also up to one hour in some cases) ,during this time my application is not allowing...
0
2908
by: Dhananjay | last post by:
Hi, I am working on an VB.Net application which I want to communicate to external device using comm port (Serial Port) . So for that first I am trying to simulate the communication on serial port between two computers using HYper terminal on both the machines. Both these computers are connected on serial port using DB9(f) null modem (Cross) cable.
0
10370
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8995
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5402
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.