MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

serial Port, what is wrong ?

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> C Sharp
Author Message
Rainer Borchmann



Joined: 22 Nov 2007
Posts: 14

PostPosted: Wed Dec 12, 2007 6:25 pm    Post subject: serial Port, what is wrong ? Reply with quote

Hi,
please can anyone tell me what is wrong with this code ?
i have an oszilloskop on the COM1 ,and nothing comes out of it.
Rainer
VS2005
..............................
private void button1_Click(object sender, EventArgs e)

{

// Instantiate the communications // port with some basic settings

SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8,
StopBits.One);

// Open the port for communications

port.Open();

// Write a string

port.Write("Hello World");

//// Write a set of bytes

port.Write(new byte[] { 0x0A, 0xE2, 0xFF }, 0, 3);

// Schliessen COM1

port.Close();

}

......................................

Thank you

Rainer

Archived from group: microsoft>public>dotnet>languages>csharp
Back to top
View user's profile Send private message
Michael Rubinstein



Joined: 11 Aug 2007
Posts: 4

PostPosted: Wed Dec 12, 2007 1:12 pm    Post subject: Re: serial Port, what is wrong ? Reply with quote

Hi Rainer. After issuing port.Open() I would check if it is open.

if (port.IsOpen)
{
port.Write("Hello World") // "Hello World\r" ???
port.Write(new byte[] { 0x0A, 0xE2, 0xFF }, 0, 3);
port.Close();
}
else
System.Media.SystemSounds.Asterisk.Play() //cry

Also, make sure that you use the right port. In newer machines it is quire
rare having a serial connector associated with COM1.

Michael

"Rainer Borchmann" wrote in message
news:%23fZ$JoLPIHA.3532@TK2MSFTNGP04.phx.gbl...
> Hi,
> please can anyone tell me what is wrong with this code ?
> i have an oszilloskop on the COM1 ,and nothing comes out of it.
> Rainer
> VS2005
> .............................
> private void button1_Click(object sender, EventArgs e)
>
> {
>
> // Instantiate the communications // port with some basic settings
>
> SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8,
> StopBits.One);
>
> // Open the port for communications
>
> port.Open();
>
> // Write a string
>
> port.Write("Hello World");
>
> //// Write a set of bytes
>
> port.Write(new byte[] { 0x0A, 0xE2, 0xFF }, 0, 3);
>
> // Schliessen COM1
>
> port.Close();
>
> }
>
> .....................................
>
> Thank you
>
> Rainer
>
>
>
>
>
>
>
>
>
>
Back to top
View user's profile Send private message
Rainer Borchmann



Joined: 22 Nov 2007
Posts: 14

PostPosted: Thu Dec 13, 2007 7:52 pm    Post subject: Re: serial Port, what is wrong ? Reply with quote

"Michael Rubinstein" schrieb im Newsbeitrag @mid.individual.net...
> Hi Rainer. After issuing port.Open() I would check if it is open.
>
> if (port.IsOpen)
> {
> port.Write("Hello World") // "Hello World\r" ???
> port.Write(new byte[] { 0x0A, 0xE2, 0xFF }, 0, 3);
> port.Close();
> }
> else
> System.Media.SystemSounds.Asterisk.Play() //cry
>
> Also, make sure that you use the right port. In newer machines it is quire
> rare having a serial connector associated with COM1.
>
> Michael

Hi Michel,
its well to have you as an good angel here in this newsgroup. And i got my
error. i have to send a RTS and a DTR signal to the Datacollecting station.
The working code ist here:





Button Senden



SerialPort sp = new SerialPort("COM8", 9600, Parity.None, 8, StopBits.One);







sp.WriteBufferSize = 2048;

sp.ReadBufferSize = 2048;

//sp.Encoding = Encoding.ASCII;





sp.Open();

sp.RtsEnable = true ;

sp.DtrEnable = true;





// Messsode Aufwecken

sp.Write(new byte[] {0x00,0x00,0x00 }, 0, 3);





//sp.ReadTimeout = 500 ;



sp.DtrEnable = false;





sp.Close();



// Button Senden Ende
Back to top
View user's profile Send private message
Michael Rubinstein



Joined: 11 Aug 2007
Posts: 4

PostPosted: Thu Dec 13, 2007 8:17 pm    Post subject: Re: serial Port, what is wrong ? Reply with quote

Glad you solved your problem. Must be legacy hardware you are working
with - using RTS DTR signals. C# Serial class is pretty good. You can easily
write your own Serial Terminal for testing or troubleshooting.

Michael

"Rainer Borchmann" wrote in message
news:%23Dsyg9YPIHA.5720@TK2MSFTNGP04.phx.gbl...
>
> "Michael Rubinstein" schrieb im
> Newsbeitrag @mid.individual.net...
>> Hi Rainer. After issuing port.Open() I would check if it is open.
>>
>> if (port.IsOpen)
>> {
>> port.Write("Hello World") // "Hello World\r" ???
>> port.Write(new byte[] { 0x0A, 0xE2, 0xFF }, 0, 3);
>> port.Close();
>> }
>> else
>> System.Media.SystemSounds.Asterisk.Play() //cry
>>
>> Also, make sure that you use the right port. In newer machines it is
>> quire rare having a serial connector associated with COM1.
>>
>> Michael
>
> Hi Michel,
> its well to have you as an good angel here in this newsgroup. And i got my
> error. i have to send a RTS and a DTR signal to the Datacollecting
> station.
> The working code ist here:
>
>
>
>
>
> Button Senden
>
>
>
> SerialPort sp = new SerialPort("COM8", 9600, Parity.None, 8,
> StopBits.One);
>
>
>
>
>
>
>
> sp.WriteBufferSize = 2048;
>
> sp.ReadBufferSize = 2048;
>
> //sp.Encoding = Encoding.ASCII;
>
>
>
>
>
> sp.Open();
>
> sp.RtsEnable = true ;
>
> sp.DtrEnable = true;
>
>
>
>
>
> // Messsode Aufwecken
>
> sp.Write(new byte[] {0x00,0x00,0x00 }, 0, 3);
>
>
>
>
>
> //sp.ReadTimeout = 500 ;
>
>
>
> sp.DtrEnable = false;
>
>
>
>
>
> sp.Close();
>
>
>
> // Button Senden Ende
>
>
>
>
>
>
>
>
>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Serial Port Hi, how can I use Serial Port, using a framework native code. I dont want to use P/Invoke. Tks, Thiago

How to get the port number when port = 0? I have created a with port number = 0 and registered it! Now how can I find out the port that is bind to it?

C++ to C# Port I am trying to use a 3rd party Dll in my C# project and am not sure I am porting everything correctly. I get what seems to be the correct information from the Dll Definded callback (not shown) but Data and DataSize are always 0. C++ Code

DateTimePicker gives wrong value If you type a year into a DTP as less than 4 digits (eg 02) and then tab out of the DTP, the control shows the new year as 2002 but the Leave, Validating and Validated events give the original year (eg 2003) in Value. After these events are raised, a Valu

what's wrong with this code? Hi, I want to limit the amount of data shown in a page coming from a database. Everything works except that I get the error: "Unable to cast object of type to type on line: PageDa
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> C Sharp All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group