Link to home
Start Free TrialLog in
Avatar of mobsos
mobsos

asked on

Getting a spoiled text when reading from COM port!

In order to communicate with an external device through COM port, I used MS Comm to do that. I can send and receive data from that device, but the problem is the text I receive from that port is spoiled! any solutions?

Attached a picture demonesterates the spoiled text, and also attached the code I've used!
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, MSCommLib_TLB;
 
type
  TForm1 = class(TForm)
    MSComm1: TMSComm;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure MSComm1Comm(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  try
    MSComm1.CommPort := 3;
    MSComm1.Settings := '9600,N,8,1';
    MSComm1.InputLen := 0;
    MSComm1.RThreshold := 1;
    MSComm1.SThreshold := 3;
    MSComm1.PortOpen := True;
  except
    on E : Exception do
      ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
  end;
end;
 
procedure TForm1.MSComm1Comm(Sender: TObject);
begin
  If (MSComm1.CommEvent = 2) Then
    memo1.Text := memo1.text +  MSComm1.Input;
end;
 
end

Open in new window

Picture-2.png
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mobsos
mobsos

ASKER

How do I know the appropriate setup? I'm trying to communicate with an external device which based on PIC18f452 microship. It doesn't have a driver since it has been made together with a group in class!
You say you can send and receive data.  When you send data out of the COM port, is it intelligible at the other end?
Avatar of mobsos

ASKER

I don't really know since I'm not able to read the the device says! but I can send data with no errors!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Another question...

Can you communicate properly using HyperTerminal which is part of Windows?

John

good afternoon.

make sure the setting of your commport is 9600,n,8,1

after u set this one.
make sure u initialize ur modem correctly...


NOTE: modems have a garbage message or spoiled message as what u have experienced. that is /are uncontrollable in the programmer part because that is on the product or modem itself. u need to check the data set of the modem u use.

game-master
Avatar of mobsos

ASKER

There are some LED's and an LCD mounted on the board and everything seems to be working properly!

Also I've tried HyperTerminal - Commercial one not Microsoft's- and it gives a little different garbage :)

I'm using 9600,n,8,1 and that's shown clearly on the code!

How do I know the device settings?

please note that I'm using USB-Serial cable to communicate with that device!
The PIC is supposed to auto negotiate baud rates. SO you won't know the settings.

Generally when you first hook up the RS232 line, all you need to do is hit the enter key or space bar, (forget which) and that is supposed to set the PIC;s auto baud rate. It may be sending stuff OK, but there is a problem in sending in back.

There is some other problem with that portion of the circuit or in the PIC uC itself.

For more details on the PIC uC's you will need to seek a PIC micro-controller's forum.

Sorry.

JOhn
Oh... I did not see USB-serial....

PLEASE try a PC or laptop that has a real RS-232 Interface set as COM1 or COM2. I have had some bizarre problems when trying to use USB to RS232 serial adapters.

John
Avatar of mobsos

ASKER

now it's working, I had to set the baud to be 19200!

Thank you all


Plz Close this Q
You can close the question yourself. If you think that any of the contributors have helped you to fix it you can award points to their comments.

If not, I believe that there are links that you can follow to request alternatives. I don't have an open question to check and see the details, so I can't tell you any more exactly than that.
"I got the solution myself!"

Ref your request to delete the question:-

Graham Skan questioned whether the Baud Rate was set correctly.  I feel he should receive acknowledgment for pointing that out to you.  Johnjces gave you a practical method of testing whether the Baud Rate was set correctly, so I think he is entitled to points too.
Avatar of mobsos

ASKER

I appreciate everybody's contribution, but the answers posted here didn't help me! they might help somebody else though! I had a question to Graham Skan regarding to his post but he didn't answer which makes his post non beneficial!

Johnjces said: "The PIC is supposed to auto negotiate baud rates. SO you won't know the settings."  and thats not correct in my case!

I don't object to your closing the Q with no points assigned, but we all did point to and mention baud rate setup. I guess we all figured you had tried all available baud rate settings.

And, if you look up info on that PIC you will see that it is "supposed to" auto negotiate its communication speed.

Anyway... I don't care how you close it.

John
Avatar of mobsos

ASKER

Honestly, I knew how to do the settings before I posted this question, and if you take a look at the code attached with my question, you will notice the communication settings are written there! Also, my question was about the appropriate settings if mine were wrong, which no body said they were incorrect!

