background preloader

Ingeniería (Hydras)

Facebook Twitter

Serial Port Communication in C# The serial port is a serial communication interface through which information transfers in or out one bit at a time. A quick search on Google reveals that there are a lot of free serial port monitor applications available for PC users. However, what these applications lack, is the possibility of controlling the serial port in a direct manner. They are generally good “sniffers” but they do not allow the user to actually write to the serial port or control any device attached to it. The applications with the write capability encapsulated are not for free, and the cheapest costs about 50 Euro – a great deal of money taking into account how easy it is to make a personalized application.

This article will show how it is possible to build such an application using the C# environment. For the example application, I have used the SharpDevelop development environment which includes a C# compiler. You will notice that one of the components available here is the one called “SerialPort”. Serial Communication using C# and Whidbey. Introduction In this article, I will give you an introduction on how to do serial port communication on .NET platform using C#.

Serial Communication using C# and Whidbey

The .NET framework version 2.0 (beta) provides features for serial communication. The framework provides System.IO.Ports namespace. The new framework provides classes with the ability to access the serial ports on a computer, and to communicate with serial I/O devices. We will be using RS 232 C standard for communication between PCs. The Namespace The System.IO.Ports namespace contains classes for controlling serial ports. The SerialPort Class SerialPort class provides a framework for synchronous and event-driven I/O, access to pin and break states, and access to serial driver properties. Creating SerialPort Object. SerialPort (RS-232 Serial COM Port) in C# .NET - #region Coad's Code (Noah Coad) .NET has a great class called SerialPort (MSDN reference) part of .NET 2.0 and is freely available in C# Express on MSDN.

SerialPort (RS-232 Serial COM Port) in C# .NET - #region Coad's Code (Noah Coad)

It is easy to use. Here’s how… BTW, this article is about communicating through the PC's Serial COM RS-232 port using Microsoft .NET 2.0 or later by using the System.IO.Ports.SerialPort class. If you're looking for USB info, see here. Example Application & Sample Code: SerialPort Terminal Prerequisites: You will need Microsoft .NET 3.5 to run the app. To start off, here is sample code in a terminal application which you can try out to see how the SerialPort class is used.

Build Note: You will receive an error that Visual Studio isn't able to find NoahCode.pfx. Get Connected You can obtain USB to Serial adapters and have just about as many ports on your PC as you like. Write Data Out Here is an example of how easy it is to use the new SerialPort control. Read Data From Port Now let's take a look at what it takes to read data in from the communications port. Colabora.NET: Leyendo y escribiendo archivos de texto y binarios en C# .NET.

La lectura y escritura a un archivo son hechas usando un concepto genérico llamado stream.

Colabora.NET: Leyendo y escribiendo archivos de texto y binarios en C# .NET

La idea detrás del stream existe hace tiempo, cuando los datos son pensados como una transferencia de un punto al otro como un flujo de datos. Lectura y escritura de archivos en c# « DevelopMania. El manejo de archivos en la plataforma .NET se logra mediante la clase Stream que representa un flujo de información (Un archivo es considerado un flujo de datos, al igual que los datos transferidos de un dispositivo a otro, o los datos transferidos por la red mediante TCP/IP).

Lectura y escritura de archivos en c# « DevelopMania

La clase Stream, es una clase abstracta, por lo que no es posible utilizarla directamente ya que no se puede crear instancias. Lo que se debe hacer es utilizar una de sus clases derivadas que se especializan en el tratamiento de streams para diferentes destinos como por ejemplo FileStream (para el manejo de archivos), Memorystream (para el manejo de datos en memoria), etc. La primera opción para escribir y/o leer datos de una archivo de texto es utilizar la clase FileStream. Esta clase se encuentra en el namespace System.IO y es una clase derivada de la clase Stream. Como se ve en la figura anterior, es un constructor bastante tedioso de utilizar porque recibe una cantidad considerable de parámetros. Me gusta: