Problem With Extended ASCII processing.
Problem With Extended ASCII processing.
am 09.10.2007 10:44:01 von RoshanRD
Hi All,
I am new to C# programming; I am developing an application for recording
audio data using voice modem.
I am using HyperTerminal to manually process audio data. The modem when
configured in voice record mode sends the audio (PCM) data on the serial
port, few of the characters from these are in Extended ASCII range i.e. more
than 127 decimal.
In HyperTerminal we can reset the property to force the incoming data to 7
bit ASCII, i.e. by un-checking this option we can record the Extended ASCII
also.
When I am using the C# application I am reading from serial port using
serialPort1.ReadExisting () --- this returns the complete received string or
serialPort1.Read(recevBuff, 0, buffLength)---- this returns received
characters in the recevBuff. The problem is by using both these methods the
extended ASCII characters are rounded off automatically to 7 bit ASCII and I
get the wrong response. I have even tried using the Encoding class with
Encoding.Default property but this does not give me the correct corresponding
Extended ASCII character in the response.
I have a plan to store this received data to a file but things are not
working due to this conversion problem. Can anybody help?
Thanks & Regards
Roshan.
Re: Problem With Extended ASCII processing.
am 09.10.2007 11:42:03 von skeet
On Oct 9, 9:44 am, Roshan R.D
wrote:
> I am new to C# programming; I am developing an application for recording
> audio data using voice modem.
> I am using HyperTerminal to manually process audio data. The modem when
> configured in voice record mode sends the audio (PCM) data on the serial
> port, few of the characters from these are in Extended ASCII range i.e. more
> than 127 decimal.
There's no such thing as "Extended ASCII". Or rather, there are
various encodings which use ASCII for the first 127 values, but which
do different things
However, you shouldn't be using text at all to receive *binary* data
(such as audio). You should be reading *bytes*, not characters. Pass a
byte array into Read instead of a char array and things are likely to
start working.
Jon
Re: Problem With Extended ASCII processing.
am 09.10.2007 12:50:00 von RoshanRD
Hello Jon,
Thanks for your reply; My problem is solved now I am able to convert the
response bytes to proper Extended ASCII characters. I have used
System.Text.ASCIIEncoding.Default.GetString(recBuffer) property to convert to
Ext ASCII.
I was actually using bytes array to read from serial port, then I am
converting it to string using the above method. I am doing this to remove
'\0', '\r', and '\n' characters from the incoming string to get a disturbance
free response.
Regards
Roshan
"Jon Skeet [C# MVP]" wrote:
> On Oct 9, 9:44 am, Roshan R.D
> wrote:
> > I am new to C# programming; I am developing an application for recording
> > audio data using voice modem.
> > I am using HyperTerminal to manually process audio data. The modem when
> > configured in voice record mode sends the audio (PCM) data on the serial
> > port, few of the characters from these are in Extended ASCII range i.e. more
> > than 127 decimal.
>
> There's no such thing as "Extended ASCII". Or rather, there are
> various encodings which use ASCII for the first 127 values, but which
> do different things
>
> However, you shouldn't be using text at all to receive *binary* data
> (such as audio). You should be reading *bytes*, not characters. Pass a
> byte array into Read instead of a char array and things are likely to
> start working.
>
> Jon
>
>
>
Re: Problem With Extended ASCII processing.
am 09.10.2007 14:28:08 von skeet
On Oct 9, 11:50 am, Roshan R.D
wrote:
> Thanks for your reply; My problem is solved now I am able to convert the
> response bytes to proper Extended ASCII characters. I have used
> System.Text.ASCIIEncoding.Default.GetString(recBuffer) property to convert to
> Ext ASCII.
That's a really bad way of doing it. There's no need for a text
conversion to start with, as far as I can see.
> I was actually using bytes array to read from serial port, then I am
> converting it to string using the above method. I am doing this to remove
> '\0', '\r', and '\n' characters from the incoming string to get a disturbance
> free response.
But voice data isn't text data to start with, surely - there shouldn't
be an "incoming string" there should just be incoming binary data.
Jon
Re: Problem With Extended ASCII processing.
am 09.10.2007 21:11:31 von Dick Grier
Hi,
You should use the Read method for binary data. ReadExisting should be used
only with ASCII - text. Use an array of type Byte to buffer receive data.
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.