Visual C++ to read Strings from Serial Port

Hi.

I'm doing a project using Visual C++ to read data from Serial Port. My
program needs to do *something* when it receives specific data. For eg,
if the program receives "Alarm 1 Zone 4", it will do something.

The data received will be variable in length. My questions:

1) Any recommendations for the serial Comm Class for Visual C++?
2) How can i compare the data i receive from serial to the specific
messages i'm looking for, eg data types, size of data types,
limitations & etc.?

Thanks. Any comments are highly appreciated.

Leng

0
1/16/2007 5:23:55 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1812 Views

Similar Articles

[PageSpeed] 28

As far as the serial part goes, it is pretty simple take a look at the 
CreateFile function.

Here are some examples:

http://www.codeproject.com/system/chaiyasit_t.asp
http://www.naughter.com/serialport.html
http://www.codeguru.com/Cpp/I-N/network/serialcommunications/article.php/c5425

As far as reading data from the port.  Once you have opened the com port, 
you will need a worker thread the pulls the port for data. When you receive 
data you will be responsible to parse the data and interpret it's meaning. 
Without knowing how the data is being sent to you it's hard to make 
recommendations.

AliR.

"albertleng" <albertleng@gmail.com> wrote in message 
news:1168968235.421739.228000@a75g2000cwd.googlegroups.com...
> Hi.
>
> I'm doing a project using Visual C++ to read data from Serial Port. My
> program needs to do *something* when it receives specific data. For eg,
> if the program receives "Alarm 1 Zone 4", it will do something.
>
> The data received will be variable in length. My questions:
>
> 1) Any recommendations for the serial Comm Class for Visual C++?
> 2) How can i compare the data i receive from serial to the specific
> messages i'm looking for, eg data types, size of data types,
> limitations & etc.?
>
> Thanks. Any comments are highly appreciated.
>
> Leng
> 


0
AliR3470 (3235)
1/16/2007 6:04:31 PM
Here is another one.

http://www.codeguru.com/Cpp/I-N/network/serialcommunications/article.php/c5395


AliR.

"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:Ps8rh.23694$sR.9271@newssvr29.news.prodigy.net...
> As far as the serial part goes, it is pretty simple take a look at the 
> CreateFile function.
>
> Here are some examples:
>
> http://www.codeproject.com/system/chaiyasit_t.asp
> http://www.naughter.com/serialport.html
> http://www.codeguru.com/Cpp/I-N/network/serialcommunications/article.php/c5425
>
> As far as reading data from the port.  Once you have opened the com port, 
> you will need a worker thread the pulls the port for data. When you 
> receive data you will be responsible to parse the data and interpret it's 
> meaning. Without knowing how the data is being sent to you it's hard to 
> make recommendations.
>
> AliR.
>
> "albertleng" <albertleng@gmail.com> wrote in message 
> news:1168968235.421739.228000@a75g2000cwd.googlegroups.com...
>> Hi.
>>
>> I'm doing a project using Visual C++ to read data from Serial Port. My
>> program needs to do *something* when it receives specific data. For eg,
>> if the program receives "Alarm 1 Zone 4", it will do something.
>>
>> The data received will be variable in length. My questions:
>>
>> 1) Any recommendations for the serial Comm Class for Visual C++?
>> 2) How can i compare the data i receive from serial to the specific
>> messages i'm looking for, eg data types, size of data types,
>> limitations & etc.?
>>
>> Thanks. Any comments are highly appreciated.
>>
>> Leng
>>
>
> 


0
AliR3470 (3235)
1/16/2007 6:06:05 PM
For serial port communication w/MFC, check this out:

http://www.naughter.com/serialport.html

-- 
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"albertleng" <albertleng@gmail.com> wrote in message
news:1168968235.421739.228000@a75g2000cwd.googlegroups.com...
> Hi.
>
> I'm doing a project using Visual C++ to read data from Serial Port. My
> program needs to do *something* when it receives specific data. For eg,
> if the program receives "Alarm 1 Zone 4", it will do something.
>
> The data received will be variable in length. My questions:
>
> 1) Any recommendations for the serial Comm Class for Visual C++?
> 2) How can i compare the data i receive from serial to the specific
> messages i'm looking for, eg data types, size of data types,
> limitations & etc.?
>
> Thanks. Any comments are highly appreciated.
>
> Leng
>


0
ajaykalra (6842)
1/16/2007 6:07:24 PM
http://www.codeproject.com/system/cserialcom.asp will be helpful ........

