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. need help with PJNaughter's CSerialPort class

need help with PJNaughter's CSerialPort class

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
2 Posts 2 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
    acidmarco
    wrote on last edited by
    #1

    Hi, I would like to communicate with the serial port in my app. I think the best way is to create a worker thread accessing the serial port and filling in a CString object (something like a buffer) with the incoming characters. It must also be possible to send chars to the connected hw. I was looking for a class implementing serial port accesses and I got PJNaughter's one. It seems to be quite well implemented but I cannot figure out how to use it in such a working thread. Is it possible to trap messages? How can I now when I have to read on the serial port? Must it be a forever loop or can it be implemented within the Windows Messages Routing? Please help me.

    R 1 Reply Last reply
    0
    • A acidmarco

      Hi, I would like to communicate with the serial port in my app. I think the best way is to create a worker thread accessing the serial port and filling in a CString object (something like a buffer) with the incoming characters. It must also be possible to send chars to the connected hw. I was looking for a class implementing serial port accesses and I got PJNaughter's one. It seems to be quite well implemented but I cannot figure out how to use it in such a working thread. Is it possible to trap messages? How can I now when I have to read on the serial port? Must it be a forever loop or can it be implemented within the Windows Messages Routing? Please help me.

      R Offline
      R Offline
      Remus Lazar
      wrote on last edited by
      #2

      Hi, I don't know exactly how the class looks like but you must have some function to notify you when an event occured. Should be somenthing like "WaitForEvent" with some parameters (event mask and timeout). You must wait until an event like CHAR_RECEIVED occures or timeout expires .. Something like that. General flow is something like this: Without handshake : - if you don't locate this kind of function to do the job for you try this : read the port with timeout and if char received is TIMEOU_CHAR or something like this -> you didn't receive something and try again, when first valid char occures you start to construct your message. Use this on thread and be carefully with your time out values.You should have some predifined types for TIMEOUT_CHAR. To send is much more easier, just send it. with handshake : - RTS/CTS, DTR/DTS or XON/XOFF you should read the protocols first and you should find functions to acces this signals from comm port. But the genereal flow is the same. This signals helps you to know when you can send something via serial port (if device is occupied and cannot receive will raise the CTS signal ..... ). i hope it's helpfull for you.

      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