C# implements writing specified data to the serial port
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.
Related Articles
C# WinForm window minimized to system tray
C# writes Window application hidden as taskbar icons when minimized.2008-11-11Example 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-04How 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-07C# 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-07IList in C#
With List In-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-01How 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 editor2017-02-02Detailed 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-05C# 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-06C#/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-03How 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