serial Port, what is wrong ?

R

Rainer Borchmann

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
 
M

Michael Rubinstein

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
 
R

Rainer Borchmann

Michael Rubinstein said:
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
 
M

Michael Rubinstein

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 said:
Michael Rubinstein said:
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
 

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