MSCOMM32.OCX在C#中的调用

MSCOMM32.OCX在C#中的调用
调用MSCOMM32.OCX控件可以实现串口通信,最近一直在做这方面的工作,所以把它记下来。
一。注册
第一步:用Windows下的注册工具regsvr32注册该OCX控件,点击“开始”->"运行",输入:
Regsvr32 控件所在路径/Mscomm32.ocx
 
 第二步:在注册表中手工新建一个主键项,找到HKEY_CLASSES_ROOT/Licenses,在其中添加主键
4250E830-6AC2-11cf-8ADB-00AA00C00905 并将内容设置为: kjljvjjjoquqmjjjvpqqkqmqykypoqjquoun
二。添加
将注册好的控件添加到工具箱,可以像使用普通工具一样使用。也就是直接拖入窗体,然后对其编程。
三。代码
这是一个关于ID卡读卡器的源代码,首先打开串口,然后向串口发送一串命令,使其读ID卡数据,再接着接收缓冲中的ID卡数据。
1 using System;
2 using System.Drawing;
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Windows.Forms;
6 using System.Data;
7 using System.Text;
8 using System.Timers;
9 using System.Threading;
10 using Microsoft.VisualBasic;
11 namespace cardtest
12 {
13 ///
14 /// Form1 的摘要说明。
15 ///

16 public class Form1 : System.Windows.Forms.Form
17 {
18 private System.Windows.Forms.TextBox TB_cardnum;
19 private System.Windows.Forms.Button but_open;
20 private System.Windows.Forms.Button but_exit;
21 private System.Windows.Forms.Button but_read;
22 private System.Windows.Forms.Button but_stop;
23 private AxMSCommLib.AxMSComm msc;
24 private System.Windows.Forms.TextBox TB_paut;
25 private System.Windows.Forms.Label lbl_info;
26 private System.ComponentModel.IContainer components=null;
27 private System.Timers.Timer atimer=new System.Timers.Timer();
28 public Form1()
29 {
30 //
31 // Windows 窗体设计器支持所必需的
32 //
33 InitializeComponent();
34
35 //
36 // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
37 //
38 }
39
40 //
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值