secondly when u go to this lower level, u get only raw data ......

or are u expecting serialized data on port ....
if yes then u may think of compatible deserialization .....

"albertleng" <albertleng@gmail.com> wrote in message 
news:1168968235.421739.228000@a75g2000cwd.googlegroups.com...
> Hi.
>
> I'm doing a project using Visual C++ to read data from Serial Port. My
> program needs to do *something* when it receives specific data. For eg,
> if the program receives "Alarm 1 Zone 4", it will do something.
>
> The data received will be variable in length. My questions:
>
> 1) Any recommendations for the serial Comm Class for Visual C++?
> 2) How can i compare the data i receive from serial to the specific
> messages i'm looking for, eg data types, size of data types,
> limitations & etc.?
>
> Thanks. Any comments are highly appreciated.
>
> Leng
> 


0
mm9402 (8)
1/16/2007 6:07:43 PM
Reply:

Similar Artilces:

Help: Visual Basic Setup Problems
I picked up a book to learn Visual basic but cannot install it on my system after I download it from this site: http://www.microsoft.com/express/Windows/. I'm assuming my pc is the problem, but have no idea where to start. It seems to stat installing, but then I get a pop-up that says: "Microsoft Visual Basic 2008 Express Edition with SP1 - ENU has encountered a problem during setup. Setup did not complete correctly." Any help would be appreciated. Thanks. Darren Harris Staten Island, New York. Searcher7 wrote: > I picked up a book to learn Visual basic b...

Exchange 2k Public Folders Read Unread Settings
Hi everyone, i have a question concerning The Read / Unread Status on Public Folders. In the Exchange System Manager it is possible to store The Read Unread Status per User, so if the user opens the folder he sees the mails, discussion etc which he read and which not, Actually i want to have a setting, that a group of Persons see which Mails are already read by someone, so thexy dont have to read them .... I had the idea of an eventsink on the folders, but didnt get through ... regards sven ...

Reading pane in outlook client
Does anyone know if the reading pane in outlook 2003 has the same charactistics as the preview pane in Outlook 2000 (Office XP)? That is, when considering viruses, is the reading pane the same as opening an e-mail like it was in Outlook 2000? ...

Read registry of dead computer
Looking for a way to read values out of a non working computers registry from within a working copy of Windows. (load a hive from a non booting XP machine). I know it can be done from the RC, but it is so slow to boot to RC just to quickly compare a few values. Is there any 3rd party software. I used to have a program for Win98 that would do this )cant remember name). "Jack B. Pollack" <N@NE.nothing> said this in news item news:#z98E3nnKHA.1548@TK2MSFTNGP04.phx.gbl... > Looking for a way to read values out of a non working computers registry > ...

Serial No in Detailed Sales Report
I'd like to be able to print the Serial Number in our detailed sales report. However, I don't see that field as a possibility to print. I can print it in the Item Movement History report, but in that report I don't get the Price field. We have been using serial numbers with our gift certificates that transferred from QS2000 and need to be able to get reports that show the serials number. Would appreciate assistance with modifying the Detailed Sales Report. Hi there, Retail Analytics, from Professional Advantage, is designed to help retailers manage their business by delive...

XmlTextReader.Read() and ampersand?
XmlTextReader reader = new XmlTextReader ("c:/downloads/somedata.xml"); while (reader.Read()) { ....etc. } I've determined that the problem in the source XML is a node that contains an attribute that doesn't have the ampersand encoded as "&amp;" <item security="Common Stock (Class A, B & C)"> How do I manage this because when the Read() method above reaches this portion of the XML document, I get a parsing error. How do I encode "&" prior to the Read() somehow? Dave. Dave wrote: > I've determined that t...

Separate Bold Text from a string
How can i separate bold text from a string for example East Doncaster Victoria, Australia If East doncaster is bold i want to separate it in another column. thanks It would need a UDF. Function GetBold(rng As Range) As String Dim mStart As Long Dim mEnd As Long Dim i As Long If rng.Cells.Count > 1 Then GetBold = CVErr(xlErrRef) Else Do mStart = mStart + 1 Loop Until mStart > Len(rng.Value) Or rng.Characters(mStart, 1).Font.Bold If mStart > Len(rng.Value) Then Exit Function mEnd = mStart Do mEnd...

