2 Replies - 15172 Views - Last Post: 28 February 2007 - 05:45 AM Rate Topic: -----

#1 cathy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 21-February 07

reading data from serial port

Posted 27 February 2007 - 05:22 AM

I need to read a block of data through the serial port. Tried using the following code.

using System;
using System.IO.Ports;
using System.Windows.Forms;
#endregion

namespace app
{
class SerialPortProgram
	{
		// Create the serial port with basic settings
		private SerialPort port = new SerialPort("COM1", 1200, Parity.None, 8, StopBits.Two);
		[STAThread]
		static void Main(string[] args)
		{ 
			// Instatiate this class
			new SerialPortProgram();
		}

		private SerialPortProgram()
		{
			Console.WriteLine("Incoming Data:");

// Attach a method to be called when there is data waiting in the port's buffer
	port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

	// Begin communications
			port.Open();
	  
	// Enter an application loop which keeps this thread alive
			Application.Run();
		}

			private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
		{
	// Show all the incoming data in the port's buffer
		Console.WriteLine(port.ReadExisting());
		}
	}
}




i tried running this in Visual studio 2003 with 1.1 framework, but it showed errors. I then tried installing 2.0 framework. but it still shows errors. what to do?

Is This A Good Question/Topic? 0
  • +

Replies To: reading data from serial port

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: reading data from serial port

Posted 27 February 2007 - 07:44 AM

Can you please post the errors you have received?
Was This Post Helpful? 0
  • +
  • -

#3 cathy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 21-February 07

Re: reading data from serial port

Posted 28 February 2007 - 05:45 AM

I got errors stating that Ports was not an identified namespace.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1