473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Net 2 Serialport OnDataReceived


Hi,

I've really struggled with this. Using Hyperterminal everything works fine.
But if I write my own program I can't get "OnDataReceived" to be fired.

MS samples from the SDK gives me the same result. I can read data by waiting
and whiling - but that's just bad. I want to use the Event!

I get the same problem in Winforms and in a Console app.

I Use Vista 64 bit ( but as I said, works fine in Hyperterminal ).

I've tried VS 2005 and VS 2008B2.

Here is the code for my simplified console app: <<-- Please HELP :-)

-------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;

namespace conSer
{
class Program
{
static public SerialPort sp;

static void Main(string[] args)
{
sp = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
sp.DtrEnable = true;

sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);

sp.Open();

Console.WriteLine("Port open\r\n");

bool going = true;

while (going)
{
string cmd = Console.ReadLine();

if (cmd.Equals("info"))
{
Console.WriteLine("Read: " + sp.BytesToRead.ToString() + " Write: " +
sp.BytesToWrite.ToString() + "\r\n");
}

if (cmd.Equals("bye"))
going = false;
else
sp.Write(cmd);
}

if (sp.IsOpen)
sp.Close();
sp.Dispose();

}

static void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Console.WriteLine("Reading");
Console.WriteLine( sp.ReadExisting() );
}
}
}

Sep 26 '07 #1
1 2319
Lars,

Serialports are not my sport, however it is from Dick Grier

Have a look at it.

http://www.hardandsoftware.net/

Cor

Sep 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrea Judge | last post by:
Hi there, I'm developing an application to catch OBD sensors' data from my car. I connect it via a RS232 interface. Now. with HyperTerminal I can connect and send/receive data, but I'd like to...
0
by: Joshua Moore | last post by:
I'm trying to convert from a lot of invoked code to c# 2.0 SerialPort code. I can't find a way to set fOutxCtsFlow to true (maybe CTSEnable?) and fRtsControl = RTS_CONTROL_HANDSHAKE (RtsEnable?). ...
13
by: Jean Paul Mertens | last post by:
Hello, Someone can tell me why I dont get serial port events in a Service, I created a separate Thread to open the port but no events are coming up (the same happens when I use the timer...
1
by: sranger | last post by:
When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then close the...
0
by: ricolee99 | last post by:
Hi Everyone, I'm using the System.IO.Ports.SerialPort component to attempt to kill an existing component opened by another application. I use the following code: SerialPort serialPort = new...
2
by: Jay | last post by:
Extracted from the C# example in http://msdn2.microsoft.com/en-us/library/s14dyf47.aspx... public static void Main() { string name; string message; StringComparer stringComparer =...
3
by: Adriano | last post by:
Hello, I'm developing an application in VB.NET 2005 that communicates with a device through RS232, and need to send the following sequence of hexadecimal data to the device: 0xFF, 0x01, 0xC3,...
6
by: Keith Lee | last post by:
All: I am attempting to compile the perl module Device::SerialPort and get this error during make -- Manifying blib/man3/Device::SerialPort.3pm Can't open blib/man3/Device::SerialPort.3pm for...
0
by: =?Utf-8?B?TGVuIFdlbHRtYW4=?= | last post by:
I've created MySerialPort, which inherits from SerialPort, and want to set an internal flag when DataReceived is signalled. If I were firing the event myself, it would be a simple matter of flag...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.