Advice on how to write a MFC application for a Data Aquisition boa

Hello,

I'm writing a MFC GUI for a data aquisition system.  I will need to 
communicate with the board through USB or a serial port (has to be able to 
function using either 1 of them or maybe both), be able to send data to the 
board to configure it then aquire data and display the data in real-time (as 
much as possible).  I would like some advice on to what approaches I should 
take to accomplish such tasks, especially the part of aquiring and displaying 
the data in real-time.  Will I need to use a thread?    My MFC GUI is a SDI 
FormView, and will have to run under windows xp (maybe older versions).  
Currently, I have a graph working that displays data in real-time(simulation 
of it) and controls to configure the board.  The board's USB chip 
manufacturer has a dll's with read/write functions to use, as well has 
drivers.  I'm unsure on how the whole interfacing with board and the GUI will 
be.  I'm looking more for an overview, than specific details.
0
11/4/2004 11:35:03 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
234 Views

Similar Articles

[PageSpeed] 42

Raed Sawalha wrote:
> Hello,
> 
> I'm writing a MFC GUI for a data aquisition system.  I will need to 
> communicate with the board through USB or a serial port (has to be able to 
> function using either 1 of them or maybe both), be able to send data to the 
> board to configure it then aquire data and display the data in real-time (as 
> much as possible).  I would like some advice on to what approaches I should 
> take to accomplish such tasks, especially the part of aquiring and displaying 
> the data in real-time.  Will I need to use a thread?    My MFC GUI is a SDI 
> FormView, and will have to run under windows xp (maybe older versions).  
> Currently, I have a graph working that displays data in real-time(simulation 
> of it) and controls to configure the board.  The board's USB chip 
> manufacturer has a dll's with read/write functions to use, as well has 
> drivers.  I'm unsure on how the whole interfacing with board and the GUI will 
> be.  I'm looking more for an overview, than specific details.

Yes, you will need to use a thread (or threads).  Your serial input 
calls (I assume USB input calls are similar) must block and await data, 
and you shouldn't block the GUI thread.  Your GUI thread must continue 
to respond to messages in order to remain responsive to the user.

Find the Allen Denver article about serial communications in MSDN, and 
the related MTTTY sample code.  It does not use MFC, but it does have 
everything you need for serial communication threads.  For best 
performance you will need to closely study and fine tune the parameters 
to SetCommTimeouts and the byte count parameter to ReadFile.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
11/4/2004 1:20:11 PM
I do a lot of this sort of thing. The simplest approach is to use threads. I typically
have one thread that sends data to the device, and another that receives data. The data is
usually some sort of packet with a header, data bytes, and a checksum, and is usually sent
in response to a specific request of the host computer. In the case of USB, this is the
natural way of doing communications.

You should not have any differences detectable when running back to Win98 for most
devices. The only issue is whether or not the board vendor's driver works in all the
various environments.

Overall, this is pretty straightforward. A few months ago I was interfacing to embedded
HVAC components which were sending realtime data back, and today I'm interfacing to a mass
spectrometer. What I do is either use worker threads with I/O Completion Ports as the
queueing mechanism, or UI threads with asynchronous I/O (for serial ports this is
required). My favorite mechanism is to use an I/O Completion Port with a thread to handle
the completion notification. There is an essay on how to do this on my MVP Tips site. I
can enqueue both requests to perform I/O and get the notifications that the I/O has
completed. I then use PostMessage to post a message back to the main GUI thread; this
message contains a pointer to the current buffer, and I plot or report the data from that
buffer.

Also look at my essay on worker threads to see thread shutdown techniques.

I/O Completion ports do not exist on toy MS-DOS systems, but my client base has now
abandoned MS-DOS systems, in fact,  most are now insisting on Win2K or better (one has a
constraint that they only run on Server 2003), so the I/O Completion Port model is a
cleaner solution when you can get away with it.

Generally I use MDI CFormViews for this; for example, the mass spec needs to monitor many
instruments at once. I learned years ago that anything that starts out as SDI turns into
MDI, so I just do MDI to start with these days. It really simplifies things to use MDI,
because there is never a temptation to use global variables for "the" data; it is always
clear from the start that there are many instances of data and communication.

"Real time" is always questionable; the best you can hope for is
"sort-of-real-time-most-of-the-time", but that is generally good enough. 
					joe

On Thu, 4 Nov 2004 03:35:03 -0800, Raed Sawalha <RaedSawalha@discussions.microsoft.com>
wrote:

