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. help with CSerial (code included)

help with CSerial (code included)

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiocomhelp
6 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.
  • O Offline
    O Offline
    oh4u2nv
    wrote on last edited by
    #1

    i'm trying to communicate with a relay box connected with a serial cable. you send a command of N1 to open the first relay, N2 to open the second, etc... i've tested it with hyperterminal and it works fine. i'm usin a c++ mfc app in vs.net03. i've just added code to my program, if there are any settings that i have to set, then i don't know about them. i'm using the CSerial class http://www.codeproject.com/system/serial.asp portName and relay are both CStrings. anyone know what's wrong?? CSerial link; link.Open(portName); //either COM1 or COM2 //set the port settings link.Setup(CSerial::EBaudrate(9600), CSerial::EDataBits(, CSerial::EParity(NOPARITY), CSerial::EStopBits(ONESTOPBIT)); if(relay[0]=='1') relay.Delete(0,1); link.Write(relay); //writing "N1" or whatever //find time for pump to stay open runtime=drinklist[num].amount[x]*MULTIPLIER; Sleep(runtime*1000); relay.Delete(0,1); relay.Insert(0,"F"); link.Write(relay); link.Close(); thanx

    J 1 Reply Last reply
    0
    • O oh4u2nv

      i'm trying to communicate with a relay box connected with a serial cable. you send a command of N1 to open the first relay, N2 to open the second, etc... i've tested it with hyperterminal and it works fine. i'm usin a c++ mfc app in vs.net03. i've just added code to my program, if there are any settings that i have to set, then i don't know about them. i'm using the CSerial class http://www.codeproject.com/system/serial.asp portName and relay are both CStrings. anyone know what's wrong?? CSerial link; link.Open(portName); //either COM1 or COM2 //set the port settings link.Setup(CSerial::EBaudrate(9600), CSerial::EDataBits(, CSerial::EParity(NOPARITY), CSerial::EStopBits(ONESTOPBIT)); if(relay[0]=='1') relay.Delete(0,1); link.Write(relay); //writing "N1" or whatever //find time for pump to stay open runtime=drinklist[num].amount[x]*MULTIPLIER; Sleep(runtime*1000); relay.Delete(0,1); relay.Insert(0,"F"); link.Write(relay); link.Close(); thanx

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      From you example: link.Setup(CSerial::EBaudrate(9600), CSerial::EDataBits(, CSerial::EParity(NOPARITY), CSerial::EStopBits(ONESTOPBIT)); From http://www.codeproject.com/system/serial.asp: serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1); Just a thought! INTP

      O 1 Reply Last reply
      0
      • J John R Shaw

        From you example: link.Setup(CSerial::EBaudrate(9600), CSerial::EDataBits(, CSerial::EParity(NOPARITY), CSerial::EStopBits(ONESTOPBIT)); From http://www.codeproject.com/system/serial.asp: serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1); Just a thought! INTP

        O Offline
        O Offline
        oh4u2nv
        wrote on last edited by
        #3

        those two lines are the same, or so the example says. any other suggestions. i'm really stuck here

        J 1 Reply Last reply
        0
        • O oh4u2nv

          those two lines are the same, or so the example says. any other suggestions. i'm really stuck here

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          When working on serial communication I have found it usful to run a terminal program on another machine and capture the data output from my program. If it receives garbage, then it is a port setup problem (or bad serial port). If it receive nothing, then either I selected the wrong output port or (heaven forbid) I forgot to make sure the port open successfuly. I hope this will at least help a little, since I have not used CSerial. I tend to write my own using file I/O (on Win32 platforms). INTP

          D 1 Reply Last reply
          0
          • J John R Shaw

            When working on serial communication I have found it usful to run a terminal program on another machine and capture the data output from my program. If it receives garbage, then it is a port setup problem (or bad serial port). If it receive nothing, then either I selected the wrong output port or (heaven forbid) I forgot to make sure the port open successfuly. I hope this will at least help a little, since I have not used CSerial. I tend to write my own using file I/O (on Win32 platforms). INTP

            D Offline
            D Offline
            Deepa Gopal
            wrote on last edited by
            #5

            Hi, Could you please let me know how you can runa terminal program to capture the output from another program?I am in the process of developing a serial communication between a laptop and PDA.I have to send data from the lpatop which has to be read by the PDA. Thanking you for your time, Deepa. John R. Shaw wrote: When working on serial communication I have found it usful to run a terminal program on another machine and capture the data output from my program. If it receives garbage, then it is a port setup problem (or bad serial port). If it receive nothing, then either I selected the wrong output port or (heaven forbid) I forgot to make sure the port open successfuly. I hope this will at least help a little, since I have not used CSerial. I tend to write my own using file I/O (on Win32 platforms). INTP

            J 1 Reply Last reply
            0
            • D Deepa Gopal

              Hi, Could you please let me know how you can runa terminal program to capture the output from another program?I am in the process of developing a serial communication between a laptop and PDA.I have to send data from the lpatop which has to be read by the PDA. Thanking you for your time, Deepa. John R. Shaw wrote: When working on serial communication I have found it usful to run a terminal program on another machine and capture the data output from my program. If it receives garbage, then it is a port setup problem (or bad serial port). If it receive nothing, then either I selected the wrong output port or (heaven forbid) I forgot to make sure the port open successfuly. I hope this will at least help a little, since I have not used CSerial. I tend to write my own using file I/O (on Win32 platforms). INTP

              J Offline
              J Offline
              John R Shaw
              wrote on last edited by
              #6

              I have not used CSerial either. In order to use a terminal program, such as hyper-terminal (comes with all PC versions of windows), you will need to make null-modem cable or you may buy one at a computer supply store like radio shack. The wiring for a null-modem cable can be found on the net or in a book on serial communications. If you are doing your serial communication using a USB port, you may also need a USB to 9-pin serial cable or 2. When you setup the teminal side, you need to make sure that it is not doing something funky with that data (like replacing CR with CR/LF). The data must be saved without modification (received as binary not text). Once you have set the serial-port properties, then all you need to do is select receive file. The terminal program will sit there and wait until data starts arriving at the port, at which time it will start coping the data to the given file (for later analisys). Well, I hope this helps you! Good Luck! INTP

              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