Serial port encoding

J

Jack Russell

I am trying to use the serial port control to send and receive 8 bit
characters to/ from a n instrument. whatever I set encoding to it
converts the characters.

Any ideas how to stop it?

Thanks

Jack Russell
 
A

Armin Zingler

Jack Russell said:
I am trying to use the serial port control to send and receive 8 bit
characters to/ from a n instrument. whatever I set encoding to it
converts the characters.

Any ideas how to stop it?

Can you give an example of the sent/received data? How did you find out that
it gets converted? How do you send the data (code)?


Armin
 
J

Jack Russell

Armin said:
Can you give an example of the sent/received data? How did you find out
that it gets converted? How do you send the data (code)?


Armin
I use a serialport sniffer program
(http://www.serial-port-monitor.com/index.html)
fantastic piece of freeware.

To output I use
serialport1.write(String)

I have found that if I set encoding to zero it seems to work
serailport1.encoding=encoder.getencoding(0)
although the documentation seems to state this is an illegal operation!
 
A

Armin Zingler

Jack Russell said:
I use a serialport sniffer program
(http://www.serial-port-monitor.com/index.html)
fantastic piece of freeware.

To output I use
serialport1.write(String)

I have found that if I set encoding to zero it seems to work
serailport1.encoding=encoder.getencoding(0)
although the documentation seems to state this is an illegal
operation!

Which encoding does the device expect?


Armin
 
J

Jack Russell

Armin said:
Which encoding does the device expect?


Armin
This is the point, I and a lot of other people use serial ports to
transmit binary data, we do not want any encoding. According to the help
files the default is 7 bit ascii, but you can set the various unicode
alternatives. The help file says that setting 0 gives the "default"
which is patently not true
 
A

Armin Zingler

Jack Russell said:
This is the point, I and a lot of other people use serial ports to
transmit binary data, we do not want any encoding.

If you send strings, they /do/ have an encoding. Every character does have a
number (one or two bytes).

Only zero-length strings don't have an encoding. :)
According to the
help files the default is 7 bit ascii, but you can set the various
unicode alternatives. The help file says that setting 0 gives the
"default" which is patently not true

"Default" usually means "ANSI" code page, which you can get from
System.Text.Encoding.Default.

In any case you must know which encoding the receiver expects.

As you probably know, Strings are stored as Unicode (2 bytes), so if you
want to send them with any other encoding, you must convert to an array of
bytes (Encoding.GetBytes).


Armin
 
J

Jack Russell

Armin said:
If you send strings, they /do/ have an encoding. Every character does
have a number (one or two bytes).

Only zero-length strings don't have an encoding. :)



"Default" usually means "ANSI" code page, which you can get from
System.Text.Encoding.Default.

In any case you must know which encoding the receiver expects.

As you probably know, Strings are stored as Unicode (2 bytes), so if you
want to send them with any other encoding, you must convert to an array
of bytes (Encoding.GetBytes).


Armin
Sorry, I am not sending "strings" I am sending binary data. This is very
common with serial port applications. I want the 8 bits to be sent
exactly as is with no "translation". Every other serial port "driver" I
have ever seen can do this why cant .net
 
A

Armin Zingler

Jack Russell said:
Sorry, I am not sending "strings" I am sending binary data.


You wrote:

serialport1.write(String)


I thought String means String. Now you write, you don't send a String.
What's right now?


Armin
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Jack said:
This is the point, I and a lot of other people use serial ports to
transmit binary data, we do not want any encoding. According to the help
files the default is 7 bit ascii, but you can set the various unicode
alternatives. The help file says that setting 0 gives the "default"
which is patently not true

The solution is very simple. If you want to send binary data, send
binary data. Don't send it as a string, send it as a byte array.
 
J

Jack Russell

Göran Andersson said:
The solution is very simple. If you want to send binary data, send
binary data. Don't send it as a string, send it as a byte array.
Thanks, just what I wanted. I should have fully read the help file I
suppose, too many years of fooling devices so it never occurred to me it
would be that easy!

Thanks again

Jack Russell
 

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

Similar Threads


Top