Board index » cppbuilder » DTR Output on COM port

DTR Output on COM port


2005-07-26 02:43:19 AM
cppbuilder44
I am trying to control the DTR output. The following code does not
generate any errors, but it doesn't do anything else either; pin 6 on
the RS232 remains stubbornly at 0 volts.
hcom=CreateFile("COM2", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, NULL, NULL);
GetCommState(hcom, &dcb );
dcb.fDtrControl= DTR_CONTROL_ENABLE;
SetCommState( hcom, &dcb );
EscapeCommFunction(hcom,SETDTR);
Can you tell me what I am doing wrong?
Thanks.
 
 

Re:DTR Output on COM port

">Can you tell me what I am doing wrong?
One thing you're doing wrong is looking at DSR, which is an input :-) You
might have better luck with pin 4 on a 9-pin connector, or pin 20 on a
25-pin connector.
HTH,
Bill
 

Re:DTR Output on COM port

Quote
One thing you're doing wrong is looking at DSR, which is an input :-) You
might have better luck with pin 4 on a 9-pin connector, or pin 20 on a
25-pin connector.

HTH,
Bill




Hi Bill,
Actually I made a mistake in my query. It IS pin number 4 on the DB9
that I was
monitoring with my meter, and getting nothing but 0 volts. So the
basic question
remains.
Jack
 

{smallsort}

Re:DTR Output on COM port

"Jack Sawatzky" < XXXX@XXXXX.COM >wrote in message
Quote

>One thing you're doing wrong is looking at DSR, which is an input :-)
You
>might have better luck with pin 4 on a 9-pin connector, or pin 20 on a
>25-pin connector.
>
>HTH,
>Bill
>
>
>
>
Hi Bill,
Actually I made a mistake in my query. It IS pin number 4 on the DB9
that I was
monitoring with my meter, and getting nothing but 0 volts. So the
basic question
remains.
Jack
Ok then - moving on to the code...
Your code looks fine to me, very similar to code I use to explicitly control
the DTR line. For what it's worth, here is where my code differs from the
code you show:
1) I use FILE_ATTRIBUTE_NORMAL rather than 0 for the dwFlagsAndAttributes
parameter in the CreateFile call.
2) I check the return from CreateFile against INVALID_FILE_HANDLE (though I
assume you do too).
3) I call CloseHandle when I'm done (I assume you do too).
4) I don't bother with GetCommState or SetCommState if I'm only interested
in controlling the DTR line.
5) If I do use the DCB (because I want to use the port for comms at the same
time) then I set the fDtrControl flag to DTR_CONTROL_DISABLE.
I don't know which, if any, of these differences might affect the
effectiveness of your code.
Finally, I'm _still_ suspicious of your voltage measurements. Every PC
comms port I have looked at swings positive and negative at the output pins
(typically +/-12V) rather than zero (required by RS-232?). Zero suggests
either you are not making a connection, or you are not looking at an output.
HTH,
Bill
 

Re:DTR Output on COM port

Jack,
Quote
Actually I made a mistake in my query. It IS pin number 4 on the DB9
that I was
monitoring with my meter, and getting nothing but 0 volts. So the
basic question
remains.
no offense intended, but do you measure pin 4 against pin 5 (siganl
ground) ? The shell may have little to do with the signal ground,
depending on how your whole setup actually looks like.
Second, do you measure on the end of a cable or directly at the output
connector of the PC? If it is a cable, is it a straight-through or a
null-modem (computer-to-computer) cable? A null-model cable would
swap the DTR and DSR pins ...
Cheers, Jochen
hjtrost at microfab dot com
Nil nimium studeo, Caesar, tibi velle placere,
nec scire ut an sis albus an ater homo.
Catullus