Serial Com controlling DTR & RTS
-
okay what I want to do is be able to open a serial port and then set and clear the str and rts whenever I want to. For example: open com port do stuff set dtr send data wait so long clear dtr Hear is what I have tried that I thought should work:
int result = EscapeCommFunction(\_hCom,SETDTR); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); result = EscapeCommFunction(\_hCom,CLRDTR);
this was unsuccessful though the EscapeCommFunction returned successful (1). Since that didn't work I tried this
BuildCommDCB("dtr = on", &dcb); SetCommState(\_hCom, &dcb); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); BuildCommDCB("dtr = off", &dcb); SetCommState(\_hCom, &dcb);
which was equally as unsuccessful. What am I doing wrong? edited to try to fix reference (&) marks
-
okay what I want to do is be able to open a serial port and then set and clear the str and rts whenever I want to. For example: open com port do stuff set dtr send data wait so long clear dtr Hear is what I have tried that I thought should work:
int result = EscapeCommFunction(\_hCom,SETDTR); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); result = EscapeCommFunction(\_hCom,CLRDTR);
this was unsuccessful though the EscapeCommFunction returned successful (1). Since that didn't work I tried this
BuildCommDCB("dtr = on", &dcb); SetCommState(\_hCom, &dcb); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); BuildCommDCB("dtr = off", &dcb); SetCommState(\_hCom, &dcb);
which was equally as unsuccessful. What am I doing wrong? edited to try to fix reference (&) marks
this is going to sound so stupid. But it works now :) I had the OScope on the wrong pin. ~Brandy
-
okay what I want to do is be able to open a serial port and then set and clear the str and rts whenever I want to. For example: open com port do stuff set dtr send data wait so long clear dtr Hear is what I have tried that I thought should work:
int result = EscapeCommFunction(\_hCom,SETDTR); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); result = EscapeCommFunction(\_hCom,CLRDTR);
this was unsuccessful though the EscapeCommFunction returned successful (1). Since that didn't work I tried this
BuildCommDCB("dtr = on", &dcb); SetCommState(\_hCom, &dcb); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); BuildCommDCB("dtr = off", &dcb); SetCommState(\_hCom, &dcb);
which was equally as unsuccessful. What am I doing wrong? edited to try to fix reference (&) marks
One thing to note: your call to
Sleep(4)
will not sleep for exactly 4 milliseconds. It will probably sleep on the order of 10-20 milliseconds, depending upon the thread quantum (the thread-switching time).Software Zen:
delete this;
Fold With Us![^] -
okay what I want to do is be able to open a serial port and then set and clear the str and rts whenever I want to. For example: open com port do stuff set dtr send data wait so long clear dtr Hear is what I have tried that I thought should work:
int result = EscapeCommFunction(\_hCom,SETDTR); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); result = EscapeCommFunction(\_hCom,CLRDTR);
this was unsuccessful though the EscapeCommFunction returned successful (1). Since that didn't work I tried this
BuildCommDCB("dtr = on", &dcb); SetCommState(\_hCom, &dcb); //send a byte WriteFileEx(\_hCom,"\\xFF",1,test,0); //wait 4 ms Sleep(4); BuildCommDCB("dtr = off", &dcb); SetCommState(\_hCom, &dcb);
which was equally as unsuccessful. What am I doing wrong? edited to try to fix reference (&) marks
For more information on timing, you may want to read my timers article. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|