>Hello,
>
>I'm writing a MFC GUI for a data aquisition system.  I will need to 
>communicate with the board through USB or a serial port (has to be able to 
>function using either 1 of them or maybe both), be able to send data to the 
>board to configure it then aquire data and display the data in real-time (as 
>much as possible).  I would like some advice on to what approaches I should 
>take to accomplish such tasks, especially the part of aquiring and displaying 
>the data in real-time.  Will I need to use a thread?    My MFC GUI is a SDI 
>FormView, and will have to run under windows xp (maybe older versions).  
>Currently, I have a graph working that displays data in real-time(simulation 
>of it) and controls to configure the board.  The board's USB chip 
>manufacturer has a dll's with read/write functions to use, as well has 
>drivers.  I'm unsure on how the whole interfacing with board and the GUI will 
>be.  I'm looking more for an overview, than specific details.

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15978)
11/5/2004 9:51:33 PM
Reply:

Similar Artilces:

substitution operator new & delete provided by MFC?
I tried another memory tracer provided by http://www.fluidstudios.com/, which is called MMGR. Without MFC, MMGR works fine. However, programs using MFC cannot be built because MMGR has some operator new() and delete() functions, which are already defined in MFC library. How can I substitute MFC memory operators to MMGR memory operators? Please reply. Thanks in advance. Bae,Hyun-jik Search your MSDN for "operator new" and read the C/C++ location topics. -- ============ Frank Hickman Microsoft MVP NobleSoft, Inc. ============ Replace the _nosp@m_ with @ to reply. "Ba...

Application Problems
I'm having trouble opening any Office 2004 Mac application. I've restarted multiple times, I've downloaded the software again but it still won't work. The applications try to start but then stop. Any suggestions? In article <721D46CD-7C44-46B3-9128-620B61690297@microsoft.com>, jnumac <jnumac@discussions.microsoft.com> wrote: > I'm having trouble opening any Office 2004 Mac application. I've restarted > multiple times, I've downloaded the software again but it still won't work. > The applications try to start but then stop. Any s...

pasting financial data from web
I am pasting pricing data from a web page into my spreadsheet. The data looks like this: 7.091 [in cell A1] When I try to use A1 in an equation I get #VALUE! as the result. I believe this is because the data pasted is in a text format not a number. I have tried the formula B1=value(A1) but still get the same result. How can I get the pasted data in a data format (currency or number) that I can use in an equation? Thanks in advance Could be a couple of things going on. You have extra spaces in the data. Try TRIM and CLEAN functions. You have non-breaking spaces Try Edit>Re...

Split combined date time data
From file dump have combined date time cells eg "14/04/03 14:20" (value 37725.59722). Want to perform time analysis so need to split to 2 separate cells; eg. "14/04/2003" (value 37725) & "14:20" (value 0.59722). Is there a fnc to do this? (Currently convert cell to value, then fncs trunc & cell less int(cell) then refmt to date dd/mm/yy & time hh:mm respectively) Mark, It seems that =INT(A2) and =MOD(A2, 1), suitably time or date formatted, would be the ticket. But it seems that's what you're already doing, and want something else....

MFC Support in DLL's
I realize this is probably an old and often repeated question, but I have been unable to find any articles that have been able to help me. I have a DLL written in plain win32 that I want to add MFC support to. I'm having trouble with the DllMain function. I've tried just removing the entire DllMain function, yet I'm still getting the compiler error that DllMain is already defined. What Do I need to add to make my DLL support MFC? Thanks in advance, ed "ed" <ed@discussions.microsoft.com> wrote in message news:03A4326E-E360-4FAF-B6DF-31D0063DC05A@microsoft....

How do I validate data using different lists based on the data in.
How do I validate data using different lists based on the data in another cell? There are instructions here for dependent data validation lists: http://www.contextures.com/xlDataVal02.html Shannon wrote: > How do I validate data using different lists based on the data in another cell? -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html ...

can I make a bell curve from this data?
A colleague at work asked if I could put some simple Excel data into a bell curve. I don't know what I'm doing, math-wise, and I don't know if my data even lends itself to a bell curve. Here it is: We have 19 cars in our division. There are usually 3 cars that are driven a lot and 3 that don't get driven much, so we periodically rotate the highs and lows so that mileage somewhat evens out. So what I have is the annual mileage for each car. My colleague is hoping this will look great on a graph. Can this be put into a bell curve format? Or would some faux work-around make it l...

