I am using Visual Studio Community 2019 to write a new serial port downloader program. I am relatively new to C# but have had to maintain a large-ish c# application that also uses the serial port to configure an embedded device.
Problematic (new) code is below. The "System.IO.Ports" using statement has no effect (is greyed out) and the issue is that the compiler has no clue what a "SerialPort" is (see the error after the code).
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 = new SerialPort(comPort,
Convert.ToInt32(baudrate),
Parity.None,
8,
StopBits.One);
serialPort.Handshake = Handshake.None;
serialPort.Open();
serialPort.ReadTimeout = 1000;
progBar = progressBar;
messages = msgListBox;
}
public Download(String comPort,
String baudrate,
//String Product,
System.Windows.Forms.RichTextBox msgListBox,
System.Windows.Forms.ProgressBar progressBar)
{
Create(comPort, baudrate, /*Product,*/ msgListBox, progressBar);
}
}
}
C:...\Download.cs(20,16,20,26): error CS1069: The type name 'SerialPort' could not be found in the namespace 'System.IO.Ports'. This type has been forwarded to assembly 'System.IO.Ports, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly.
I have checked against the app that I maintain and which compiles and runs fine. The old app has a set of References, but the new app has just a set of dependencies, but I gather these are very similar or the same?
I suspect adding a reference is what is required but I have no clue what is needed. When I try to add a Reference in the new app I see nothing except for COM assemblies. There are loads but there is no clue as to which might be needed for serial port stuff. The old config app does not give any clue as the where it finds a reference for the SerialPort type.
Does anyone have a clue what I may have missed?