Author Topic: 0x0D & 0x0A RS232 communication  (Read 31160 times)

Mitmel

  • Member
  • ***
  • Posts: 4
0x0D & 0x0A RS232 communication
« on: November 07, 2011, 12:32:14 pm »
Hi Everyone,

I´m using the mscomm control included in Visual Basic to perform a serial comunication with the 8051 microcontroller.  The problem is I read back an invalid result (or line feed) everytime the data is 0x0A.  It's suppose to be 0x0A but read back as 0x0D and 0x0A.  How can I fix this?  Is there an example of the code that you can share?

Thanks,

Mitmel

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: 0x0D & 0x0A RS232 communication
« Reply #1 on: November 07, 2011, 12:49:46 pm »
Post the code that gets the input with the added ODh.

Jan

Mitmel

  • Member
  • ***
  • Posts: 4
Re: 0x0D & 0x0A RS232 communication
« Reply #2 on: November 14, 2011, 11:56:57 pm »
Hi Jan,

Thanks for the reply.  Can I send you the zip file so you can look at it?  If so, can I have your email?

Thanks

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: 0x0D & 0x0A RS232 communication
« Reply #3 on: November 15, 2011, 12:53:50 pm »
Post the relevant excerpt here.

Jan

Mitmel

  • Member
  • ***
  • Posts: 4
Re: 0x0D & 0x0A RS232 communication
« Reply #4 on: November 17, 2011, 03:02:17 pm »

Hi Jan,

Here's my code:

==================

If rbcomm1(0) = true then
    port = 1
else
    port = 2
end if

me.comm1.commport = port

if me.comm1.portopen = false then
    me.comm1.portopen = true
end if

comm1.settings = "9600,n,8,1"
comm1.inputlen = 1

reg_00 = Asc(serial_device.comm1.input)

==============================

When reg_00 = 0x0A, it reads as 0x0D and 0x0A.  Sometimes it hang up.  I appreciate your help.

Mitch




Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: 0x0D & 0x0A RS232 communication
« Reply #5 on: November 17, 2011, 03:37:01 pm »
What do you mean by "it reads as 0x0D and 0x0A."? Post the code where "it" reads the two values.

Jan

Mitmel

  • Member
  • ***
  • Posts: 4
Re: 0x0D & 0x0A RS232 communication
« Reply #6 on: November 17, 2011, 05:48:44 pm »

Hi Jan,

The code is incldued in the last description.

reg_00 = Asc(serial_device.comm1.input)


The above command is read from the serial port


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: 0x0D & 0x0A RS232 communication
« Reply #7 on: November 17, 2011, 05:56:16 pm »
Asc Returns an Integer value representing the character code corresponding to a character.

Where are you seeing two character codes?

If this:

Asc(serial_device.comm1.input)

returns 0Dh, the remote device is sending the value.

Jan
« Last Edit: November 18, 2011, 10:48:17 am by Jan Axelson »

WestfW

  • Member
  • ***
  • Posts: 8
Re: 0x0D & 0x0A RS232 communication
« Reply #8 on: November 26, 2011, 04:20:13 am »
It's pretty common for "lines of text" to be terminated (on a serial line) with both a CR (0x0D) and a LF (0x0A) when the file (unix?) contains only LF (aka "\n")   that's because a vast number of actual serial devices (printers, crt terminals, etc) require both operations (CR == Carriage return == set column to 0, LF == Line Feed == Advance to next line.)

866JR

  • Member
  • ***
  • Posts: 5
Re: 0x0D & 0x0A RS232 communication
« Reply #9 on: December 04, 2011, 09:11:33 am »
I have been using MScomm for several years with VB6. The MScomm control won't add any characters. I would guess that your 8051 is sending back the 0D & 0A (CR LF) combo. I suggest checking your firmware carefully.