Letter Writing Assistant does not work with Office 2007
Letter Writing assistant will display documents created with version 2003 but when a new document is to be created with 2007, fields are not available to add. When I create that same document in Office 2003, those fields are available. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in th...

how to replace the "new" and "delete" operator funtion define in mfc.
I am trying to overload the global new and delelte operator function in order to use my own memory allocation mechanism.Every time i do it smoothly until i get to a MFC project. The problem is that there are already a set of new and delete operator function defined in afxmem.cpp of MFC. While i'm trying to replace them with my own,the new operator call the MFC's operator new function and call my operator delete function.This is a surelost. How can i replace them completely? Booker, Best regards. It is strongly recommended that you do not overload operator new/delete....

refer to data on multiple worksheets using hlookup/look up data on many worksheets?
Hi I have data on many worksheets in the same workbook. Is it possible to look up data on multiple worksheets using Hlookup, which means can the second argument in the formula refer to multiple sources? If it is not possible, is there any other way I can do so? I would like to select and display data according to a fixed order, whereby the data is located in one of many worksheets in the same workbook. For eg, I have stock returns of many firms in many worksheets. Say I would like to display in a single worksheet the returns of Firm D, Firm Z, Firm R; whereby the data of these 3 fir...

Using Alt-key in MFC app
I am creating a cad-program which must simulate the user interface of another program. This means that I need to be able to use Alt-key combinations, like alt-leftmouse and mousemove and such. Default key handling forces the alt key to be used with menu only. Is there a way to work around this safely? Yours, Morten Aune Lyrstad Never mind; got it! Just needed to find GetAsyncKeyState(VK_MENU)! Use GetKeyState instead. "Morten Aune Lyrstad" <too@much.spam> wrote in message news:fBgHc.13$Rb.7643@juliett.dax.net... > Never mind; got it! Just needed to find GetAsyncKeySt...

Import data from Access to SQL
Hello everyone. I have an instance of SQL Server 2008 Express on my PC, I have need to export tables from Access 2007 to SQL. I did successfully migrate (table access with unique ID field primary key) with SQL Server Migration Assistant for Access 2008, I rechecking the tables in SQL and it's all ok. Linking tables in Access. I have saved import (from text files) that work without problems with Access tables, when I go to do one of these imports, at some point the message "Unable to register changes. The entered value violates the settings for the table or the list...

CRM 3.0 Service Calendar, Server Error in '/' Application
Hi I have been chasing this error for a while now with no success. When viewing the Service calendar or Creating a new Activity we get an error that would appear to be some issue with a date format somewhere. (error message at bottom of post) I have checked that the CRM application in IIS is running under dot.net 1.1, I have installed all service roll ups and hot fixes, I have stood on my head and prayed to all the MS gods that I know of - does anyone have any new ones I can try? It seems to have appeared after I installed some C360 add ons - removing them however has not fixed the is...

Advice
I am going to start a new job in a month looking after an Exchange 2000 server and would like to know if there are any good resources that anyone knows of online for a complete newcomer to all things Exchange as I need to get up to speed pretty sharpish! Most of the sites I've found seem to assume a degree of knowledge and I have none! Any help would be greatly appreciated. TIA J My advise is to go an visit your local book store and see what they have fir Exchange 2000, there are some excellent books out there, not sure what knowledge you have with regard to Active Directory but you ...

data range props
I have a problem with external data. In the Data Range Properties, under Data Layout. There are 3 options after 'If the number of rows in the data range changes upon refresh:' 1 - Insert cells for new data, delete unused cells 2 - Insert entire rows for new data, clear unused cells 3 - Overwrite existing cells with new data, clear unused cells. I want option 3 to be the default oprion but it always defaults back to option 2. Is there any way I can change this.?? Cheers Baz ...

SOS! how do I write a customized function to do multiple-value lookup in Excel 2007?
I have two regions in exact same places of sheet 1 and sheet 2, I want to find all cells in the region in sheet 1, with cell content equal to 0, and then add the numbers at the corresponding locations in the region in sheet 2 up. For example, let's say in the region in sheet 1, there are multiple locations where the cell content = 0: A1, B3, C4, D2, etc... I would like to obtain sum(sheet2!A1, sheet2!B3, sheet2!C4, sheet2! D2), etc. How do I do that? I want to write a user customized function for that: The regions in sheet1 and sheet2 are fixed to be D7 to Z20. So the fi...

