Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Serial Com controlling DTR & RTS

Serial Com controlling DTR & RTS

Scheduled Pinned Locked Moved C / C++ / MFC
comhelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aei_totten
    wrote on last edited by
    #1

    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

    A G L 3 Replies Last reply
    0
    • A aei_totten

      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

      A Offline
      A Offline
      aei_totten
      wrote on last edited by
      #2

      this is going to sound so stupid. But it works now :) I had the OScope on the wrong pin. ~Brandy

      1 Reply Last reply
      0
      • A aei_totten

        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

        G Offline
        G Offline
        Gary R Wheeler
        wrote on last edited by
        #3

        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![^]

        1 Reply Last reply
        0
        • A aei_totten

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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|


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups