How to read and write serial port using C#

D

Dick Grier

You also can download DesktopSerialIO from my homepage for Framework 1.x.

The System.Ports.IO namespace works fine for Visual Studio 2005 (Framework
2) applications.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
D

Dick Grier

Whoops. I meant CFSerialIO for Compact Framework 1.x from my homepage.
DesktopSerialIO offers the same api for desktop apps.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
D

Dick Grier

IMO, Bluetooth is a nascent technology. The various implementations (still,
after several years) leave a lot to be desired. Have you seen similar with
hardware serial ports? I haven't.

Divk

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
P

Paul Metcalfe

Hi Dick,

Thanks for replying to my post about memory loss when using VB
system.io.ports/SerialPort to receive data.

I can believe you in that it is device-specif problem and I'm talking
to the manufacturer in Germany, without any luck so far.

But I'm very new to .net and would aprcieate your advice;

Obvisouly there's a driver for the serial port sitting between .net and
the hardware, but is this provided by MS or the manufacturer? Is it
something that I can get at or replace?

There seems very little diagnostic info within CF with regards to
memory usage etc, so I'm really poking around in the dark, but i need
to get this resolved somehow.

Don't supose you or anyone can point me at an alterntive serial port
solution for VB/CF2.0 that avoids the driver I'm having issue with?

Many thanks for your help.

Paul.
 
G

Guest

The OEM writes that driver. There's no way to really replace it (well if
you had a new one you could adjust the registry to use it, but the new one
would come from the OEM anyway). There's no real way around it.

There's also no guarantee it's the driver. The OAL might have a problem
where it's handling serial interrupts too.

In short, only the OEM can fix this.

-Chris
 
D

Dick Grier

Hi,
Obvisouly there's a driver for the serial port sitting between .net and
the hardware, but is this provided by MS or the manufacturer? Is it
something that I can get at or replace?
<<

Microsoft provides information in its documentation to create the serial
driver by the manufactuer. If they make a mistake, there is nothing you or
I can do except to ask them for help (demand?).

Certainly there are things that your application might be doing that could
cause a memory loss, too. Perhaps a first step would be to write the
simplest code that simply opens the port, reads data into a dummy variable
(without processing it) and continues that way. If you see some sort of
memory loss with this simple scenario -- where your code does NOTHING, then
the place to look is in the lower level routines (OEM). However, if you
don't see a problem with this, then... Look higher. And, I don't mean,
pray.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Joined
Sep 23, 2007
Messages
5
Reaction score
0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Timers;

namespace serial
{
public partial class Form1 : Form
{
SerialPort sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

int number;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
sp.Open();
}

private void timer1_Tick(object sender, EventArgs e)
{
if (number!=900)
{
number = number + 1;
if (number < 300)
{
sp.WriteLine(number.ToString());
label1.Text = number.ToString();
}
//label2.Text = sp.ReadLine();



}

}

private void button1_Click(object sender, EventArgs e)
{
number = 900;
sp.Close();

}

private void timer2_Tick(object sender, EventArgs e)
{
if (number != 900)
{
//sp.WriteLine(number.ToString());

label2.Text = sp.ReadLine();


}
}
}
}
 
Joined
Sep 23, 2007
Messages
5
Reaction score
0
Can any one tell me a way to detect serial port interrupts using visual C#.

Can any one tell me a way to detect serial port interrupts using visual C#.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top