不同语言的串口程序文档格式.docx
- 文档编号:16620866
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:12
- 大小:566.37KB
不同语言的串口程序文档格式.docx
《不同语言的串口程序文档格式.docx》由会员分享,可在线阅读,更多相关《不同语言的串口程序文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
SerialPort1.Open()//注释:
打开串口
EndSub
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
SerialPort1.Write("
aaaa"
)//注释:
发送字符串到串口
PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
SerialPort1.Close()//注释:
关闭串口
PrivateSubButton4_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton4.Click
SerialPort1.Write(TextBox1.Text)//发送字符串,字符串通过界面输入。
PrivateSubButton5_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton5.Click
Label1.Text=Chr(Val(TextBox2.Text))
SerialPort1.Write(Val(TextBox2.Text))
Dimaa
(2)AsByte
aa(0)=255
aa
(1)=254
SerialPort1.Write(aa,0,2)//注释发送0xff大于127的数据。
EndClass
使用VS2008建立VC++串口程序
建立CLR程序:
拖动串口控件到对话框。
private:
System:
:
Voidbutton1_Click(System:
Object^sender,System:
EventArgs^e){
serialPort1->
Open();
}
private:
Voidbutton2_Click(System:
Close();
Voidbutton3_Click(System:
serialPort1->
Write("
);
}
Voidbutton4_Click(System:
Write((i++).ToString());
VC2008C#编写串口程序
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassForm1:
Form
{
publicForm1()
InitializeComponent();
}
privatevoidbutton1_Click(objectsender,EventArgse)
serialPort1.Open();
privatevoidbutton2_Click(objectsender,EventArgse)
serialPort1.Close;
privatevoidbutton3_Click(objectsender,EventArgse)
serialPort1.Write("
}
对串口监控程序,细化一下操作:
编译C#并调试
单击打开,观察串口监控的变化
上图是,单击打开后,串口监控显示的串口打开了。
字符a的ASCII码是0x61
上图显示,单击关闭后的情形。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 不同 语言 串口 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)