Board index » cppbuilder » DTR Output on COM port
Jack Sawatzky
![]() CBuilder Developer |
Jack Sawatzky
![]() CBuilder Developer |
DTR Output on COM port2005-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. |
Bill
![]() CBuilder Developer |
2005-07-27 03:56:16 AM
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 |
Jack Sawatzky
![]() CBuilder Developer |
2005-07-29 10:31:08 AM
Re:DTR Output on COM portQuoteOne thing you're doing wrong is looking at DSR, which is an input :-) You that I was monitoring with my meter, and getting nothing but 0 volts. So the basic question remains. Jack {smallsort} |
Bill
![]() CBuilder Developer |
2005-07-30 09:00:33 PM
Re:DTR Output on COM port
"Jack Sawatzky" < XXXX@XXXXX.COM >wrote in message
Quote
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 |
Hans-Jochen Trost
![]() CBuilder Developer |
2005-08-01 11:25:28 PM
Re:DTR Output on COM port
Jack,
QuoteActually I made a mistake in my query. It IS pin number 4 on the DB9 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 |