Anyways, when I said I found it myself, I implied that I made an effort to get the solution, and if I felt anyone here had helped me finding the solution, I wouldn't hesitate awarding him the offered points!
What were the exact steps you took to establish that 19200 was the correct Baud rate, please?

Looking at your code tells us nothing about how "the other end" is setup.  That was our line of approach, for you to tell us what was at the other end so that we could determine whether the problem was with your Delphi code, or whether it was at the other end.  There's no point in modifying lines of code, saying "Try this" when there is a more elegant approach which will lead to a more certain solution.  I have 37 years of experience in troubleshooting electronic and computer systems, frequently engaging in finding a solution over the phone, by email or in EE, and I have to say that I found your method of interacting with us to establish a solution was not helpful to me at least.  Being at the troubleshootee end of a technical support conversation is as much of an art as being a troubleshooter.  With all due respects, you need to hone up your ability to converse with troubleshooters to get the maximum benefit from asking people to help you.  I make that comment to you in the (subsequent) light of looking at your previous question history.  I am not saying this to antagonise you, but as sincere and frank advice to you for the future.
Avatar of mobsos

ASKER

moorhouselondon:

Thank you for your value advise, and the answer for your question is my professor! Yes, I had tried many ways, including this question, in order to fix that problem, but unfortunately non of them worked. So I had to go back to my professor who told me to set the baud rate to be 19200

You are criticizing me because there was a lot of information were missing about the other end, and that's true! If I had the information that you needed, I wouldn't post anything here!

Thank you again!
Aha, I had a feeling you were going to say something like "I asked someone".  

Thing is that you would learn a lot more about troubleshooting by being a bit more patient with us.  You are in an educational environment, but in the non-controlled environment of places other than educational establishments# there is not the luxury of "asking someone".  Yes there is EE but there is still the need to frame one's questions and responses to responses to those questions in a way that enables a solution to be extracted from the experts here.  That's not always easy, but practice is good.  Ask lots and lots of questions here, but try not to rub people here up the wrong way by suggesting that we had absolutely no part in helping you find a solution.  Question is: Would we have got a Grade A Accept if we'd said "Ask your professor?"  (LOL, I am jesting).  

>If I had the information that you needed, I wouldn't post anything here!  
All you needed to do was ask a few things about how to get the information about the other end.  The method of getting to that result using techniques we could have talked you through would have been much more valuable an insight than asking your prof.  It would have taken a few Comments to get there I know, and that might have been tedious, but it's the way things tick.  

Anyway, good luck with your course - here's hoping we can assist you better next time....

#putting it in another way would have sounded very patronising, and that is not a way I wanted it to come across at all.
Avatar of mobsos

ASKER

Am I supposed to award the points to everyones "tried to help me"? or the one who really helped me should be awarded? Despite all the valuable contributions on this page, non of them has helped me fixing that problem honestly!
It is ultimately up to the Moderator (Modus Operandi) who has intervened as to what is decided.  

I posted (ID:22883665) what I personally felt was fair in the circumstances, based on what I know about the subject, and what had already been suggested in the Q, assuming you had not consulted with your professor, assuming that you would have persevered with us a while longer you would have found graham and john's suggestions the best basis from which to achieve a solution.  
Avatar of mobsos

ASKER

I'm not sure if this is the right place to discuss such an issue, but the past discussion led to ask another question...

if I understood you correctly, I agree with you when you implied that the suggested solutions were good enough to be awarded.. but why should I pay that? did I make any mistake that cost 500 points when I asked to close my question? even though I didn't get what I was looking for?!
You can set the ground rules when asking the question.  If you'd said "I know all about baud rates, and I already know how to use Hyperterminal to fault-find" then that would have headed off any suggestions involving those things.  But then we wouldn't have been able to narrow down to a solution without some difficulty, because you have already ruled out the baud rate as the problem.  Right??

Have a look at the following link.  However true this conversation was (it is Urban Legend material, but I've not been able to find it on Snopes), there is something to be learned whichever end of the telephone line you are on.

http://charmainezoe-nvts.blogspot.com/2008/08/wordperfect-helpline-conversation-oldie.html
Hehe.

Perhaps the user in the link should have mentioned that it was a laptop. That way the customer services member would have kept his job. At least he didn't suggest defragmenting the hard drive.

Actually, understanding the main point of the question is often more difficult than working out an answer. Fortunately we are all volunteers and we can't spent the points.