Managed SerialPort class fails buy HyperTerm and msCom.ocx works

T

Tomppa

I've got an RS232 device that gives me data via hyperterminal but no data
comes acorss using my class below.

My hyperterm settings are as follows and appear to be the same as my
class?????
COM1
Bits per second 57600
Data bits 8
Parity None
Stop bits 1
Flow control None

I am able to open the port and it shows open but no data.

Any Ideas??????

I get the same results from my desktop framework or my embedded device in
the CF2.0

I tested it in VB6 using the MScomm ocx and it did recieve data. I
obviously cannot use this ocx in WinCE though.

public class RS232Device

{

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

public RS232Device()

{

port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

port.Handshake = Handshake.None;

port.ReceivedBytesThreshold = 1;

}

public bool Open()

{

bool ret = false;

port.Open();

if (port.IsOpen)

{

ret = true;


}

return ret;

}

public void Close()

{

if (port.IsOpen)

{

port.Close();

}

}

void port_DataReceived(object sender, SerialDataReceivedEventArgs e)

{

Debug.WriteLine(port.ReadExisting());

}

}
 
T

Tomppa

I also tried using using OpenNETCF.IO.Serial;

and I get a Create Fiel Failed: 2 on the open method of the port.


portSettings = new HandshakeNone();

port = new Port("COM1", portSettings);

port.Settings.BaudRate = BaudRates.CBR_57600;

port.Settings.Parity = Parity.none;

port.Settings.StopBits = StopBits.one;

port.DataReceived += new Port.CommEvent(port_DataReceived);


// these are fairly inefficient settings

// for a terminal we want to send/receive all data as it is queued

// so 1 byte at a time is the best way to go

port.RThreshold = 1; // get an event for every 1 byte received

port.InputLen = 1; // calling Input will read 1 byte

port.SThreshold = 1; // send 1 byte at a time

if (port.IsOpen)

{

port.Close();

}


port.Open();
 
T

Tomppa

I just ported the OpenNETCF.IO.Serial code to the desktop and it works!
If I could resolve the fole Create File issue then I think I'm on my way.

Running WinCE5.0 and CF 2.0 also using OpenNetCF (current version)

THX
 
T

Tomppa

I had to add

port.DtrEnable = true;

port.RtsEnable = true;

to enable the RS232 hardware.....



Using the MS namespace now
 
D

Dick Grier

Your device may require that DTR and RTS be set to True.

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.
 
D

Dick Grier

Ah, I see that you found the solution. This is a common problem.

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.
 

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