Pass cell data to Query
Anyone know how to pass the contents of a cell to an sql query? I have a worksheet that I have connected to an SQL database that I want to query to get data. The worksheet is like an invoice. What I want is the user to input a product code and currency then the query to return the price. It sounds simple enough to do with a nested function but the price list is made complex by prices in different currencies so the level of nesting allowed is insufficient. I thought a database query would be a more appropriate solution but I can't find any information on how to do it in this way. -...

Moving Palm Desktop data to outlook
I have a new HP Ipaq which only runs Outlook for calendar and contact information. All of my calendar and contacts are in Palm Desktop software. I can move through export files, the contact information, but I cannot find a way to export from Palm and import to outlook, the calendar information. Does anyone have a solution, software utility or other method to move all of the calendar information from Palm desktop to Outlook Thanks JEV jverzella@comcast.com <anonymous@discussions.microsoft.com> wrote: > I have a new HP Ipaq which only runs Outlook for calendar > and contact ...

Error for multiple users merging data from Access into Word 2003
Hello. I have multiple users who access a Microsoft Access database. The issue I have is that when a user is in the database, a different user is unable to merge data from that database, as Word states that the database file is already in use (which is it). When no one is in the database, all users can merge without issue. When I try to merge data from the database already in use, the error message is as follows: "Test connection failed becuase of an error in initializing provider. Could not use "; file already in use". Is there any simple way that I can make Word '...

Formula: values in one column based on corresponding data
My goal is simply this - I want to add a series of values (hours and minutes) worked on specific projects within one months time. Now, the month/day/year is listed in a separate column. Thus, one column lists all the hours and minutes used to complete a project and now I want to add up those values for a specific month's time. The reason is so I can explain how much time was spent doing a specific task for various cases. I believe the formula starts with "=sumif(" but after that I simply do not know. SUMIF won't suffice as you have multiple conditions to satisfy fo...

Creating a chart using data from multiple worksheets
I am trying to create a chart using data from multiple worksheets within one workbook. Does anyone have experience in doing this? I would suggest consolidating / referencing the data from the different worksheets into a single worksheet. Once that data is in a single worksheet, you can create your chart. You can use different worksheets - just my experience that it's easier to put all of the data into one place. -- John Mansfield http://cellmatrix.net "Rose" wrote: > I am trying to create a chart using data from multiple worksheets within one > workbook. D...

MFC extension dll initialization
I have MFC application, which uses several MFC extension dlls. For simplicity suppose their names are math.dll gdiext.dll and advancedGUI.dll. All this dlls are used in application. (MFC in shared dll and dlls are shared dll dynamically linked). But between dlls are dependencies. advancedGUI.dll uses gdiext.dll and math.dll, Guiext.dll uses math.dll. Do I have to initialize math.dll before first call from advancedGUI.dll is done and Guiext.dll. By initialization I mean this extern "C" extern void WINAPI InitXxxDLL() { new CDynLinkLibrary(extensionDLL); } I have read t...

OfficeQuestions looking for feedback and advice from Outlook users
Hi all, I am a long-time Outlook user and have used resources like Google and newsgroups for years to help find answers to my questions about many MS Office applications. My biggest frustration with using these types of resources was that it is cumbersome to sift through search engine results to find the answer I needed, and newsgroup threads make it difficult to pick out the best answer among all of the responses. So, I started a new site that I hope will serve the MS Office community by providing an inviting platform for asking and answering questions about MS Access, Excel, InfoPath and ...

Should write history for more than one HR change per day
Currently, Human Resources only allows writing a history record for one change per day per employee when the Enable Reason For Change is marked. If an employee changes departments and positions both in the same day, only one of the records will be written. It seems logical that multiple changes could happen for an employee in a day. Why not allow writing more than one history record per day? -- BrianB ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" but...

32 bit MFC app modify 64-bit registry hive
Hi all, we've got a 32 bit configuration problem which serves to configure the registry for our application which is composed of multiple executables. We've ported the intensive process of our application to 64bit. Now, in windows xp x64, there are different registry views for 32bit and 64-bit programs. Basically, for the part that concerns us, For example a 32 bit application trying to access HKEY_LOCAL_MACHINE\SOFTWARE\app\64bitprocess Will actually be redirected to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\app\64bitprocess This redirection does not take place for 64bit processes....