0

I have an old VB6 program that opens COM1 for serial port reading only; To initialize the COM1 serial port I do the following on Form_Load() event:

commStats.ComPort = 1
commStats.Settings = "9600,N,8,1"
commStats.InputMode = comInputModeText
commStats.InputLen = 0
commStats.PortOpen = True

I read the serial port on a timer event and parse the input buffer - the packet I receive is very simple; starts with an STX and ends with a ETX all the bytes between the STX and ETX are ASCII printable characters. The packet is not very big maybe 100 bytes at most.

I have been reading this packet for years on my ASUS XP laptop during development, debug, and testing without a problem. For the first time in about 2 years I went back to doing some testing of the program and started testing sending these packets to this program again. To my surprise I was getting errors parsing the packets and discovered that when the packet had 3 ASCII zeros in a row the third zero was not a zero but a degree symbol in my VB6 receive packet?

I thought it was the computer sending the data packets so I went into HyperTerminal on the receiving computer and used HyperTerminal to view the received packets but did not see the degree symbol in HyperTerminal. So I exited HyperTerminal and went back to my VB6 program and started the test over and the packet was correct no more degree symbols for every 3rd ASCII zero in the packet they were ASCII zeros.

Can anyone explain what might have happened - it appears to me that HyperTerminal changed some setting of the COM1 serial port that fixed the problem? I have been trying to recreate the problem so I know what the root cause was; I have a straight C program that uses the old Win32 API and DCB structure to modify the serial port settings and as yet I can not recreate the problem described above

Any ideas how that serial port got into a mode to do what was described above?

Here is what a received packet in VB6 looks likes now that it is arriving with no degree symbol:

"STX6C1505 3008019003008004004001003005005001005000023032004005003006000013004000HTaurasi, Diana                  15F5ETX"

work your way over to the part of the packet above where you see 1005000023 - that 3rd ASCII zero after the 5 was a degree symbol and all other packets that had 3 ASCII zeros in a row the 3rd ASCII zero was converted to a degree symbol - in VB6 debug watcher when it was wrong as reported above initially it look like this:

100500°023

What I am trying to do is figure out how that happened?

Neal Davis
  • 648
  • 6
  • 21
  • Can you show all the decimal values for a received packet that contains the three 0x0 bytes? That's not representative of printable ASCII ... – Alex K. Dec 20 '16 at 11:09
  • Without being able to consistently reproduce the problem it's going to be difficult to diagnose. Is it at all possible that the sending computer was temporarily sending incorrect data? – Guillermo Phillips Dec 20 '16 at 17:34
  • Hello - I put a sample of what it looks like correctly and what it looked like when it was wrong in the VB6 debug watcher. I do not believe the sending computer was temporarily sending incorrect data - I was using HyperTerminal on the sending computer to send a text file. The text file was always the exact same file. Both computers I'm using a USB to serial adapter; could it be that one of these was doing this but why did it seem to correct its self after entering and exiting HyperTerminal on the receive computer? – Neal Davis Dec 20 '16 at 17:41
  • @AlexK. - I edited my text above to show the VB6 packet as shown in the debug watcher of VB6. When I copy this packet data to HxD editor those zeros are ASCII 0x30 values so truly are a zero character. – Neal Davis Dec 20 '16 at 18:43
  • @GuillermoPhillips - See my comment above, I believe the data sent from the sending computer was always identical. I suppose it is possible what was coming out of the USB serial adaptor on the sending computer might have been incorrect but then why would it have corrected itself if all I changed was entering and exiting HyperTerminal on the receive computer? – Neal Davis Dec 20 '16 at 18:47
  • 1
    One thing to note is that it's only a one bit difference in the (binary) ASCII representation of the degree symbol and a zero character, namely: for zero, 00110000 and for degree, 10110000. Data is sent LSB first, something like startbit+b0+...+b7+stopbit. So the spurious 1 would have been bit 7. The stopbit is sent as a mark (1). – Guillermo Phillips Dec 21 '16 at 10:21
  • This question my shed some light: http://stackoverflow.com/questions/27174898/unusual-pattern-of-data-corruption-over-serial-port?rq=1 – Guillermo Phillips Dec 21 '16 at 12:46
  • @GuillermoPhillips - good find! that almost certainly answers my problem; I was using a saved HT configuration on the sending computer. – Neal Davis Dec 21 '16 at 16:58

0 Answers0