|
Hi there,
I don't want to seem pedantic, though I will point out that this is not actually system error 0x0000007B, but rather the error-code of the last system function that failed. A system error is one generally regarded as having been generated by Windows itself (rather than just a 'helper' function)
Something that you may choose to do which certainly clarifies the error is to display a description of the error.
Have a look over here, for a method by which the code 0x7B may be turned into a text message.
|
|
|
|
|
The error message is (you can check it in WinError.h )
What library are you using?
Veni, vidi, vici.
|
|
|
|
|
basically i have the console program running fine (means having source file and header files). than i wanted to build GUI for this using MFC in vs2008. now i don't understand how to open serial port in MFC. code below shows how to open serial port in console programming using cmd prompt.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}
set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName);
if ( COMstream == PORT_NOT_OPENED )
{ printf("\nSerial Port setup error.\n");
goto abnormal_exit; }
printf("\nSerial port %s initialized\n", COMportName);
|
|
|
|
|
jawadali477 wrote: COMstream = open_host_port(COMportName);
I would use the debugger to watch COMportName content in both console and MFC applications.
Veni, vidi, vici.
|
|
|
|
|
console program is running fine. problem is in MFC program. can you tell how to implement the console program, as mentioned, in MFC??
|
|
|
|
|
What a mix up of different naming conventions!
|
|
|
|
|
As CPallini pointed out
CPallini wrote: The error message is (you can check it in WinError.h )
Are you sure COM3 exists on your machine?
Did you try the format \\.\COM3 instead?
What happens in set_baud_rate() and in open_host_port()? You have to open the COM-Port before changing the baudrate
Cou can find some more hints on serial communication here:
Communications Resources[^]
[Edit]corrected spelling of memeber name [/Edit]
modified 15-May-12 5:16am.
|
|
|
|
|
Andy411 wrote: JPalini
Veni, vidi, vici.
|
|
|
|
|
Oooouuuuuuch
Sorry, I just corrected it. Sometimes I don't have any control on what my fingers are doing with the keyboard
|
|
|
|
|
yes COM3 is available and i have tried \\.COM3 and \\\\.\\COM3 both. basically i'm developing GUI via MFC in vs2008 for my console program. part of the code for opening serial port in console program is given below. i can't understand how to do it in MFC.
COMportName[0] = ' ';
while (COMportName[0] == ' ') {
printf("\nEnter the %s port number the PTU is attached to: ", COMportPrefix);
scanf("%d", &COMportNum);
printf("You selected %s%d. Is this OK? (enter 'y' or 'n'): ", COMportPrefix, COMportNum);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
if ( tmpChar == 'y' )
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
}
tmpChar = 'f';
while (tmpChar != 'y') {
printf("\nEnter the baud rate the ptu is communicate at (default: 9600): ");
scanf("%d", &BaudRate);
printf("You selected %d. Is this OK? (enter 'y' or 'n'): ", BaudRate);
tmpChar = 'f';
while ( (tmpChar != 'y') && (tmpChar != 'n') )
tmpChar = ((char) tolower(getchar()));
}
set_baud_rate(BaudRate);
COMstream = open_host_port(COMportName);
if ( COMstream == PORT_NOT_OPENED )
{ printf("\nSerial Port setup error.\n");
goto abnormal_exit; }
printf("\nSerial port %s initialized\n", COMportName);
|
|
|
|
|
Does the console programm run?
And what's the code inside open_host_port()?
Did you step through the code of open_host_port() in the debugger? Examine every return code of Win32 API-calls and check GetLastError().
What happens, if you just do a call to the CreateFile-function to open the COM-port, just like in this article
Creating a Serial communication on Win32[^]
I dont't think that this is an MFC problem,
|
|
|
|
|
Andy411 wrote: I dont't think that this is an MFC problem, I agree.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
jawadali477 wrote: char COMportPrefix[10] = "COM";
char COMportName[256];
sprintf(COMportName, "%s%d", COMportPrefix, COMportNum);
strng = CString(COMportName);
strng.Format(_T("%0.9s"), strng);
SetDlgItemText(IDC_STAT, strng); I'm thinking you could eliminate some overhead here. Try:
strng.Format(_T("COM%d"), COMportNum); Note that this likely has nothing to do with why open_host_port() is not opening the port.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I do not recognize the open_host_port function, but it does not really matter. On some systems you need to add a ':' after COMx. Try sprintf(COMportName, "%s%d:", COMportPrefix, COMportNum); to get COM3:
Cheers,
Henryk
|
|
|
|
|
i did what you suggested and now the error comes out to be 00000002 (i.e The system cannot find the file specified). and the outcome of
SetDlgItemText(IDC_STAT, strng);
is "COM3:".
|
|
|
|
|
OK, so this means you fixed one problem (I think), but now came up against another. I believe 7B meant that command format was wrong that is why I was suggesting the ':' the 2 means that system cannot find COM3. Are you sure that it exists. On a Windows PC you'd look in device manager. If it really exists then 7B probably means something else.
That is about all I can help.
Henryk
|
|
|
|
|
hello guys... how do I respond to an asynchronous function call? Let's say that I have a function (asynchronous, boolean) like this
classObject->Function_Call();
Now I want to do something like this
BOOL bResult = FALSE;
bResult = classObject->Function_Call();
if(bResult)
{
}
else
Now what do I do in this situation as Function_Call() is asynchronous? Thanks for any input.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
The short answer is: you cannot do that.
When the function is asynchronous you may usually perform a test like that only to know whether the function was called properly (it might fail, for instance, if classObject was not properly initialized). To know the result of the actual function execution you should check that a state change happened, but that is specific of the function (for instance asynchrounous I/O Windows API provide GetOverallappedResult function) and there is no general way.
Veni, vidi, vici.
|
|
|
|
|
Let me address this in simpler terms without any context to the OS.
When you say "Async" , the control passes through. In your example, there is no point in waiting to check "bResult". Typically an Async function is attached with a callback function - a function pointer to notify when the operation has been completed.
Or you'll attach a Windows Handle (windows) so that the Async function can post updates to the function through messages.
So you need to figure out how your function_call() is implemented to let the main thread (for example- main()) know the completion of the function.
|
|
|
|
|
Sounds like you need a multithreaded application. With one thread set up to wait for the call while another is doing the normal processing. On the other hand it kind of depends on what you mean by asynchronous. Windows message pump is is another example of managing asynchronous events.
Cheers,
Henryk
|
|
|
|
|
Then you have to wait until you get the result and then decide how to continue.
|
|
|
|
|
I must be doing something really stupid, but... I cannot get any of the changes to my menu items reflected in visual appearance. If I check a menu item, or change string I can see changes if I test in code, but not when I click on the menu bar.
I use standard default bar creation in main frame OnCreate:
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
if (!m_wndMenuBar.Create(this))
{
TRACE0("Failed to create menubar\n");
return -1; }
m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
I then create a menu message handler in a view and in it I put something like this:
MENUITEMINFO info;
TCHAR buf[32];
info.cbSize=sizeof(MENUITEMINFO);
info.fMask=MIIM_STATE|MIIM_ID|MIIM_STRING;
info.fType=MFT_STRING;
info.dwTypeData=0;
HMENU hMenusafe= ((CMainFrame*)(AfxGetApp()->m_pMainWnd))->m_wndMenuBar.GetHMenu();
HMENU hMenu=::GetSubMenu(hMenusafe,0);
DWORD err=GetLastError();
int er=GetMenuItemInfo(hMenu,3,1,&info);
err=GetLastError();
info.cch++;
if( info.cch > 32)
info.cch = 32;
info.dwTypeData=buf;
er=GetMenuItemInfo(hMenu,3,1,&info);
err=GetLastError();
if(info.fState & MFS_CHECKED)
{
info.fState &=~MFS_CHECKED;
info.fState|=MFS_UNCHECKED;
_tcscpy(buf,_T("Menu is unchecked"));
info.cch=_tcslen(buf)+1;
}
else
{
info.fState &=~MFS_UNCHECKED;
info.fState |=MFS_CHECKED;
_tcscpy(buf,_T("Menu is checked"));
info.cch=_tcslen(buf)+1;
}
er=SetMenuItemInfo(hMenu,3,1,&info);
((CMainFrame*)(AfxGetApp()->m_pMainWnd))->DrawMenuBar();
As I click on the menu item I never see a check, nor changed text. However as I am stepping through the code debugging, I see that changes did take place. What am I doing wrong?
Any help appreciated
Henryk
|
|
|
|
|
|
Thanks! that works. I guess it is another disconnect in MFC .
|
|
|
|
|
I can detect the 120 mode, now I to decide how to handle large fonts
Should I use the paint, and resize all the controls?
|
|
|
|