• 0

[C#] SerialPort Question


Question

2 answers to this question

Recommended Posts

  • 0

I believe it would be helpful if you told us which device you are using and what you are trying to accomplish, specifically. Maybe post a little code that you are having trouble with. Your description is quite vague.

While I have never tried interfacing with a serial port in C#, or Windows in general, I will try to help anyway. I worked on a project recently that involved interfacing with an Arduino board over its serial connection. For lack of further details on your part, I'm going to assume that your program will interface fairly similarly. I found this blog post by John Ciacia that describes interacting with the Arduino in C# in great detail. In fact, the demonstration code in his post looks very similar to my own implementation (in C++ for Linux, however).

For the record, I had the same problem as you with the data received being somewhat slow. Essentially, you need to know exactly how many characters you need to read from the serial device before starting the read operation, and block until you receive that specific number of characters. In my case, I found it easiest to send and receive only one character at a time. That worked for me because I didn't have exceptionally complex instructions to carry out. Since your device's output sequence seems to be 3 integers followed by a space, that approach may work for you too (but waiting for four characters instead of just one before returning).

If you wish, I will post my class so you can look at how I solved the problem. Note, however, that it is in a different language for a different operating system, although the concepts should be fairly similar.

PS: Make sure you are initializing the connection with the correct baud rate. You will not be able to get anything done if the baud rate is wrong!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I wonder what that line really meant...
    • draw.io Desktop 30.2.6 by Razvan Serea draw.io desktop is a downloadable security-first diagramming application that runs on Windows, MacOS and Linux. Creating diagrams in the desktop app doesn’t need an internet connection. This is useful when you are disconnected or when you must create diagrams in a highly secure environment, where data protection is of the utmost importance. When you use the draw.io desktop app, your diagrams will be stored on your local device. Because this is a stand-alone application, also designed to run offline, there are no interfaces to cloud storage platforms available. Of course, you can still store your diagrams in folders that are synchronised to your cloud storage if you wish. Easy-to-use diagram editor The draw.io apps work just like the office and drawing tools you are used to using. Drag and drop shapes from the shape libraries and drag to draw connectors between them. Drag connectors to add waypoints and set a precise shape and position, or let them reroute automatically. Double click and start typing to add a label to anything. Create tables and swimlane flows with a familiar tool. Style shapes and connectors with customisable palettes, sketch options, fonts and text formatting tools. Search for shapes, including in open-source icon libraries. Use our vast libraries of shapes and templates, organised into logical categories, to create a range of diagrams and infographics. Generate diagrams from text descriptions using our smart templates. Diagram faster with keyboard shortcuts. draw.io Desktop 30.2.6 changelog: Uses electron 42.5.0 #2452 Updates to draw.io core 30.2.6. Download: draw.io 64-bit | Standalone (Open Source) Download: draw.io 32-bit | ARM64 | ARM64 Standalone Links: draw.io Home Page | Project page @GitHub | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • One Month Later
      Excellence2025 earned a badge
      One Month Later
    • Week One Done
      Excellence2025 earned a badge
      Week One Done
    • Week One Done
      flexorcist earned a badge
      Week One Done
    • One Month Later
      Woland13 earned a badge
      One Month Later
    • Week One Done
      Woland13 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      497
    2. 2
      +Edouard
      207
    3. 3
      PsYcHoKiLLa
      146
    4. 4
      Steven P.
      74
    5. 5
      FloatingFatMan
      69
  • Tell a friend

    Love Neowin? Tell a friend!