0

Afternoon everyone,
I'm having a bit of trouble writing a program just to open the serial port for communications, its the first time ive really dabled in c# so if i'm missing something really obvious let me know as im only using it to open the serial port.

Many Thanks!

// This is a new namespace in .NET 2.0
// that contains the SerialPort class
using System.IO.Ports;

private static void SendSampleData()
{
  // Instantiate the communications
  // port with some basic settings
  SerialPort port = new SerialPort(
    "COM1", 9600, Parity.None, 8, StopBits.One);

  // Open the port for communications
  port.Open();
}
2
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by Momerath
1

Your code isn't in a class. C# is an OO language and requires everything to be in a class.

Other than that there doesn't seem to be anything wrong. That should open the COM1 port (and then immediatly close it since your method ends and the 'port' variable only has method scope).

0

That should open the COM1 port (and then immediatly close it since your method ends and the 'port' variable only has method scope).

Thanks for the help, am i correct in thinking changing private to public would resolve this problem?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.