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();
}

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).

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?

It still won't be in a class. Without knowing what your problem is, I can't tell you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.