Solved

Getting a spoiled text when reading from COM port!

Posted on 2008-11-02
24
955 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:mobsos
  • 9
  • 6
  • 5
  • +2
24 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 total points
Comment Utility
Do you have the correct setup for the port (baud, bits per character, etc)?
0
 

Author Comment

by:mobsos
Comment Utility
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!
0
 
LVL 31

Expert Comment

by:moorhouselondon
Comment Utility
You say you can send and receive data.  When you send data out of the COM port, is it intelligible at the other end?
0
 

Author Comment

by:mobsos
Comment Utility
I don't really know since I'm not able to read the the device says! but I can send data with no errors!
0
 
LVL 18

Assisted Solution

by:Johnjces
Johnjces earned 250 total points
Comment Utility
So far it sounds like you are trying to communicate with a PIC18f452 micro-controller that was programmed and built by as a class project.

The PIC18f452 has automatic baud rate and calibration but the garbage you are receiving can, IMHO, be:

1). baud rate problem (bad PIC uC) or bad/inverted signals that are externally buffered by a circuit onboard your proto board.

2). It is replying in machine code... doubtful.

3). How do you know that the PIC programming is correct?

Are you sending BASIC instructions or are you downloading PIC uC machine code??

How do you know you are communicating with the uC correctly? I.E. sending it commands? Can you make an LED blink via command or make it do something externally observable?

Just a few thoughts and questions.

John
0
 
LVL 18

Expert Comment

by:Johnjces
Comment Utility
Another question...

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

John
0
 
LVL 13

Expert Comment

by:game-master
Comment Utility

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
0
 

Author Comment

by:mobsos
Comment Utility
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!
0
 
LVL 18

Expert Comment

by:Johnjces
Comment Utility
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
0
 
LVL 18

Expert Comment

by:Johnjces
Comment Utility
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
0
 

Author Comment

by:mobsos
Comment Utility
now it's working, I had to set the baud to be 19200!

Thank you all


Plz Close this Q
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 31

Expert Comment

by:moorhouselondon
Comment Utility
"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.
0
 

Author Comment

by:mobsos
Comment Utility
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!

0
 
LVL 18

Expert Comment

by:Johnjces
Comment Utility
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
0
 

Author Comment

by:mobsos
Comment Utility
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!
0
 
LVL 31

Expert Comment

by:moorhouselondon
Comment Utility
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.
0
 

Author Comment

by:mobsos
Comment Utility
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!
0
 
LVL 31

Expert Comment

by:moorhouselondon
Comment Utility
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.
0
 

Author Comment

by:mobsos
Comment Utility
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!
0
 
LVL 31

Expert Comment

by:moorhouselondon
Comment Utility
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.  
0
 

Author Comment

by:mobsos
Comment Utility
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?!
0
 
LVL 31

Expert Comment

by:moorhouselondon
Comment Utility
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
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now