473,770 Members | 6,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SerialPort question

Jay
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 = StringComparer. OrdinalIgnoreCa se;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
<snip>

I would have thought that the last line would need to be:

SerialPort _serialPort = new SerialPort();
Jan 9 '07 #1
2 1805
"Jay" <nospamwrote in message
news:%2******** *******@TK2MSFT NGP04.phx.gbl.. .
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 = StringComparer. OrdinalIgnoreCa se;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
<snip>

I would have thought that the last line would need to be:

SerialPort _serialPort = new SerialPort();
I didn't check the link, but probably the _serialPort property is just
declared outside this method.
Something like:

class blabla {
private static SerialPort _serialPort;

public static void Main() {
_serialPort = new SerialPort();
}

private static void AnotherMethod() {
// do something with _serialPort here
}
}

this way you can access the _serialPort property also from outside the main
method.

HTH
Fabrizio
Jan 9 '07 #2
Jay
OK, that makes sense. Thanks for your help.

Jay

"Fabrizio Romano" <sf*****@zerovo lt.comwrote in message
news:45******** *************** @reader4.news.t in.it...
"Jay" <nospamwrote in message
news:%2******** *******@TK2MSFT NGP04.phx.gbl.. .
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 = StringComparer. OrdinalIgnoreCa se;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();
<snip>

I would have thought that the last line would need to be:

SerialPort _serialPort = new SerialPort();
I didn't check the link, but probably the _serialPort property is just
declared outside this method.
Something like:

class blabla {
private static SerialPort _serialPort;

public static void Main() {
_serialPort = new SerialPort();
}

private static void AnotherMethod() {
// do something with _serialPort here
}
}

this way you can access the _serialPort property also from outside the main
method.

HTH
Fabrizio

Jan 10 '07 #3

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

Similar topics

6
17024
by: DraguVaso | last post by:
Hi, I'm experimenting with the Serial Port in VB.NET 2005. Although it isn't that easy to get any feedback from my COM-port as I thought it would be... How can I read all the Data that the port sends back? I tryed with SerialPort1.ReadLine, but that blocks the application and takes a lot of time (10 seconds!), I tryed SerialPort1.Read, but I have to read it into a buffer and has to indicate the count, but how do I know this?
0
8495
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?). Also, do I need to set the handshaking? Below is the old and attempted new (that continually gets a timeout error on read. I upped the read timeout, but it's way too long NOT for it to be a handshaking or other issue than the readtimeout...
3
1787
by: Eric | last post by:
Hi, In my application for PDA I use the serialport class to send data to a navigation computer of VDO Dayton. Everything works fine as long as it is connected to the nav-computer. When the nav-computer is not connected to the PDA, the program hangs. No exceptionerrors, no serialports error events, nothing. Even if I set the WriteTimeOut property to 500, I still don't get any messages.
13
7822
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 component, using the System.Timers.Timer it works fine) tnx in advance Jean Paul
0
385
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 SerialPort ("COM1"); if(serialPort.IsOpen)
3
31283
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, 0xE3, 0xFF, 0xFF. That's the configuration:
2
5498
by: egress | last post by:
Forgive me for stupid questions for I am new to serial IO programming. I am developing an app that will need to communicate with a device via RS232 protocol using a standard 9 pin serial cable. From what I understand this can be accomplished relativly easy using .net 2.0 SerialPort component over a COM port. My question: because most newer computers don't have 9 pin serial ports (COM), can the SerialPort component use a USB connection...
6
5421
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 writing: Invalid argument at /usr/lib/perl5/5.8.8/ExtUtils/Command/MM.pm line 132 make: *** Error 22 $ make all Manifying blib/man3/Device::SerialPort.3pm Can't open blib/man3/Device::SerialPort.3pm for writing: Invalid argument
10
18254
by: sklett | last post by:
I'm trying to send some printer commands (ZPLII) to an attached USB printer using the SerialPort component. I didn't get very far at all. In fact I haven't gotten anywhere. The first problem I encountered is that a call to SerialPort.GetPortNames() returns an empty string. In other words, NO port names are returned. I'm not terribly knowledgable about ports but from the Hardware Manager I did notice that I don't have the Ports and...
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10057
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.