|
The code was offered as a way of showing all the fields that need to be filled in to achieve a working solution, cut / paste at your own peril.
I can't predict what a future OS might look like, nor can you. However, I do know that some old OS'es do not support the balloon so I do not attempt it there, the results are unpredictable.
Thanks for your comments
|
|
|
|
|
Finnaly I get the notify baloon with follow code :
BOOL CMainFrame::ShowNotifyBaloon(LPCTSTR lpszBalloonTitle, LPCTSTR lpszBalloonMsg, DWORD dwIcon, UINT nTimeOut)
{
ASSERT (dwIcon == NIIF_WARNING || dwIcon == NIIF_ERROR || dwIcon == NIIF_INFO || dwIcon == NIIF_NONE);
NOTIFYICONDATA nid;
memset(&nid,0,sizeof(nid));
nid.uID = 0;
nid.dwInfoFlags = dwIcon;
nid.hWnd = GetSafeHwnd();
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_INFO;
nid.uTimeout = nTimeOut;
nid.uCallbackMessage = WMU_TRAYNOTIFYICON;
::strcpy(nid.szInfoTitle,lpszBalloonTitle);
::strcpy(nid.szInfo,lpszBalloonMsg);
return ::Shell_NotifyIcon(NIM_MODIFY,&nid);
}
but still has a problem : when baloon show up, the systemtray icon dissapear !? Why ? I compile code with VC6 + SDK, and I try it on Win7.
|
|
|
|
|
I realize you had to make changes to my code but I don't think the .dwInfoFlags field is where you stick the dwIcon. And you don't fill in the .hIcon field in the structure so I'm not surprised that the icon disappears. Go back and check the code I posted
|
|
|
|
|
Lookup the definition of the flag NFI_ICON, it says:
NIF_ICON (0x00000002)
0x00000002. The hIcon member is valid.
but you didn't fill in the .hIcon field (well, memset() zeroed it).
Either give it an Icon handle in .hIcon or remove the NFI_ICON flag.
|
|
|
|
|
You are right, and it is good to avoid calling the function on OSes that are too old to support it. But we can reasonably assume that the code will work on future OSes, as has most always been the case with Windows (high level of backwards compatibility, via extended (FuncXyzEx) functions), so I was suggesting only setting a minimum.
When changing the compatibility setting for an executable to an older version of windows, the GetVersion API changes along to display the 'emulated' setting. The reason is does this is to 'fix' code that does version checks 'the wrong way' (restricting it from above. Such as applications for XP that stop working on Windows 7 because they only checked if major version was 5).
While searching for an article I once saw, I found this: VerifyVersionInfo Function[^] which does what we want for us.
|
|
|
|
|
Finally goes fine ... here is the code :
BOOL CMainFrame::ShowNotifyBaloon(LPCTSTR lpszBalloonTitle, LPCTSTR lpszBalloonMsg, DWORD dwIcon, UINT nTimeOut)
{
ASSERT(dwIcon == NIIF_WARNING || dwIcon == NIIF_ERROR || dwIcon == NIIF_INFO || dwIcon == NIIF_NONE);
NOTIFYICONDATA nid;
memset(&nid,0,sizeof(nid));
nid.uID = 0;
nid.dwInfoFlags = dwIcon;
nid.hWnd = GetSafeHwnd();
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_INFO;
nid.uTimeout = nTimeOut;
nid.hIcon = theApp.LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME));
nid.uCallbackMessage = WMU_TRAYNOTIFYICON;
::strcpy(nid.szInfoTitle,lpszBalloonTitle);
::strcpy(nid.szInfo,lpszBalloonMsg);
return ::Shell_NotifyIcon(NIM_MODIFY,&nid);
}
Thank you very much, for your kindness and patience !
|
|
|
|
|
Anytime. PS, if you found some of the answer useful, give them a good rating.
|
|
|
|
|
I am trying to debug a program that is having a strange issue. When I first build and run the program it saves an image file, but after a series of saves the program will suddenly have a windows exception thrown. The error is happening at this point in the code:
void CDlg_ScanAcq::OnPlaceData()
CString title;
title.Format("%06d.stm",theInst->m_Flags.ScanNumber);
strcat(pDoc->m_Header.FileName, title);
pDoc->SetTitle(title);
pDoc->m_Ready = true;
pDoc->SetModifiedFlag(true);
pDoc->ShowAllViews();
CWinSTMApp *theApp = (CWinSTMApp*)AfxGetApp();
CString path;
path = theApp->m_Default.SaveDir + title;
pDoc->SetPathName(path);
This leads me to the exception being thrown here
void CRecentFileList::Add(LPCTSTR lpszPathName, LPCTSTR lpszAppID)
{
if (!afxGlobalData.bIsWindows7)
{
Add(lpszPathName);
return;
}
CString strAppID = lpszAppID == NULL ? _T("") : lpszAppID;
#if (WINVER >= 0x0601)
ASSERT(AfxIsValidString(lpszPathName));
Add(lpszPathName);
HRESULT hr = S_OK;
CComPtr<IShellItem> psi = NULL;
#ifdef UNICODE
hr = afxGlobalData.ShellCreateItemFromParsingName(lpszPathName, NULL, IID_IShellItem, reinterpret_cast<void**>(&psi));
#else
{
USES_CONVERSION;
LPOLESTR lpWPath = A2W(lpszPathName);
hr = afxGlobalData.ShellCreateItemFromParsingName(lpWPath, NULL, IID_IShellItem, (LPVOID*)&psi);
}
#endif
ENSURE(SUCCEEDED(hr));
If I manually save the data, which is an image, then everything is fine...but this very inconvenient and I would like to find the reason the bug suddenly pops up. I can try to provide more information if anyone has an idea as to why this is happening. Thanks!
|
|
|
|
|
Hi Andrew,
You can probably get around the exception if you change:
pDoc->SetPathName(path);
to
pDoc->SetPathName(path,FALSE);
I believe the CDocument::SetPathName[^] function causes the CRecentFileList to call ShellCreateItemFromParsingName which ends up checking for the existence of the file. If you are actually using the MRU list then you will need to ensure that the file exists before calling SetPathName.
-House of Blues
|
|
|
|
|
Our team has the task of maintaining and developing new features for a very old application. There is no budget (and no hope we can ever convince management) to rewrite it from scratch, so the only feasible way to keep this beast running is to gradually rewrite only parts of it, just as I have done before, occasionally.
It isn't quite that easy though, because, as I learned the hard way, even when I thought I completely understood a part of the program, errors kept creeping up. Often much, much later than when I initially wrote the replacement, making it much harder for me to understand my original thought process, and why it didn't work.
So I need tests, and the only valid method of testing under these circumstances that I can think of are Unit Tests. The problem is - I never worked with Unit Tests, I only know of them through articles that mention them, and therefore I only have a vague understanding of what they are and how they are supposed to be done.
Now I need some guidance where to start: I did search for articles and information on the web, but unfortunately didn't find anything useful that doesn't already require a thorough understanding of Unit Tests to start with. Somehow there don't seem to be any introductory articles - or I'm too stupid to find them. If anyone knows a link, could you please share?
As for books, I know there are literally thousands out there - but that is also my problem: which of them would be the right one? Could you advise some good picks to help out an old, experienced programmer, who for some reason never picked up the art of unit-testing?
|
|
|
|
|
The idea of unit tests is to test the functionality of units, as opposed to whole systems. (I assume you've read the relevant Wikipedia page.)
It's not as widely talked about in relation to C++ as some other languages (notably Java, but also C# and 'new' dynamic languages like Python, Ruby and that ilk) because
a) there isn't an established practically-standard unit testing framework, and
b) the language does not support reflection.
You can roll your own little framework, or grab one of the many free ones available. See Exploring the C++ Unit Testing Framework Jungle for a decent run-down. At my current workplace we use Boost.Test, but I've used CppUnit in the past. They both work, but are clunky when compared with, say, NUnit for C#.
Now, the idea is to test a unit, so you have a separate test application that links in the unit(s) you want to test, and work to their public interfaces. It's usual to have a setup-test-teardown structure, as you might need to create mock objects to pass in, or otherwise set up an environment to run the test.
So next time you need to make a change to this old legacy application, you start with identifying what units/modules/classes you need to change, and then sit down and make a series of tests that test them. For it to be any use, you need to have a comprehensive test suite - if you test only the behaviour on one sanitised input your test has poor coverage.
You want to be sure that you exercise the whole module, and all execution paths. This means testing for failures, to make sure that bad inputs or invalid environment setups generate appropriate failures (exceptions or error return codes). Test the edge cases, test "obviously" bad calls (for instance all functions that take int parameters that are assumed to be always positive - what happens when you pass in -1?) and test unlikely (but possible) combinations of inputs.
So you make your tests, and you check that they pass. If they don't pass, you need to figure out if the test is poorly written, or if there is a bug in the unit.
If you were fixing a bug in the unit, write a test that exercises that bug. In other words, write a test that will fail with the existing code. That way, you can verify that you've fixed the bug, since the test should pass after you're done.
Oh, and something that's often left out of the list advice - presumably because the adivsors see it as self-evident - is that you shouldn't remove tests. This means that for every bug you find and fix, the list of tests should grow, as you write a test to prove there's a bug, and then proves you've fixed the bug. Only remove a test if an interface has changed so the call doesn't compile any more. If that happens, write a new test to replace it.
Hope this helps a bit
|
|
|
|
|
Thanks a ton for your time. I was aware of most of what you said, but as I picked up each individual piece of information from all kinds of different sources it's a great help for me to see it all in one cohesive writeup!
I like the title of the article you linked to and will definitely try to get a look at it, but first I'll have to convince the admin to unblock the site
I've heard about the 'clunkiness' of CppUnit and other tools, and that is one of the reasons I posted here: I didn't want to invest a lot of time to learn working with a tool as long as I don't even know what to expect and what everything is about - that kind of would be like learning to use a hammer without knowing what a nail is
I've already set up a little project to get a feel for it: it has two cpp files for each header file, one as a mockup and one for the real thing. That part was easy, but I already wonder if I could somehow automate it. Also I'm asking myself how to set up a framework that calls tests for more than one unit: If I replace one cpp file in the mock project, then I can only test that one unit; I need to create a new project for each test! Is that right?
|
|
|
|
|
Mocking isn't always necessary - it depends on the units you are testing. If they conform to the classic design ideals - low coupling, small interface, high cohesion - the lion's share of their function should be testable with no mock objects. But seeing such designs in real life, especially in old production apps, is quite rare.
A mockup is only needed if the unit you want to test is dependent on something that is expensive or impossible to provide in a simple test.
For instance, a self-contained unit that calculates income tax probably wouldn't need any mock objects.
namespace taxCalc
{
double calcIncomeTax(double annualIncome);
double calcIncomeTax(double annualIncome, double pensionDeduction);
...
}
void test_taxCalc()
{
std::cout << "Testing taxCalc::calcIncomeTax" << std::endl;
int passed = 0;
int tests = 4;
if (15.3 == calcIncomeTax(60.0))
++passed;
if (0 == calcIncomeTax(5.0))
++passed;
if (0 == calcIncomeTax(0.0))
++passed;
if (14.6 == calcIncomeTax(60.0, 4.0))
++passed;
std::cout << passed << " out of " << tests << " passed" << std::endl;
if (passed != tests)
std::cout << "There were errors" << std::endl;
}
int main()
{
test_taxCalc();
return 0;
}
There you go, a very simple unit test. As you see, there can be multiple tests in one function.
If you had a second unit in the system, to calculate national insurance or something, you can test that in the same test file, though it makes sense to write a separate test function for it.
Now, it could be that for hysterical reasons a simple function is dependent on something hugely expensive, like access to a corporate database with lots of security and whatnot. That's when you make a mock. Not of what you're testing, but of what the tested unit is dependent on.
class DataBaseTableFromFortKnox
{
public:
DataBaseTableFromFortKnox();
...
double GetCentsPerDollar() const;
...
};
namespace taxCalc
{
double calcIncomeTax(double annualIncome);
double calcIncomeTax(double annualIncome, double pensionDeduction);
double calcIncomeTaxInCents(double annualIncome, const DataBaseTableFromFortKnox& dbTab);
...
}
class DataBaseTableFromFortKnox
{
public:
DataBaseTableFromFortKnox()
{}
...
double GetCentsPerDollar() const
{
return 100.0;
}
};
void test_taxCalc()
{
...
}
void test_taxCalcDB()
{
DataBaseTableFromFortKnox db;
std::cout << "Testing taxCalc::calcIncomeTax with mock DB connection" << std::endl;
int passed = 0;
int tests = 4;
if (1530.0 == calcIncomeTax(60.0, db))
++passed;
...
In this case, you must make sure that you link to the mock rather than the real thing.
In one of the projects I'm managing where I work, there's a DLL that's dependent on some libs from other departments. For that project, I have two unit test projects - one where I've replaced the other libs with stub libs, and one where it's built with the proper libs. The first tests the internal logic of the DLL, making sure that the correct libs are called for the various inputs. Only when that test project runs successfully do I need to run the other, which is calling into the other libs (which takes a few minutes to initialise and close down).
|
|
|
|
|
Cool Cow Orjan wrote: low coupling, small interface, high cohesion
You guessed it: yes, 95% of our application is everything but that. Much of it is 'objectified C', stuff like structs renamed to class, but with everything staying on the public interface because it's being referenced in thousands of places. And that, exactly is the problem: everyone references everything, or in other words, calling our 'interfaces' huge might be an understatement.
I know I will eventually have to face that, but before I do I wish to start small to get a hang of Unit Tests. What I'll start with is the libraries I wrote myself, beginning with one I've just started implementing. At least here I know exactly where it's referenced (nowhere so far), and what it is supposed to achieve.
I've just seen your followup post. Thanks for the tip, yes I will be in need of good documentation, so I might just as well look into boost.
|
|
|
|
|
Also: one purpose of unit test frameworks is to aid with reporting and result checking, keeping track of how may tests you have, trapping expected exceptions and so on.
I'd recommend Boost, if only because it's got the best documentation of the frameworks I've looked at. It's using lots of macros, which isn't to everybody's taste, but it's quite straightforward to use.
|
|
|
|
|
Hi Developers,
I want to draw text(number of recorded symptoms) at OnPaint()
This is a Dialog Bar in which i have handled OnPaint() as well.
Here the code:
CString strClipCount;
CRect rcClipBoard;
m_stClipMind.GetWindowRect( rcClipBoard );
ScreenToClient(rcClipBoard);
strClipCount.Format( _T("%3d"), theApp.m_MentalClipbrd.GetCount() );
CPaintDC paintDC(this);
paintDC.Rectangle(rcClipBoard);
//COLORREF color = paintDC.SetBkColor(RGB(255,255,255));
paintDC.SelectObject(theApp.pCtrlFont);
paintDC.SetTextColor(RGB(0,0,0));
paintDC.TextOut( rcClipBoard.left, rcClipBoard.top, strClipCount, strlen(strClipCount) );
The problem is that the painting is not getting properly i.e. Whenever a msg box get shown at click of it's OK button it display the text for a while & after that it gets disappeared.
Can anyone help me out.
Thanks.
Amrit Agrawal
Software Developer
|
|
|
|
|
Use Invalidate () to make the framework invoke your OnPaint handler to update the screen.
|
|
|
|
|
If I understood you correctly, the m_stClipMind is a place holder CStatic?
If so, the problem is after your paint on the rect, when m_stClipMind refresh itself, your text will get erased.
two way to fix:
1) remove the WS_VISIBLE style for the m_stClipMind
2) using m_stClipMind.SetWindowText
|
|
|
|
|
Thanks my friend,
Now it's getting properly painted. Can you help me at one more issue.
There is some other windows in which symptoms of a patient is listed. If I am double clicked on any symptom, on the respective clipboard the count should be updated. The clip board is a dialog bar.
In that dialog bar in OnPaint() is am painting that count on the area of static text (so it will be update on the fly).
After recording a symptom it is not getting painted that count, but if Invalidate() get called implicitly, like switched to another window. the count get updated( painted ).
How can I invalidate that dialog bar from other window.
Thanks In Advance.
Amrit Agrawal
Software Developer
|
|
|
|
|
After you create the dialog bar, try to passing its window handle to other window.
and when update needed, in the other window, call InvalidateRect(hWndDialogBar
|
|
|
|
|
[]&<
<big></big>
<pre>
/*===============================================================================================================================
Thorlabs Wavefront Sensor sample application
This sample program for Wavefront Sensor instruments connects to a selected instrument,
configures it, takes some measurment and displays the results.
Finally it closes the connection.
Source file 'sample.c'
Date: Dec-04-2009
Software-Nr: N/A
Version: 1.0
Copyright: Copyright(c) 2009, Thorlabs GmbH (www.thorlabs.com)
Author: Egbert Krause (ekrause@thorlabs.com)
Changelog: Dec-04-2009 -> V1.0
Disclaimer:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
===============================================================================================================================*/
/*===============================================================================================================================
Include Files
Note: You may need to set your compilers include search path to the VXIPNP include directory.
This is typically 'C:\VXIPNP\WinNT\include'.
===============================================================================================================================*/
#include "wfs_drv.h" // Wavefront Sensor driver's header file
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*===============================================================================================================================
Defines
===============================================================================================================================*/
// settings for this sample program, you may adapt settings to ypur preferences
#define OPTION_OFF 0
#define OPTION_ON 1
#define SAMPLE_PIXEL_FORMAT PIXEL_FORMAT_MONO8 // only 8 bit format is supported
#define SAMPLE_CAMERA_RESOLUTION CAM_RES_768 // see wfs_drv for alternative cam resolutions
#define SAMPLE_REF_PLANE WFS_REF_INTERNAL
#define SAMPLE_PUPIL_CENTROID_X (0.0) // in mm
#define SAMPLE_PUPIL_CENTROID_Y (0.0)
#define SAMPLE_PUPIL_DIAMETER_X (2.0) // in mm, needs to fit to selected camera resolution
#define SAMPLE_PUPIL_DIAMETER_Y (2.0)
#define SAMPLE_IMAGE_READINGS (10) // trials to read a exposed spotfield image
#define SAMPLE_OPTION_DYN_NOISE_CUT OPTION_ON // use dynamic noise cut features
#define SAMPLE_OPTION_CALC_SPOT_DIAS OPTION_OFF // don't calculate spot diameters
#define SAMPLE_OPTION_CANCEL_TILT OPTION_ON // cancel average wavefront tip and tilt
#define SAMPLE_OPTION_LIMIT_TO_PUPIL OPTION_OFF // don't limit wavefront calculation to pupil interior
#define SAMPLE_WAVEFRONT_TYPE WAVEFRONT_MEAS // calculate measured wavefront
#define SAMPLE_ZERNIKE_ORDERS (3) // calculate up to 3rd Zernike order
#define SAMPLE_PRINTOUT_SPOTS (5) // printout results for first 5 x 5 spots only
/*===============================================================================================================================
Data type definitions
===============================================================================================================================*/
typedef struct
{
int selected_id;
int handle;
int status;
char version_wfs_driver[WFS_BUFFER_SIZE];
char version_cam_driver[WFS_BUFFER_SIZE];
char manufacturer_name[WFS_BUFFER_SIZE];
char instrument_name[WFS_BUFFER_SIZE];
char serial_number_wfs[WFS_BUFFER_SIZE];
char serial_number_cam[WFS_BUFFER_SIZE];
int mla_cnt;
int selected_mla;
int selected_mla_idx;
char mla_name[WFS_BUFFER_SIZE];
double cam_pitch_um;
double lenslet_pitch_um;
double center_spot_offset_x;
double center_spot_offset_y;
double lenslet_f_um;
double grd_corr_0;
double grd_corr_45;
int spots_x;
int spots_y;
} instr_t;
/*===============================================================================================================================
Function Prototypes
===============================================================================================================================*/
void handle_errors (int);
int select_instrument (int *selection);
int select_mla (int *selection);
/*===============================================================================================================================
Global Variables
===============================================================================================================================*/
const int cam_xpixel[] = { 1280, 1024, 768, 512, 320 };
const int cam_ypixel[] = { 1024, 1024, 768, 512, 320 };
const int zernike_modes[] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66 }; // converts Zernike order to Zernike modes
instr_t instr = { 0 }; // all instrument related data are stored in this structure
/*===============================================================================================================================
Code
===============================================================================================================================*/
void main (void)
{
int err;
int i,j,cnt;
int rows, cols; // image height and width, depending on camera resolution
unsigned char *ImageBuffer; // pointer to the camera image buffer
double expos_act, master_gain_act;
double beam_centroid_x, beam_centroid_y;
double beam_diameter_x, beam_diameter_y;
float centroid_x[MAX_SPOTS_Y][MAX_SPOTS_X];
float centroid_y[MAX_SPOTS_Y][MAX_SPOTS_X];
float deviation_x[MAX_SPOTS_Y][MAX_SPOTS_X];
float deviation_y[MAX_SPOTS_Y][MAX_SPOTS_X];
float wavefront[MAX_SPOTS_Y][MAX_SPOTS_X];
float zernike_um[MAX_ZERNIKE_MODES+1]; // index runs from 1 - MAX_ZERNIKE_MODES
float zernike_orders_rms_um[MAX_ZERNIKE_ORDERS+1]; // index runs from 1 - MAX_ZERNIKE_MODES
double roc_mm;
int zernike_order;
double wavefront_min, wavefront_max, wavefront_diff, wavefront_mean, wavefront_rms, wavefront_weighted_rms;
printf("This is a Thorlabs Wavefront Sensor sample application.\n\n");
// Get the driver revision
if(err = WFS_RevisionQuery (NULL, instr.version_wfs_driver, instr.version_cam_driver)) // pass NULL because handle is not yet initialized
handle_errors(err);
printf("Camera USB driver version : %s\n", instr.version_cam_driver);
printf("WFS instrument driver version : %s\n\n", instr.version_wfs_driver);
// Show all and select one WFS instrument
if(select_instrument(&instr.selected_id) == 0)
{
printf("\nNo instrument selected. Press <enter> to exit.\n");
fflush(stdin);
getchar();
return; // program ends here if no instrument selected
}
// Open the Wavefront Sensor instrument
if(err = WFS_init (instr.selected_id, &instr.handle))
handle_errors(err);
// Get instrument information
if(err = WFS_GetInstrumentInfo (instr.handle, instr.manufacturer_name, instr.instrument_name, instr.serial_number_wfs, instr.serial_number_cam))
handle_errors(err);
printf("\n");
printf("Opened Instrument:\n");
printf("Manufacturer : %s\n", instr.manufacturer_name);
printf("Instrument Name : %s\n", instr.instrument_name);
printf("Serial Number WFS : %s\n", instr.serial_number_wfs);
// Select a microlens array (MLA)
if(select_mla(&instr.selected_mla) < 0)
{
printf("\nNo MLA selected. Press <enter> to exit.\n");
fflush(stdin); ////清除文件缓冲区
getchar();
return;
}
// Activate desired MLA
if(err = WFS_SelectMla (instr.handle, instr.selected_mla))
handle_errors(err);
// Configure WFS camera, use a pre-defined camera resolution
printf("\n\nConfigure WFS camera with resolution index %d (%d x %d pixels).\n", SAMPLE_CAMERA_RESOLUTION, cam_xpixel[SAMPLE_CAMERA_RESOLUTION], cam_ypixel[SAMPLE_CAMERA_RESOLUTION]);
if(err = WFS_ConfigureCam (instr.handle, SAMPLE_PIXEL_FORMAT, SAMPLE_CAMERA_RESOLUTION, &instr.spots_x, &instr.spots_y))
handle_errors(err);
printf("Camera is configured to detect %d x %d lenslet spots.\n\n", instr.spots_x, instr.spots_y);
// set camera exposure time and gain if you don't want to use auto exposure
// use functions WFS_GetExposureTimeRange, WFS_SetExposureTime, WFS_GetMasterGainRange, WFS_SetMasterGain
// set WFS internal reference plane
printf("\nSet WFS to internal reference plane.\n");
if(err = WFS_SetReferencePlane (instr.handle, SAMPLE_REF_PLANE))
handle_errors(err);
// define pupil
printf("\nDefine pupil to:\n");
printf("Centroid_x = %6.3f\n", SAMPLE_PUPIL_CENTROID_X);
printf("Centroid_y = %6.3f\n", SAMPLE_PUPIL_CENTROID_Y);
printf("Diameter_x = %6.3f\n", SAMPLE_PUPIL_DIAMETER_X);
printf("Diameter_y = %6.3f\n", SAMPLE_PUPIL_DIAMETER_Y);
if(err = WFS_SetPupil (instr.handle, SAMPLE_PUPIL_CENTROID_X, SAMPLE_PUPIL_CENTROID_Y, SAMPLE_PUPIL_DIAMETER_X, SAMPLE_PUPIL_DIAMETER_Y))
handle_errors(err);
printf("\nRead camera images:\n");
printf("Image No. Status -> newExposure[ms] newGainFactor\n");
// do some trials to read a well exposed image
for(cnt = 0; cnt < SAMPLE_IMAGE_READINGS; cnt++)
{
// take a camera image with auto exposure, note that there may several function calls required to get an optimal exposed image
if(err = WFS_TakeSpotfieldImageAutoExpos (instr.handle, &expos_act, &master_gain_act))
handle_errors(err);
printf(" %d ", cnt);
// check instrument status for non-optimal image exposure
if(err = WFS_GetStatus (instr.handle, &instr.status))
handle_errors(err);
if(instr.status & WFS_STATBIT_PTH) printf("Power too high! ");
else
if(instr.status & WFS_STATBIT_PTL) printf("Power too low! ");
else
if(instr.status & WFS_STATBIT_HAL) printf("High ambient light!");
else
printf( "OK ");
printf(" %6.3f %6.3f\n", expos_act, master_gain_act);
if( !(instr.status & WFS_STATBIT_PTH) && !(instr.status & WFS_STATBIT_PTL) && !(instr.status & WFS_STATBIT_HAL) )
break; // image well exposed and is usable
}
// close program if no well exposed image is feasible
if( (instr.status & WFS_STATBIT_PTH) || (instr.status & WFS_STATBIT_PTL) ||(instr.status & WFS_STATBIT_HAL) )
{
printf("\nSample program will be closed because of unusable image quality, press <enter>.");
WFS_close(instr.handle); // required to release allocated driver data
fflush(stdin);
getchar();
exit(1);
}
// get last image (only required to display the image)
if(err = WFS_GetSpotfieldImage (instr.handle, &ImageBuffer, &rows, &cols))
handle_errors(err);
// get centroid and diameter of the optical beam, you may use this beam data to define a pupil variable in position and size
if(err = WFS_CalcBeamCentroidDia (instr.handle, &beam_centroid_x, &beam_centroid_y, &beam_diameter_x, &beam_diameter_y))
handle_errors(err);
printf("\nInput beam is measured to:\n");
printf("Centroid_x = %6.3f mm\n", beam_centroid_x);
printf("Centroid_y = %6.3f mm\n", beam_centroid_y);
printf("Diameter_x = %6.3f mm\n", beam_diameter_x);
printf("Diameter_y = %6.3f mm\n", beam_diameter_y);
fflush(stdin);
printf("\nPress <enter> to proceed...");
getchar();
// calculate all spot centroid positions using dynamic noise cut option
if(err = WFS_CalcSpotsCentrDiaIntens (instr.handle, SAMPLE_OPTION_DYN_NOISE_CUT, SAMPLE_OPTION_CALC_SPOT_DIAS))
handle_errors(err);
// get centroid result arrays
if(err = WFS_GetSpotCentroids (instr.handle, *centroid_x, *centroid_y))
handle_errors(err);
// print out some centroid positions
printf("\nCentroid X Positions in pixels (first 5x5 elements)\n");
for(i=0;i<sample_printout_spots;i++)>
{
for(j=0;j<sample_printout_spots;j++)>
printf(" %8.3f", centroid_x[i][j]);
printf("\n");
}
printf("\nCentroid Y Positions in pixels (first 5x5 elements)\n");
for(i=0;i<sample_printout_spots;i++)>
{
for(j=0;j<sample_printout_spots;j++)>
printf(" %8.3f", centroid_y[i][j]);
printf("\n");
}
printf("\nPress <enter> to proceed...");
getchar();
// calculate spot deviations to internal reference
if(err = WFS_CalcSpotToReferenceDeviations (instr.handle, SAMPLE_OPTION_CANCEL_TILT))
handle_errors(err);
// get spot deviations
if(WFS_GetSpotDeviations (instr.handle, *deviation_x, *deviation_y))
handle_errors(err);
// print out some spot deviations
printf("\nSpot Deviation X in pixels (first 5x5 elements)\n");
for(i=0;i<sample_printout_spots;i++)>
{
for(j=0;j<sample_printout_spots;j++)>
printf(" %8.3f", deviation_x[i][j]);
printf("\n");
}
printf("\nSpot Deviation Y in pixels (first 5x5 elements)\n");
for(i=0;i<sample_printout_spots;i++)>
{
for(j=0;j<sample_printout_spots;j++)>
printf(" %8.3f", deviation_y[i][j]);
printf("\n");
}
printf("\nPress <enter> to proceed...");
getchar();
// calculate and printout measured wavefront
if(err = WFS_CalcWavefront (instr.handle, SAMPLE_WAVEFRONT_TYPE, SAMPLE_OPTION_LIMIT_TO_PUPIL, *wavefront))
handle_errors(err);
// print out some wavefront points
printf("\nWavefront in microns (first 5x5 elements)\n");
for(i=0;i<sample_printout_spots;i++)>
{
for(j=0;j<sample_printout_spots;j++)>
printf(" %8.3f", wavefront[i][j]);
printf("\n");
}
printf("\nPress <enter> to proceed...");
getchar();
// calculate wavefront statistics within defined pupil
if(err = WFS_CalcWavefrontStatistics (instr.handle, &wavefront_min, &wavefront_max, &wavefront_diff, &wavefront_mean, &wavefront_rms, &wavefront_weighted_rms))
handle_errors(err);
printf("\nWavefront Statistics in microns:\n");
printf("Min : %8.3f\n", wavefront_min);
printf("Max : %8.3f\n", wavefront_max);
printf("Diff : %8.3f\n", wavefront_diff);
printf("Mean : %8.3f\n", wavefront_mean);
printf("RMS : %8.3f\n", wavefront_rms);
printf("Weigthed RMS : %8.3f\n", wavefront_weighted_rms);
printf("\nPress <enter> to proceed...");
getchar();
// calculate Zernike coefficients
printf("\nZernike fit up to order %d:\n",SAMPLE_ZERNIKE_ORDERS);
zernike_order = SAMPLE_ZERNIKE_ORDERS; // pass 0 to function for auto Zernike order, choosen order is returned
if(err = WFS_ZernikeLsf (instr.handle, &zernike_order, zernike_um, zernike_orders_rms_um, &roc_mm)) // calculates also deviation from centroid data for wavefront integration
handle_errors(err);
printf("\nZernike Mode Coefficient\n");
for(i=0; i < zernike_modes[SAMPLE_ZERNIKE_ORDERS]; i++)
{
printf(" %2d %9.3f\n",i, zernike_um[i]);
}
printf("\nEnd of Sample Program, press <enter> to exit\n");
fflush(stdin);
getchar();
// Close instrument, important to release allocated driver data!
WFS_close(instr.handle);
}
/*===============================================================================================================================
Handle Errors
This function retrieves the appropriate text to the given error number and closes the connection in case of an error
===============================================================================================================================*/
void handle_errors (int err)
{
char buf[WFS_ERR_DESCR_BUFFER_SIZE];
if(!err) return;
// Get error string
WFS_ErrorMessage (instr.handle, err, buf);
if(err < 0) // errors
{
printf("\nWavefront Sensor Error: %s\n", buf);
// close instrument after an error has occured
printf("Sample program will be closed because of the occured error, press <enter>.");
WFS_close(instr.handle); // required to release allocated driver data
fflush(stdin);
getchar();
exit(1);
}
}
/*===============================================================================================================================
Select Instrument
===============================================================================================================================*/
int select_instrument (int *selection)
{
int i,err,instr_cnt;
int device_id;
int in_use;
char instr_name[WFS_BUFFER_SIZE];
char serNr[WFS_BUFFER_SIZE];
// Find available instruments
if(err = WFS_GetInstrumentListLen (&instr_cnt))
handle_errors(err);
if(instr_cnt == 0)
{
printf("No Wavefront Sensor instrument found!\n");
return 0;
}
// List available instruments
printf("Available Wavefront sensor instruments:\n\n");
for(i=0;i<instr_cnt;i++)>
{
if(err = WFS_GetInstrumentListInfo (i, &device_id, &in_use, instr_name, serNr))
handle_errors(err);
printf("%2d %s %s %s\n", device_id, instr_name, serNr, (!in_use) ? "" : "(inUse)");
}
// Select instrument
printf("\nSelect a Wavefront Sensor instrument: ");
fflush(stdin);
*selection = getchar() - '0';
if(*selection < 0)
*selection = 0; // nothing selected
return *selection;
}
/*===============================================================================================================================
Select MLA
===============================================================================================================================*/
int select_mla (int *selection)
{
int i,err,mla_cnt;
// Read out number of available Microlens Arrays
if(err = WFS_GetMlaCount (instr.handle, &instr.mla_cnt))
handle_errors(err);
// List available Microlens Arrays
printf("\nAvailable Microlens Arrays:\n\n");
for(i=0;i<instr.mla_cnt;i++)>
{
if(WFS_GetMlaData (instr.handle, i, instr.mla_name, &instr.cam_pitch_um, &instr.lenslet_pitch_um, &instr.center_spot_offset_x, &instr.center_spot_offset_y, &instr.lenslet_f_um, &instr.grd_corr_0, &instr.grd_corr_45))
handle_errors(err);
printf("%2d %s CamPitch=%6.3f LensletPitch=%8.3f\n", i, instr.mla_name, instr.cam_pitch_um, instr.lenslet_pitch_um);
}
// Select MLA
printf("\nSelect a Microlens Array: ");
fflush(stdin);
*selection = getchar() - '0';
if(*selection < -1)
*selection = -1; // nothing selected
return *selection;
}
/*===============================================================================================================================
End of source file
===============================================================================================================================*/
|
|
|
|
|
How to learn C++ in depth. can you prefer any book or website to learn all concepts in brief with an example. kindly guide me to become good programmer.
modified on Wednesday, August 31, 2011 12:41 AM
|
|
|
|
|
Have you looked here?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
|
that's a pretty good website, I still use it for reference from time to time...
|
|
|
|
|