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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Issue Reading and Writing to Serial Port

Issue Reading and Writing to Serial Port

Scheduled Pinned Locked Moved Managed C++/CLI
helpcsharpc++visual-studioquestion
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.
  • B Offline
    B Offline
    BubbaGeeNH
    wrote on last edited by
    #1

    I've written a managed class that handles the serial communication to a laser using ascii text. My problem is if my GUI makes too many calls to the functions in the laser communication class I get the wrong responses back from the laser. They are valid responses but it appears as if the response from the first call is being replaced by the response from the second call. I've attempted to control the usage of the serial port by using 'Mutex.WaitOne' but that doesn't seem to have an affect. All the calls to the laser are being generated by Windows' messages within the GUI. Does anyone know of a way to control the flow of calls to the laser class? I'm using Visual Studio 2008 and Managed C++. Thanks, George

    George

    R 1 Reply Last reply
    0
    • B BubbaGeeNH

      I've written a managed class that handles the serial communication to a laser using ascii text. My problem is if my GUI makes too many calls to the functions in the laser communication class I get the wrong responses back from the laser. They are valid responses but it appears as if the response from the first call is being replaced by the response from the second call. I've attempted to control the usage of the serial port by using 'Mutex.WaitOne' but that doesn't seem to have an affect. All the calls to the laser are being generated by Windows' messages within the GUI. Does anyone know of a way to control the flow of calls to the laser class? I'm using Visual Studio 2008 and Managed C++. Thanks, George

      George

      R Offline
      R Offline
      Rick Shaub
      wrote on last edited by
      #2

      Why don't you try sending one command and waiting for the response before sending the next command?

      B 1 Reply Last reply
      0
      • R Rick Shaub

        Why don't you try sending one command and waiting for the response before sending the next command?

        B Offline
        B Offline
        BubbaGeeNH
        wrote on last edited by
        #3

        If I run my class as part of a Console application I have no problems with it communicating correctly and getting the correct responses. My problem is when I try to run it as part of a Windows GUI application. It seems as though the compiler is making my application a multi-threaded application and it is putting the writing and reading of portions of the class into different threads.

        George

        L 1 Reply Last reply
        0
        • B BubbaGeeNH

          If I run my class as part of a Console application I have no problems with it communicating correctly and getting the correct responses. My problem is when I try to run it as part of a Windows GUI application. It seems as though the compiler is making my application a multi-threaded application and it is putting the writing and reading of portions of the class into different threads.

          George

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

          Hi, you can use synchronous calls such as SerialPort.Read() and SP.Write() any way you like; the thread executing the call will process the data, obviously. However some event handlers, such as DataReceived, will fire on another thread (what else could they do?). You may want to read this article[^]. And that is exactly the same for Console and WinForms applications. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          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