Hi all!
I’m a beginner with C#. Actually this is my first C# project and i’m trying to program a little traffic light for my K8090 board. I already had a little help from a friend who is a programmer, but i don’t want to ask him for help over and over again. So i hope someone can help me here.
First of all i’m looking for a code that is automaticly detecting the right USB (COM) port, so i dont have to change the port in C# if i connect to another port. I’m using this code now:
private void Form1_Load(object sender, EventArgs e)
{
string[] portNamen = System.IO.Ports.SerialPort.GetPortNames();
board.Port = "COM9";
connection = board.Connect();
if (connection)
{
this.Text = "Trafficlight connected to Port 9";
}
else
{
this.Text = "Trafficlight NOT connected to Port 9";
System.Windows.Forms.MessageBox.Show("k8090 NOT connected to Port 9");
pictureBox1.Visible = false;
pictureBox2.Visible = false;
}
if (connection)
{
board.SwitchRelayOn(1);
board.SwitchRelayOn(8);
board.SwitchRelayOn(32);
board.CommandReceived += OnCommandoRecieving;
}
}
So i hope someone can help me with a better code!
Thx!