PORTS Forum
Ports and Interfaces => Serial Ports => Topic started by: Duss on December 08, 2011, 10:18:48 am
-
Is there some sort of hidden (unwanted) filtering in the RECEIVE part of the Com_port_terminal_vb example?
Whenever the receive stream contains a character greater than 0x7f, it displays it as a "?" or 0x3f
It is very disturbing for receiving "non-ASCII" data.
What is the workaround?
-
Try a different encoding. See:
http://msdn.microsoft.com/en-us/library/ms404377.aspx
Jan
-
I read through the Com_port_terminal_vb and only saw a reference to "encoding" as being "utf-8" and it was in the .XML files.
First question : are those machine-generated files or are they part of the program itself.
So, can they be user-modified?
-
Try:
port_name.Encoding = System.Text.Encoding.UTF8;
See:
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.encoding.aspx
The xml files are machine-generated. I didn't write them.
Also, if you want to read binary data, not text, see the SerialPort Read and Write methods for sending and receiving Bytes.
Jan
-
What I could see in the examples in http://msdn.microsoft.com/en-us/library/ms404377.aspx was that the Com_port_terminal_vb had NO EXPLICIT encoding scheme.
Those examples show that we have to EXPLICITLY declare an encoding scheme.
Thank you for the opportunity to search and find...
-
I found that using the UTF32 encoding scheme was much better for what I wanted to do. In fact the UTF8 encoding yields a bizarre representation of the values over 0x7f it actually puts a 0xC3 in front of each of those values over 0x7f, while for the lower values it yields one byte of data.
The UTF32 seems to be the KISS method :-))
In your previous response :
port_name.Encoding = System.Text.Encoding.UTF8;
would the "port_name" be the "serial_port_name" ??
-
Yes, I don't recall offhand what name I used in the COM port application.
Jan
-
In the MainForm.vb I added the following :
UserPort1.SelectedPort.Encoding = System.Text.Encoding.UTF32
But it did not change a thing when I did a test (loopback) with characters larger than 0x7f if I was working with VB 2008
BUT with VB 2010 it works... Exactly the same code but converted automatically by VB 2010.
I did not test ALL codes.
But VB 2010 gives me a "warning" that says :
"Property "encoding" does not return a value on all code paths. A null reference exception could occur at run time when the result is used"
When one says "basic" it isn't...
;-))
-
I decided to re-do it.
Re-starting the program, without any changes did not yield the same result
It does not work anymore!!!
The encoding has to be performed within the OpenComPort() procedure when the port is opened.
Then it shall work, even with VB 2008, contrary to what I have said before.
-
Thanks for reporting what you learned!
Jan
-
What you learn, you own.
So, why be alone?
;-))
-
Something works and the other does not.
With ANY encoding, I have problems transmitting (or receiving) certain unusual characters For example, in the VERY LOW range of values n the range of 0x08 to 0x0f, the values we "decode" are the following
SENT RECEIVED (decoded)
0x08 0x08
0x09 0x09
0x0a 0x0a
0x0b 0x0a
0x0c 0x0c
0c0d 0x0a
0x0e 0x0e
0x0f 0x0f
That gets extremely confusing if we are trying to make sense out of a received message from a robot or other "intelligent" device....
Does anyone have an idea of where it gets sticky?
-
I have tested something. The PHYSICAL OUTPUT of the RS232 port.
First, it is the ComPort that actually twiddles the sent characters.
How could I get the ComPort to send exactly the character I want?
I like intelligent devices but it looks as if this ComPort business is TOO intelligent for the task I want it to do ;-))
It does not sen the character 0x00, and also it does not transmit anything that comes after that character...
OK now, how do I get it to SEND exactly what I want and get what I receive? I also mean all the characters between 0x00 and 0xFF.
-
See the SerialPort Read and Write methods for sending and receiving Bytes (rather than text).
Jan
-
The.GetEncoding(0) got me 255 out of 256 good results. Only is left the Chr(0x00)
Thank you for the suggestion.
-
Jan,
The SerialPort Read and Write methods for sending and receiving Bytes (rather than text) were OK WITH using the GetEncoding(0)
I First made a complete test of ALL the 256 bytes, from 0x00 through 0xFF.
I have been able to send commands and receive the correct responses from the serial-interfaced device I want to command.
I now am waiting for your book to arrive
;-))