Problem With Sending Read Receipts
I have looked in the knowledge base trying to find information about this. I have my settings in Office 2000 set to ask before I send a read receipt. I get the box that asks for my decision just fine. When I click Yes it tries to send the message but it eventually stops and the read receipt sits in the Outbox. Has anyone had problems with this? When I was using Outlook Express I had no problems sending read receipts. Unfortunately I do not have the error message available. Any help would be appreciated. ...

MFC/C++
I have uploaded some MFC related stuff. you can download sample projects http://neuralnetworks.in/windowsprogramming.html which includes Automate Notepad and Custom Color Dialog > I have uploaded some MFC related stuff. > you can download sample projects > > http://neuralnetworks.in/windowsprogramming.html > > which includes Automate Notepad and Custom Color Dialog It will help you put [ANN] in the title to show that it is an announcement. In addition, it will be good if you have a section to leave comments on your website. --- Ajay Thanks for the link to your websit...

Pumping Message in synchronous COM Read
Hi, everyone. I'm developing a software to comunicate with a device, by COM1 serial. After I send a command, the device can take until 2 seconds to answer. I gave up using a NON-Blocked READ and callback functions to handle the answer, because the same answer will have different actions depending which object started the command. So I use a READ Thread, to read until the answer comes or timeout. The main thread (who called read), pump windows messages until read returns. But I couldn't make a pump loop to do it right. MsgWait don't capture ON_CLOSE messages. So it won't close...

Send a string between 2 applications
Hi, Is there a way to send a string from one application to another using SendMeassage or PostMessage functions ? Yoav. Yoavo wrote: > Hi, > Is there a way to send a string from one application to another using > SendMeassage or PostMessage functions ? Have a look at WM_COPYDATA which you can use to transfer data between apps. -- SvenC Try WM_COPYDATA message "Yoavo" wrote: > Hi, > Is there a way to send a string from one application to another using > SendMeassage or PostMessage functions ? > > Yoav. > > > You can use WM_COPYDATA. ...

Open C:/examplefile.xls or file.txt from another excel worksheet
Hey, people!! I need some help, I want to create an excel worksheet that checks which files are in a directory (C:\) and lists them in my worksheet. When I click on the listed files it takes me to the directory were they are located. If you can open the files when clicked even better!!! I consider myself average in vba now, but I need someone to tell me which function or built in procedure I should use. Thanks, Chay Chay, I'm not entirely sure everything you want to do here, but let me offer this as a start. This macro will list all the files in the "C: \" directory on ...

Serialization problem with .net vb client
Hello, We have a COM server dll that links with other dlls. Classes in these dlls support serialization. These dlls are built by VC6. When used by a ..net vb client, classes in the secondary dlls are unable to deserialize. We get the following warning from CRuntimeClass::Load: 'Cannot load <classname> from archive. Class not defined.' When used by a VC6 client, it works fine. Any help would be appreciated. Thanks. John I must add a correction. It only works fine when the secondary dlls are linked to a VC6 client, bypassing the COM server. A VC6 client going through the COM ser...

Read Only Folder
I would like to create a 'Read Only Folder' or a 'Password Protected Folder' in which I can add spreadsheets to without having to individually protect each spreadsheet. cwt This is a function of Windows OS(or whatever OS you are running under), not Excel. For Windows, see Start>Help "permissions"(no quotes). Gord Dibben Excel MVP On Wed, 16 Jun 2004 07:33:53 -0700, "cwt" <anonymous@discussions.microsoft.com> wrote: >I would like to create a 'Read Only Folder' or >a 'Password Protected Folder' in which I can add >s...

Need help detecting/reading smartcard default certificate ID
Has anyone done anything with reading smartcards? Would like to be able to use smartcard default certificates for identity verification on a couple of processes. I'm not so much concerned about restricting the script (it's an hta) to a specific user per-se, rather I need to be able to log WHICH user ran a routine. I'd use domain credentials, but there are situations where the script will be run from non-domain machines, or from users that are logged on locally. any pointers or sample code would be greatly appreciated. The code also needs to be supported from Win2K thr...

Excel File Opens as Read Only in Vista #3
I am running into a situation where an Excel file installed in the Program Folder opens as Read Only in Vista; for example, c:\Program Folder\zxc\hello.xls. I have been able to narrow down the cause to the User Account Control feature in Vista and the only work around to this problem is to turn OFF the User Account Control and the file opens normally and my application functions normally. I am compelled to install the file in the Program folder because the Packaging Wizard offers no other installation options and places the application is the Program Folder. Placing the application in ...

