|
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
|
|
|
|
|
the number of controls that can be added in design mode is limited to 255 due to the resource identifiers.
if you want more, you will have to add your controls dynamically/programmatically.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I can understand that, but why is it working if I manually add them in the .rc file (using Notepad for that) ?
( I did not have 255 identifiers yet )
SkyWalker
|
|
|
|
|
Mircea Puiu wrote:
using Notepad for that
why doun't you just use the resource editor ??????
check however to resource.h file to verify that the coutrols have consecutive IDs.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Because the resource editor was not working any longer for some reason.
The IDs were consecutive.
SkyWalker
|
|
|
|
|
|
|
Apparently no one else has tried that before, including the designiners of the resource editor. The limits sound like they are right (I forget what they are). I am suprised (if there is a bug) that you can add 129 controls, because the problem should have showed up at 128 controls.
NEVER MIND THAT!
It is working when you manually add them in the .rc because the RC compiler is doing what it was designed to do. The RC editor (on the other hand) is apparently introducing false limitations.
In any case that is a ridiculous number of controls.
INTP
Every thing is relative...
|
|
|
|
|
http://www.codeproject.com/useritems/WOL.asp
Hello, I just read an article and test on my machines. My two machines was connected through a giga byte LAN wire.
I realize that, if my target machine is shut down through win xp, the target machine can be WOL no problem.
However, if my target machine is shut down by pressing the on/off button, the target machine cannot be WOL
In both cases, the LAN LED still light up.
Seems weird, may I know what is the difference between turn off via on/off button and via winxp shut down? Why WOL problem occur does occur?
Thank you.
|
|
|
|
|
yccheok wrote:
http://www.codeproject.com/useritems/WOL.asp
Why don't you post your question in the Forum present at the bottom of article...
"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
|
|
|
|
|
It depends on the individual hardware, some systems may not maintain all of the standby voltages when switched off by the on/off button.
Elaine
The tigress is here
|
|
|
|
|
I have a winsocket server listening on a given port, say 2000. Is there a way how to find out what service (eg. telnet) is used by a particular client when it connects to the server? I tried getpeername() on a connected socket to get sockaddr_in structure filled and then I called getservbyport() with sin_port parameter from sockaddr_in, but with no success. I've got WSANO_DATA (Valid name, no data record of requested type) error.
I'd really appreciate any insight recommendation
Zdenek
|
|
|
|