473,503 Members | 12,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

comm port input bytes getting...randomly?...offset by 128

I'm having an odd problem where im reading input from a comm port (the
maker of the software that exports the data TO the comm port is
unhelpful).

What im reading is fixed length (13 character) sets of data seperated
by CR/linefeed. At first, it simply seemed like i was getting messed
up data, due to encoding it wrong, or using the wrong font, or
something like that, but it turns out, when i analyze the byte stream,
that the data i get is, for example:
160 160 51 57 183 54 48 204 78 77 141 10

which would translate to (in terminal font) "àà39·60ÌNM?<LF>"

however, notice, if you subtract 128 from all the bytes larger than
127, you get
32 32 51 57 55 54 48 76 78 77 13 10

which would translate to " 39760LNM<CR><LF>"
which IS exactly the data we expect to get.

So, my question is,...does anyone know why in the world the data from
the commport (read using ReadByte()), would have various characters
offset by 128?

Dec 21 '05 #1
4 2615
Hi,

Ic************@gmail.com wrote:
So, my question is,...does anyone know why in the world
the data from the commport (read using ReadByte()), would
have various characters offset by 128?


Incorrect data/parity/stop bit settings for the port. It's been a long time
since my serial terminal days, but I recall those being off producing
precisely that sort of result.

I'd further guess that you have left the port at default 8-N-1, but your
hardware device is trying to send 7-E-1. The SerialPort class has
properties for these (DataBits, Parity, StopBits).

--
Chris Priede

Dec 21 '05 #2
Thanks so much! This immediately fixed the problem. I had in fact
tried setting bits to 7, as it would make a lot of sense for that to be
the problem, but the comm port wouldnt open. I didn't try messing with
the various other comm port options in conjunction with that change
though. How did you know 7-E-1 would be the right combination?

Dec 21 '05 #3
Ic************@gmail.com wrote:
How did you know 7-E-1 would be the right combination?


The parity bit your UART wasn't expecting was becoming your 8th data bit (if
the total number of bits between start and stop was off, you'd be getting
framing errors). When the parity bit happened to be 0, you wouldn't even
notice. When the parity bit happened to be 1, of which there is about 50/50
chance... :)

Between that and no one ever using odd parity, it was an easy guess. I'm
glad it worked out.

--
Chris Priede
Dec 21 '05 #4

"Chris Priede" <pr****@panix.com> wrote in message
news:uB**************@TK2MSFTNGP11.phx.gbl...
Ic************@gmail.com wrote: ....
Between that and no one ever using odd parity, it was an easy guess. I'm
glad it worked out.


You don't have to guess, as converting sample numbers to binary would show
that every number has even number of bits set :).

Regards,
Goran

Dec 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3943
by: al | last post by:
Hi, I am creating an application in access 97, so coding in vba. I am at the stage of sending values to my external machine, but am stuck at a point. I need to send each character at an...
1
3627
by: sarath1111 | last post by:
hi all, I am using comm port for serial communication between 2 PC's using C language. Once I have initialized the COMM port, Is there any option of closing the port in C language. Thanks in...
7
2731
by: Michael Chong | last post by:
I wrote a program that communicate with SerialComm. In every 300 milliseconds, my program continuously send & receive data via the serial port once the program starts. My program is once in a...
6
2831
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
3
4771
by: Amjad | last post by:
Hi, I'm working on an application that sends and receives data over the serial port using the MSComm control. How do I empty the buffer of the received data and how do I set its size? Are there...
9
14244
by: Mircea | last post by:
Hi everybody, I have a big problem. I am trying to use serial communication in C# 2. The problem is that the event DataReceived is never fired. I have tried on two computers and it does not...
8
16324
by: Vivek Menon | last post by:
Hi, I am using a C program to write/read from a serial port. The writing part is working perfectly fine. However, I am not able to read the values correctly and display them. To debug this issue I...
2
10261
by: herat007 | last post by:
hi , i have developed a prog in vb to send sms , but i get an error error:8020 "Error reading from comm port" my prog for mscomm_oncomm() is Private Sub MSComm1_OnComm() Dim strMessage As...
4
4210
by: skunapareddy | last post by:
I am needing to read a blob from database and pass it to another java program. I researched internet and found a program that reads a file on the client pc and gives bytes, but when I modified the...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
405
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.