//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define TOSTRING(arg) #arg
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Send->Enabled = false;
}
LRESULT __fastcall TForm1::OnComRecv(TMessage &msg)
{
AnsiString str = "";
char buf[1024];
char tmpBuf[1];
int len=com1.Read(buf,1024);
if(len>0)
{
for(int i=0;i<len;i++)
{
sprintf(tmpBuf,"%c",buf[i]);
str+=AnsiString(tmpBuf);
}
EditRcv->Text = str;
}
return 0;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenPortClick(TObject *Sender)
{
//
if(OpenPort->Caption == "Open Port")
{
if(!com1.IsOpen())
{
if(com1.Open(1))
{
ShowMessage("串口已经打开");
com1.SetWnd(Handle);
OpenPort->Caption = "Close Port";
Send->Enabled = true;
}
}
else
ShowMessage("串口com1被其他程序占用!");
}
else
{
com1.Close();
ShowMessage("串口已经关闭!");
OpenPort->Caption = "Open Port";
Send->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SendClick(TObject *Sender)
{
//
com1.Write(EditSend->Text.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(com1.IsOpen())
com1.Close();
}
//---------------------------------------------------------------------------
c++builder下面用windows api 进行串口通行的源码。
4星 · 超过85%的资源 需积分: 34 138 浏览量
2009-03-18
23:00:34
上传
评论
收藏 391KB RAR 举报
java_lover_
- 粉丝: 40
- 资源: 20
最新资源
- Python 版冒泡排序算法源代码
- tensorflow-gpu-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析
- 智能车仿真软件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页