When running a project in Visual Studio 2019 that requires serial communication, I get the error: The COM3 port does not exist. How could I solve this?
CODE:
public Form1()
{
InitializeComponent();
if (!serialPort1.IsOpen)
{
serialPort1.Open();
}
}
private void Form1_Load(object sender, EventArgs e)
{
OnOffButton.Text = "OFF";
}
private void Form1_close(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void OnOffButton_Click(object sender, EventArgs e)
{
if (ON=="A0" && aux==false)
{
ON = "A1";
serialPort1.WriteLine(ON);
OnOffButton.Text = "ON";
OnOffButton.BackColor = Color.LimeGreen;
}
else
{
ON = "A0";
serialPort1.WriteLine(ON);
OnOffButton.Text = "OFF";
OnOffButton.BackColor = Color.Red;
}
}