|
hi i want to calculate execution time of the function
how should i go about it ?
is it possible (as it is done in winrunner)
Also if i have to calculate logical time(by calculatin frequencies of statements) which algorithm should i use
plz help
sagar
love is photogenic, it requires a dark to develope
|
|
|
|
|
You can use GetTickCount function to retrieve the number of miliseconds elapsed.
|
|
|
|
|
Main Menue->Build->Profile...
It should point you in the right direction for profiling. You'll need to lookup the details in the MSDN.
Lookup QueryPerformanceFrequency().
There is also the multi-media timers.
There is also also a timer class article at CP (call CDurration, I think).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
No what i want is an application which calculates execution time of other codes
e.g.
Input to my application will be abc.c
abc.c contains 5 functions
then my output sould be execution tim of these 5 functions
as done in winrunner
Is it possible
plz help
Sagar
Love Is photogenic,It require a dark to develope
|
|
|
|
|
I use WMI to set Ip Address for my local computer.
every function works well. but nothing changed.
Why?? I use vc6,xp OS. For some header files,you can found them from vc7, just copy them to the Include directory for vc6.
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
for a test,the above line must be modified.replace "MyComputerName" with your own computer name.
I paste all the code here. A win32 console app.
Thank you everyone.
#define _WIN32_DCOM
#include
#pragma comment(lib,"Wbemuuid.lib")
#include
//#include "wbemcli.h"
#include "objbase.h"
#include
#include
#pragma comment(lib, "comsupp.lib")
void CreateOneElementBstrArray(VARIANT* v, LPCWSTR s)
{
SAFEARRAYBOUND bound[1];
SAFEARRAY* array;
bound[0].lLbound = 0;
bound[0].cElements = 1;
array = SafeArrayCreate(VT_BSTR, 1, bound);
long index = 0;
BSTR bstr = SysAllocString(s);
SafeArrayPutElement(array, &index, bstr);
SysFreeString(bstr);
VariantInit(v);
v->vt = VT_BSTR | VT_ARRAY;
v->parray = array;
}
HRESULT __fastcall UnicodeToAnsi(LPCOLESTR pszW, LPSTR* ppszA)
{
ULONG cbAnsi, cCharacters;
DWORD dwError;
// If input is null then just return the same.
if (pszW == NULL)
{
*ppszA = NULL;
return NOERROR;
}
cCharacters = wcslen(pszW)+1;
// Determine number of bytes to be allocated for ANSI string. An
// ANSI string can have at most 2 bytes per character (for Double
// Byte Character Strings.)
cbAnsi = cCharacters*2;
// Use of the OLE allocator is not required because the resultant
// ANSI string will never be passed to another COM component. You
// can use your own allocator.
*ppszA = (LPSTR) CoTaskMemAlloc(cbAnsi);
if (NULL == *ppszA)
return E_OUTOFMEMORY;
// Convert to ANSI.
if (0 == WideCharToMultiByte(CP_ACP, 0, pszW, cCharacters, *ppszA,
cbAnsi, NULL, NULL))
{
dwError = GetLastError();
CoTaskMemFree(*ppszA);
*ppszA = NULL;
return HRESULT_FROM_WIN32(dwError);
}
return NOERROR;
}
void PrintWMIError(HRESULT hr)
{
IWbemStatusCodeText * pStatus = NULL;
HRESULT hres = CoCreateInstance(CLSID_WbemStatusCodeText, 0,
CLSCTX_INPROC_SERVER,IID_IWbemStatusCodeText, (LPVOID *) &pStatus);
if(S_OK == hres)
{
BSTR bstrError;
hres = pStatus->GetErrorCodeText(hr, 0, 0, &bstrError);
if(S_OK != hres)
bstrError = SysAllocString(L"Get last error failed");
LPSTR pszStatusTextA;
UnicodeToAnsi(bstrError, &pszStatusTextA);
printf("%s\n",pszStatusTextA);
CoTaskMemFree(pszStatusTextA);
pStatus->Release();
SysFreeString(bstrError);
}
}
HRESULT ConfigNet()
{
IWbemLocator *pLocator=NULL;
IWbemServices *pNamespace=NULL;
IWbemClassObject *pClass=NULL;
IWbemClassObject *pInputParamClass=NULL;
IWbemClassObject *pInputParamInstance=NULL;
IWbemClassObject * pOutInst = NULL;
BSTR InstancePath = SysAllocString(L"Win32_NetworkAdapterConfiguration=2");
HRESULT hr;
BSTR Path = SysAllocString(L"\\\\MyComputerName\\root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetworkAdapterConfiguration");
BSTR MethodName = SysAllocString(L"EnableStatic");
LPCWSTR Arg1Name = L"IPAddress";
VARIANT var1;
LPCWSTR Arg2Name = L"SubnetMask";
VARIANT var2;
__try
{
CreateOneElementBstrArray(&var1, L"10.0.0.101");
CreateOneElementBstrArray(&var2, L"255.255.255.0");
CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID*)&pLocator);
hr = pLocator->ConnectServer(Path,NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
hr = CoSetProxyBlanket( pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pClass->GetMethod(MethodName, 0, &pInputParamClass, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamClass->SpawnInstance(0, &pInputParamInstance);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg1Name, 0, &var1, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pInputParamInstance->Put(Arg2Name, 0, &var2, 0);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
if(SUCCEEDED(hr))
{
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL,
pInputParamInstance, &pOutInst, NULL);
}
if(!SUCCEEDED(hr))
{
PrintWMIError(hr);
return hr;
}
}
__finally
{
if(pInputParamInstance)
pInputParamInstance->Release();
if(pInputParamClass)
pInputParamClass->Release();
if(pClass)
pClass->Release();
if(pNamespace)
pNamespace->Release();
if(pLocator)
pLocator->Release();
}
return hr;
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
ConfigNet();
CoUninitialize();
printf("Program end\n");
return 0;
}
|
|
|
|
|
I got runtime error when I am moving toolbars in my program. Please can any one solve my problem.
The steps to reproduce are:
1) Start application eithor in Release mode or Debug mode.
2) Select the Com port to communicate.
3) Select start polling. (In this option the polling function will be
called repeatedly for every 2 seconds.
In that function we are getting details of hardware. Be cause if
we need the current details of hardware we need to do eithor refresh, or start polling. then we can get the current details of HW. )
4) Move tool bars 3 or 4 times.
( I have 4 tool bars in my program. they are 1. Standard toolbar,
2. CDialogBar m_wndPolling;//will be created through dialog design.
3. CToolBar m_wndToolBar; // will be created through dialog design
4. CToolBar m_tlbAlarms; ) // will be created completely at runtime.
5) Got Runtime error.
(If I am not moving tool bars then I am not getting any crash.)
The error has occured for me eithor in debugging mode or in relealse mode.
If any thing not clear please let me know.
When i got error in debugging mode, the call stack in my program is follows:
CDockContext::InitLoop() line 427 + 31 bytes
CDockContext::StartDrag(CPoint {x=0x00000145 y=0x00000144}) line 84
CControlBar::OnLButtonDown(unsigned int 0x00000001, CPoint {x=0x00000145 y=0x00000144}) line 645
CWnd::OnWndMsg(unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6, long * 0x0012eb54) line 1964
CWnd::WindowProc(unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 1585 + 30 bytes
CControlBar::WindowProc(unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 480 + 20 bytes
AfxCallWndProc(CWnd * 0x00324ea4 {CToolBar hWnd=0x007904ba}, HWND__ * 0x007904ba, unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 215 + 26 bytes
AfxWndProc(HWND__ * 0x007904ba, unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 368
AfxWndProcBase(HWND__ * 0x007904ba, unsigned int 0x00000201, unsigned int 0x00000001, long 0xfff400d6) line 220 + 21 bytes
Any help will be great. Thank you
Nice talking to you.
|
|
|
|
|
Hello..
I'm a beginner with Visual C++.. (have only done very very basic C++ programming).. I'm trying to communicate with a microcontroller using serial communication.. I tried to do it from scratch using the Windows functions..this is what my code looks like..
#include "stdafx.h"<br />
<br />
int _tmain()<br />
{<br />
<br />
HANDLE h = CreateFile("COM3", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);<br />
if (h == 0)<br />
{<br />
printf("Can't open com port (1)\n");<br />
return 1;<br />
}<br />
DCB dcb;<br />
memset(&dcb, 0, sizeof(DCB));<br />
dcb.DCBlength = sizeof(DCB);<br />
dcb.BaudRate = 19200;<br />
dcb.fBinary = TRUE;<br />
dcb.fParity = FALSE;<br />
dcb.ByteSize = 8;<br />
dcb.Parity = NOPARITY;<br />
dcb.StopBits = ONESTOPBIT;<br />
BOOL result = SetCommState(h, &dcb);<br />
if (!result)<br />
{<br />
printf("Can't set com port state(2)\n");<br />
return 1;<br />
}<br />
<br />
if (result)<br />
printf("Have Set com port state\n");<br />
<br />
char buffer[100];<br />
DWORD bytesRead = 0;<br />
while (true)<br />
{<br />
printf("In while\n"); <br />
<br />
memset(buffer, 0, sizeof(buffer));<br />
if (ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0))<br />
{<br />
printf("Read file has a result\n"); <br />
if (bytesRead != 0)<br />
{<br />
printf("Got some bytes\n"); <br />
printf ("%s", buffer);<br />
}<br />
<br />
else {<br />
printf("No bytes read\n"); <br />
}<br />
}<br />
<br />
else {<br />
printf("Readfile didnt give proper result \n"); <br />
}<br />
Sleep(200);<br />
}<br />
<br />
CloseHandle(h);<br />
<br />
return 0;
he micro is continously sending characters to the serial port.. when i run the program.. the port does gets initialized properly (debug statement printed ) then some characters are recieved but they are unintelligble.. i've checked the speed and all other settings for the com port and they are the same as the micro and the micro's usart is working fine.. can anyone see why i'm getting garbage..
Thank you for the help..
|
|
|
|
|
Hi,
Can you check this with Hyperterminal tool provided along with the operating systems?. If hyperterminal prints the right characters send by the microcontroller then we can dig into your code... Could you please do this??
And also check whether the characters sent by the microcontroller are ascii or unicode complaint..
" Action without vision is only passing time,
Vision without action is merely day dreaming,
But vision with action can change the world "
- Words from Nelson Mandela
Thanks & Regards,
Gopalakrishnan
|
|
|
|
|
Hello..
Thanks for your reply.. I've checked with Hyper Terminal.. the characters are receieved properly.. the micro is sending ASCII characters..
Regards,
Aditi
|
|
|
|
|
We need more beginners like you. You have good instincts as to how to figure out what the problem is. (You also have the option of using the TRACE() marcos, as well as printf(), in order to print debugging resutls).
Unfortunaley your code is good enough that it should probably be working. It does need improvement, but that's not the problem. What the problem is I do not know and I've written severial serial communications programs. In otherwords, I'd have to be degugging it.
SOME COMMENTS:
1) CreateFile() doesn't return 0 on failure, it returns INVALID_HANDLE_VALUE (which is equal to -1). All this tells us it that even thou your code does not know if it failed to open a port, it has succeded because you are receiving data. (Oh, if it did fail you code would report that it fail to open port 1 not 3).
2) Use: if(result) {...} else {...}. Not: if(result) {...} if(!resutl) {...}
3) If ReadFile() succededs then bytesRead should not be 0, so checking for it makes no since.
GARBAGE IS A RELITIVE TERM:
1) Your code implies that you are expecting to receive (ASCII) text. If that is not what the microcontroller is returning, then it will look like garbage.
2) What are you expecting to receive from the microcontroller?
FYI:
I assume you know that you are writting C code and not C++ code.
(It has no effect on your problem or its solution).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
There are two things at the top of my head: flow control and timeouts.
In most cases when you are beginning to communicate with a MC or similar you don't need any flow control and you would select "None" in Hyperterminal.
In your code this would mean the following setting that you have omitted:
<br />
dcb.fDtrControl = DTR_CONTROL_ENABLE;<br />
dcb.fRtsControl = RTS_CONTROL_ENABLE;<br />
Since you have fillled the DCB struct with zeros, the HW signals DataTerminalReady and RequestToSend will be inactive. Depending on connected hardware this could have various results from no communication to no impact at all.
Regarding timeouts you may want to read about it in MSDN under the documentation for the ::SetCommTimeouts function.
Tip of the day: use PortMon!
I have found PortMon to be extremely helpful in situations like the one you are describing. PortMon is freeware and can be downloaded at http://www.sysinternals.com/utilities/portmon.html[^]
With PortMon it's easy to determine how the port is setup and see what is sent and received in either hex or ASCII.
Make sure that the setup sequence looks the same for both your app and HT since HT seems to be working.
Hope this helps
--
Roger
|
|
|
|
|
Hello all..
Thank you for the replies.. Right now i'm sitting with the problem that the program on the PC is SOMETIMES getting the expected data from the micro but sometimes it gets the unintelligble characters.. I've noticed that for instance if i run the program and its gets garbage.. then i close it and wait a bit,run it a coupla times and then it gets the right stuff once.. then if i run it again it'll give garbage again.. and for the next coupla times it'll just give garbage.. then after a coupla tries it'll give the right stuff after some time ??!!!
In my code.. I use CloseHandle() to close the serial connection.. but i've noticed that after running the program and exiting it and then using the a terminal program such as HyperTerminal.. then HyperTerminal has trouble getting the characters from the serial port.. but after giving some time then HyperTerminal starts getting the characters properly..
The program always garbage when the micro starts sending characters to it (at power up).. and then has to be run a coupla times before it'll give the right output once..
Is there any other method to close the serial connection properly ?
I know my description above is not very technical but I'm a beginner and am trying to give as much info as I can make sense of in this program..
Thank you for your help..
Aditi
P.S. I did put in the DTR and RTS control ENABLE lines in the code as suggested by Roger.. but it still behaves the same way..
|
|
|
|
|
Have you compared the setup sequences for your app and HyperTerminal with PortMon?
Any diffs?
Aditi484 wrote:
In my code.. I use CloseHandle() to close the serial connection..
::CloseHandle() is the proper call to make.
If you are referring to the code you posted in your first mail you'll never reach ::CloseHandle() since it's outside the while-loop. This should make HT complain about the port being busy.
How do you exit your application? Terminating it with <shift+f5>?
Is it a real RS232 connection you're using or is it some simulated serial connection over USB?
It might be helpful if you could log the setup sequence with PortMon and cut it out and send it in your next post.
--
Roger
|
|
|
|
|
Hello..
I just used PortMon and the setup is right between the app and hyperterminal.. I'm using a normal serial port...
Below is the log of what PortMmon recorded..
4 0.00006984 comm console.ex IRP_MJ_CREATE Serial1 SUCCESS Options: Open <br />
5 0.00000559 comm console.ex IOCTL_SERIAL_GET_BAUD_RATE Serial1 SUCCESS <br />
6 0.00000196 comm console.ex IOCTL_SERIAL_GET_LINE_CONTROL Serial1 SUCCESS <br />
7 0.00000196 comm console.ex IOCTL_SERIAL_GET_CHARS Serial1 SUCCESS <br />
8 0.00000168 comm console.ex IOCTL_SERIAL_GET_HANDFLOW Serial1 SUCCESS <br />
9 0.00000950 comm console.ex IOCTL_SERIAL_SET_BAUD_RATE Serial1 SUCCESS Rate: 19200 <br />
10 0.00000587 comm console.ex IOCTL_SERIAL_SET_RTS Serial1 SUCCESS <br />
11 0.00000559 comm console.ex IOCTL_SERIAL_SET_DTR Serial1 SUCCESS <br />
12 0.00000531 comm console.ex IOCTL_SERIAL_SET_LINE_CONTROL Serial1 SUCCESS StopBits: 1 Parity: NONE WordLength: 8 <br />
13 0.00000391 comm console.ex IOCTL_SERIAL_SET_CHAR Serial1 SUCCESS EOF:0 ERR:0 BRK:0 EVT:0 XON:0 XOFF:0 <br />
14 0.00000531 comm console.ex IOCTL_SERIAL_SET_HANDFLOW Serial1 SUCCESS Shake:1 Replace:40 XonLimit:0 XoffLimit:0 <br />
15 0.00819546 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
16 0.00986215 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
17 0.00978951 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
18 0.00971129 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
19 0.00959787 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
20 0.00904864 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
21 0.00977275 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
22 0.00979733 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
23 0.00865725 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
24 0.00866004 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
25 0.00002375 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .*W...............M.................M.................M......... <br />
26 0.00002375 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
27 0.00002319 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
28 0.00002347 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
29 0.00002570 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
30 0.00002542 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
31 0.00002738 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
32 0.00002570 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
33 0.00002514 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
34 0.00002514 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
35 0.00002598 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
36 0.00002514 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
37 0.00002570 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
38 0.00002570 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
39 0.00002542 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
40 0.00002542 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
41 0.00002486 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: M.................M.................M.................M......... <br />
42 0.00002514 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: .........M.................M.................M.................M <br />
43 0.00864188 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 19: M.................. <br />
44 0.00865976 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
45 0.00874022 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
46 0.00863909 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
47 0.00868714 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
48 0.00865026 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
49 0.00717968 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
50 0.00863601 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
51 0.00867764 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
52 0.00754062 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
53 0.00651982 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
54 0.00002123 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
55 0.00002430 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
56 0.00002347 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
57 0.00002375 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
58 0.00002375 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
59 0.00002514 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
60 0.00002626 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
61 0.00002626 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
62 0.00002430 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
63 0.00002738 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
64 0.00002766 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
65 0.00002570 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
66 0.00002766 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
67 0.00002794 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
68 0.00002654 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
69 0.00002011 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: Start0087testokendStart0087testokendStart0087testokendStart0087t <br />
70 0.00002570 comm console.ex IRP_MJ_READ Serial1 SUCCESS Length 99: testokendStart0087testokendStart0087testokendStart0087testokendS <br />
71 0.00772724 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 18: Start0087testokend <br />
72 0.00842621 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
73 0.00828876 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
74 0.00910674 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
75 0.00837425 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
76 0.00890532 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
77 0.00913496 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
78 0.00783899 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
79 0.00822954 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
80 0.00905199 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
81 0.00778255 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
82 0.00891286 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
83 0.00916038 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
84 0.00911708 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
85 0.00827032 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
86 0.00898773 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
87 0.00820048 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
88 0.00804208 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
89 0.00910702 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
90 0.00791190 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
91 0.00912602 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
92 0.00838654 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
93 0.00910060 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
94 0.00817059 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
95 0.00912267 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
96 0.00824379 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
97 0.00907182 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
98 0.00775518 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
99 0.00858740 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
100 0.00827396 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
101 0.00947243 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
102 0.00836978 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
103 0.00934392 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
104 0.00875195 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
105 0.00858768 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
106 0.00968754 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
107 0.00972666 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
108 0.00970738 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
109 0.00913049 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
110 0.00973252 comm console.ex IRP_MJ_READ Serial1 TIMEOUT Length 0: <br />
111 0.00000922 comm console.ex IRP_MJ_CLEANUP Serial1 SUCCESS <br />
112 0.01114248 comm console.ex IRP_MJ_CLOSE Serial1 SUCCESS <br />
Initially my micro was sending stuff continuously but now I'm just sending my test string a 100 times.. and then the micro doesnt send anything..
From this log what I can make out (please correct me if I'm wrong) that the serial port is setup correctly.. and then the program was waiting for some bytes and got nothing (the Length 0 part).. and then i switched on my micro..the micro sent the string 100 times, but the program got some characters which were garbage.. then the program was just looping through getting nothing (micro had finished sending the string 100 times) then i switched off-on the micro again and this time it recieved the right characters.. and then micro finishes sending the string so the program loops through getting nothing.. then i closed the console of the program.. and then PortMon gets "Cleanup and Close" messages which are successful..
Also I wanted to ask.. if after running my program.. to exit it I close the console window i run it from.. that effectievly ends the program and should result in Closehandle() being called (PortMon did get the "Cleanup and Close" messages ?? ) So then why after that does HyperTerminal still complain..
Thank you for your help..
Aditi
|
|
|
|
|
The port seems to be setup good enough.
To put it in short terms: I suspect that your MC doesn't do what you think it does.
I tried running the code you've written and it works. It receives the bytes sent to the port and writes them to the console window.
Note that calling ::ReadFile in non-overlapped mode will be a blocking call. You decide for how long it should block and when to timeout and what for by a call to ::SetCommTimeouts after calling ::SetCommState.
Regarding ::CloseHandle() it cannot be called in the code you've written.
The call to ::CloseHandle() is on the other side of an endless loop.
Since you are running the app as a console app it is the responsability of the console to terminate the program running in the console, if it's possible, when you close the console window.
I suspect a call to _endthread() that will end your app and that would let the run-time system reclaim allocated resources such as the port since there is only one thread in your app. As a result of that you will see the cleanup and close statements in PortMon.
HyperTerminal might complain if the MC is malfunctioning or is not setup the same as HT, e.g. uses the wrong baudrate or uses two stopbits instead of one. But this is not unique for HT, your app should react the same way by getting nonsense.
If I were you I would get an oscilloscope or logic analyser to see what's really going on with the RxD and TxD lines.
--
Roger
|
|
|
|
|
Thank you for your reply.. Sorry i'm only getting back now.. I was busy tweaking the code and the MC to see where the problem was.. turns out it was the MC.. there was problems with synchronization when talking to the PC..
Thank you all for your time to help.. I've sure have learnt some pointers from the replies..
|
|
|
|
|
I want to write a program that makes a particular exe run everyday. For this, it should add that exe to Scheduled Tasks. But how to do that programatically?
All I know is, when we add a new Scheduled Task, say MyTask, it creates a file "C:\Windows\Tasks\MyTask.job", but this file contains some binary data and can't be directly created/editad.
Any Standard Ways / Workarounds ?
It's better to know some of the questions than all of the answers.
Pravin.
|
|
|
|
|
You need to use ITaskScheduler interface.
You can easily come to know how to use it, and there are related interfaces.
|
|
|
|
|
Here's a starting point:
HRESULT hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
ITaskScheduler *pITaskScheduler = NULL;
hr = CoCreateInstance(CLSID_CTaskScheduler, NULL, CLSCTX_INPROC_SERVER, IID_ITaskScheduler, (void **) &pITaskScheduler);
if (SUCCEEDED(hr))
{
...
pITaskScheduler->Release();
}
CoUninitialize();
}
See here for more.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I don't understand why NT uses a 2-step physical memory locating method. it splits a 32-bit virtual address in 3 parts. two first parts are indexes of page-directory and page-table respectively.
why dosn't it split virtual adress in 2 parts in which the fist part only indexs page table index and the CR3 register points to the first index of page table?
please explain more and more!!
|
|
|
|
|
I have a simple server and client source code that can run. The problem is I type two same IP address in the source code of server and client, the program can connect and send. But when I test the program in two PC and type both IP address in both of the program, the program cannot work. What is the problem of it?
|
|
|
|
|
Hello,
It is said in MSDN for the SDK SelectObject fn that "An application should always replace a new object with the original, default object after it has finished drawing with the new object".
Is it neccessary for MFC CDC object also?
- NS -
|
|
|
|
|
Nishad S wrote:
Is it neccessary for MFC CDC object also?
Why Not??
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Yes!
The CDC object is just a wrapper around a DC handle and it provides minimal support for reading/writing to a DC handle, as it should.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Hi all,
Has any ever encountered this kind of problem when usin VC6:
On the surface of the main dialog, tthere are 129 controls (CStatic's, CEdit's, CButton's).
No other resource can be added on the dialog surface (neither by resource selecting and insertion, nor by copy-paste merthod) ?
Thanks
SkyWalker
|
|
|
|
|