How to apply encoding when reading from a serial port

Posted by rross on Stack Overflow See other posts from Stack Overflow or by rross
Published on 2010-04-26T15:09:05Z Indexed on 2010/04/26 15:13 UTC
Read the original article Hit count: 206

Filed under:
|
|

I'm reading data from a serial port. I read this posting: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/a709d698-5099-4e37-9e10-f66ff22cdd1e

He is writing about many of the issues I have encounter, but in his writing he refers to using: System.Text.Encoding.GetEncoding("Windows-1252"). The problem I'm having is when and how to apply this. There are three potitional spots in my opinion. When the serial port object is define:

private SerialPort comport = new SerialPort();

The Event handler:

comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);

Or when reading the data:

string data = comport.ReadExisting();

No matter where I add it. I seem to get errors. How would one use Encoding?

© Stack Overflow or respective owner

Related posts about c#

Related posts about serial-port