PORTS Forum
Ports and Interfaces => Serial Ports => Topic started by: Mitmel 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
-
Post the code that gets the input with the added ODh.
Jan
-
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
-
Post the relevant excerpt here.
Jan
-
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
-
What do you mean by "it reads as 0x0D and 0x0A."? Post the code where "it" reads the two values.
Jan
-
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
-
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
-
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.)
-
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.