我正在使用 Visual Studio Community 2019 编写一个新的串口下载程序。我对 C# 比较陌生,但必须维护一个大型 C# 应用程序,该应用程序也使用串行端口来配置嵌入式设备。
有问题的(新)代码如下。“System.IO.Ports”using 语句没有任何效果(显示为灰色),问题是编译器不知道“SerialPort”是什么(请参阅代码后面的错误)。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Ports;
using System.Drawing;
namespace PangeaUpdater
{
class Download
{
const byte STX_CHAR = (byte)'\x2';
const byte ETX_CHAR = (byte)'\x3';
const byte DLE_CHAR = (byte)'\x10';
const int MAX_DATA_PACKET_LEN = 128;
private BinaryReader pkgStream = null;
public SerialPort serialPort;
private void Create(String comPort, String baudrate,
System.Windows.Forms.RichTextBox msgListBox,
System.Windows.Forms.ProgressBar progressBar)
{
//Lots of stuff should be configurable but is not (yet)
serialPort …
Run Code Online (Sandbox Code Playgroud)