SoFunction
Updated on 2025-04-06

C# implements writing specified data to the serial port

C# implements writing specified data to the serial port

Updated: June 16, 2015 11:34:37 ​​Submission: junjie
This article mainly introduces the C# implementation of writing specified data into the serial port and directly gives sample code. Friends who need it can refer to it
    public static bool WriteToSerialPort(byte[]byteArr)
    {
      SerialPort Com = newSerialPort();
      try
      {
         = 5000;
         = 5000;
         = "Com1";
         = 9600;
         = ;
         = ;
        ();
        (byteArr, 0,);
        return true;
      }
      catch(Exception ex)
      {
        return false;
      }
      finally
      {
        ();
      }      
    }

This example uses the method Write(Byte[]buffer, Int32 offset, Int32 count). This method uses the buffer's data to write a specified number of bytes to the serial port. The buffer is a buffer, offset means copying bytes to the port from here, and count means the number of bytes to be written.

  • C#
  • data
  • Write to the serial port

Related Articles

  • C# WinForm window minimized to system tray

    C# writes Window application hidden as taskbar icons when minimized.
    2008-11-11
  • Example of C# code generating URL address

    This article mainly introduces the method of generating URL addresses in C# code, which helps everyone better understand and learn how to use C#. Interested friends can learn about it.
    2021-04-04
  • How to read and write INI configuration files in C#

    This article mainly introduces the methods of reading and writing INI configuration files in C#. It is very good and has certain reference value. Friends who need it can refer to it.
    2018-07-07
  • C# Winform downloads file and displays progress bar implementation code

    I originally wanted to study how to judge the download was completed. As a result, I found this method. You can prompt the download to be completed after the method is completed. Friends who need it can refer to it.
    2014-07-07
  • IList in C#With ListIn-depth analysis of the differences

    This article mainly analyzes and introduces the difference between IList<T> and List<T> in C#. Friends who need it can come and refer to it. I hope it will be helpful to you.
    2014-01-01
  • How to handle errors in case of failing to load a file or assembly when calling DLL in C# (detailed explanation)

    Below, the editor will bring you a method of handling errors in C# that fail to load files or assembly when calling DLLs (detailed explanation). The editor thinks it is quite good, so I will share it with you now and give you a reference. Let's take a look with the editor
    2017-02-02
  • Detailed explanation of the production and usage examples of C# custom controls

    This article provides a detailed analysis and introduction to the production and use of custom controls in C#. For those who need it, please refer to it.
    2013-05-05
  • C# Depth-first Search Algorithm

    This article mainly introduces the C# depth priority search algorithm, which has certain reference value. Interested friends can refer to it.
    2017-06-06
  • C#/Implementation of inserting or deleting footnotes in Word

    Footnotes can be attached to the bottom of the article page, explaining something, and printing it on the bottom of the book page. This article will show you how to programmatically insert or delete footnotes in Word through C#/code. If you need it, please refer to it.
    2023-03-03
  • How to use sortedlist in c#

    This article mainly introduces the use of sortedlist in C#. Friends who need it can refer to it.
    2014-05-05

Latest Comments