Host computer program written with control Spcomm

Source: Internet
Author: User

I first use the host computer to send data to the microcontroller. After the MCU receives the data, it sends it to the host computer and displays it. q: Why can't the upper computer receive the data sent by the single-chip microcomputer? How can I know that the upper computer has sent data to the single-chip computer. my SCM Program I have used the serial port assistant for debugging. Thank you.
Unit unit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, Spcomm;

Type
Tform1 = Class (tform)
Memo1: tmemo;
Button1: tbutton;
Button2: tbutton;
Button3: tbutton;
Button4: tbutton;
Button5: tbutton;
Combox1: tcombobox;
Label1: tlabel;
Button6: tbutton;
Comm1: tcomm;
Edit1: tedit;
Procedure button3click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button1click (Sender: tobject );
Procedure button4click (Sender: tobject );
Procedure comm1receivedata (Sender: tobject; Buffer: pointer; bufferlength: Word );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;


Implementation

{$ R *. DFM}

Procedure tform1.comm1receivedata (Sender: tobject; Buffer: pointer; bufferlength: Word );
VaR
Data: string;
Begin // receives data
Setlength (data, bufferlength );
Move (buffer ^, pchar (data) ^, bufferlength );
Memo1.lines. Add (data );
Memo1.invalidate;

End;
Procedure tform1.button3click (Sender: tobject );
Begin
Form1.close;
End;
Procedure tform1.button2click (Sender: tobject );
Begin
Comm1.stopcomm;
Button1.enabled: = true;
End;

Procedure tform1.button1click (Sender: tobject );
Begin
Try
// Comm1.commname: = 'com' + inttostr (combobox1.itemindex); // select the port number
Comm1.commname = COM1;
Comm1.bau drate: = 9600;
Comm1.startcomm;
Button1.enabled: = false;
Button2.enabled: = true;
Button3.enabled: = true;
Button4.enabled: = true;
Button5.enabled: = true;
Except
Showmessage ('Open serial port error! ');
End;
End;

Procedure tform1.button4click (Sender: tobject );
VaR
STR: string;
Begin // send data
STR: = edit1.text;
Form1.comm1. writecommdata (pchar (STR), length (STR ));
End;
End.

Continue to read the full text of "PC program written with control Spcomm...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.