Dataset to memory to serializer?
I created business entity classes using XSD.exe. In code I've populated my dataset. Now, I want to put that data into the entity class. Do I use DataSet.WriteXml() to a memorystream, then pass the memorystream to a serializer? I want to avoid I/O to disk if possible. No examples show how best to populate entity classes via dataset. Thanks for any info. Hi Marty, Thank you for posting in the community! First of all, I would like to confirm my understanding of your issue. From your description, I understand that need to know how to serialize the data in a DataSet and how to popul...

Safe way to read attribute
Hi Is there a easy way to read a attribute and at the same time making sure that the attribute excist and is of the right type (int, string, double)? Thanks Torben Torben Laursen wrote: > Is there a easy way to read a attribute and at the same time making sure > that the attribute excist and is of the right type (int, string, double)? What are you using to read out the XML, XmlTextReader, XmlDocument, XPathDocument? Is there a schema associated with the XML that defines those types for the attributes? -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ ...

Read Receipts
The standard read receipt is somewhat cryptic. eg Final-Recipient: RFC822; xxx@yyy.com Disposition: automatic-action/MDN-sent-automatically; displayed X-MSExch-Correlation-Key: vutepr88W0O8/648n5xp/g== Original-Message-ID: <92DBBEA563EC49BD91657854F3BA8B69@delljim> Is it possible to configure it to be more informative? eg including time and date sent -- Jim Bunton On Tue, 8 Dec 2009 17:53:20 +0100, Jim Bunton wrote: > The standard read receipt is somewhat cryptic. > eg > Final-Recipient: RFC822; xxx@yyy.com > Disposition: automatic-action/MDN-sent-...

Serial number status
We just started using Serial Numbers on some of our higher ticket items. Judging from the short history it appears that status 0 = Available for sale 1 = Sold 2 = Offline Can anyone confirm for me? Are there any other statuses? 1 Serialized item is Sold 0 Serialized item is Available Afshin Alikhani - afshin@retailrealm.co.uk Retail Realm = = = = = = = = = = = = = = = = = = = = Rick@ASP" <RickASP@discussions.microsoft.com> wrote in message news:AD89934A-0DA8-41C7-8CFD-2F746AECE6DD@microsoft.com... > We just started using Serial Numbers on some of our higher ticket items...

Why does Outlook 2002 sometimes send read receipts even when I've disabled them?
Running Outlook 2002 SP2. Periodically, I'll receive a message from my ISP that some mail message couldn't successfully be sent. Examining the message it was trying to send revealed that the message was a read receipt being returned to some spam address that doesn't actually exist. Originally, I had read receipt requests set to prompt for what action to take but these receipts appeared to be going out automatically without notifying me. I also tried changing the option to never return read receipts but I still get these messages indicating that a read receipt is, in fact, being se...

My problem with XML Serialization
I use XSDValidation before deserializatoin. It works fine because I have schemaLocation set in XML file. However, serialization routine overwrites this root element attribute and XSD validation doesn't work 2nd time around in this application. So I must have a way of serializing schemaLocation to the root node. I just answered a similar question a few days ago. Just add a field for the schemaLocation and attach the XmlAttributeAttribute as shown in [0] -- HTH Christoph Schittko [MVP] Software Architect, .NET Mentor [0] http://groups.google.com/groups?q=christoph+mvp+xml+adding+schem...

Audio Visual Stencils
Does anyone know where I can get free Audio Visual stencils for Visio 2003, specifically to map home theatre setups (amps, tv's, speakers, dvd, cd, etc) Alternatively some free or web software that will do this? Thanks Stu chris just posted some on his site http://www.visguy.com/2006/12/15/audio-visual-components-shapes/ al <stuey21@gmail.com> wrote in message news:1166514566.390935.112170@t46g2000cwa.googlegroups.com... > Does anyone know where I can get free Audio Visual stencils for Visio > 2003, specifically to map home theatre setups (amps, tv's, speakers, >...

Money 2000 compatible c Windows XP Professional?
Is Money 2000 Standard Edition Version 8 compatible with Windows XP Professional? Thanks. ...

Serial Autocorrelation
If I have a column of data, is it possible in Excel to test for Seria Autocorrelation? It's been a while since my rudimentary stat educaction, so I may have the terminology wrong. Basically, I have list of returns from a trading system. I am interested to see if thes returns are related (or linked) to each other in some way. Any thought would be greatly appreciated. Thanks -- Message posted from http://www.ExcelForum.com ...