资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net串口控件 vb串口源代码

vb.net如何在串口接收事件中访问并修改另一个窗体的控件?

可以将Form1里的串口公开,然后在Form2里添加对DataReceived事件的处理

创新互联专注于雨湖网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供雨湖营销型网站建设,雨湖网站制作、雨湖网页设计、雨湖网站官网定制、小程序设计服务,打造雨湖网络公司原创品牌,更为您提供雨湖网站排名全网营销落地服务。

Form1.Designer.cs中将

private System.IO.Ports.SerialPort port;改为

publice System.IO.Ports.SerialPort port;

然后在Form2里加上

Form1.port.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(port_DataReceived);

最后在

void port_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

{

在这里进行处理就可以了;

}

这个是C#的,VB的你自己转一下

一个基于API的VB.net串口通讯类

的串口通讯支持总是让人觉得有所不足 在使用VB 的MsComm ocx时 很多人都会在的开发中觉得很困扰 这里讲述的串口通讯类使用native代码 并且它是通API调用实现的 你会发现的串口通讯就是这么简单 在说明如何使用这个类前 需要说明的是 本类只是一个的串口通讯演示 你可能需要根据你的情况修改后使用 另外 本类的目的是通过例子教会你在无需ocx控件和第三方组件的支持下用开发串口通讯程序 所有并没有完善的异常错误处理 1 初始化并打开串口创建一个CRs 类的实例 并在调用Open方法前设置好串口通讯参数 例 Dim moRS as New Rs ()With moRs Port = // Uses BaudRate =   // 波特率 DataBit =   //  data bits StopBit = Rs DataStopBit StopBit_ // 停止位 Parity = Rs DataParity Parity_None // 无奇偶校验 Timeout =   //超时时间 msEnd With // 初始化并打开串口moRS Open () // 串口打开后 你可以随意地控制DTR/RTSmoRS Dtr = TruemoRS Rts = True为了处理异常情况 建议你使用Try Catch 2 发送数据本类为Rx和Tx准备了两个缓冲区(buffer) 发送数据时 只需要设置TxData属性为你需要发送的数据 然后调用Tx方法就可以了 例如 moRS TxData = txtTx TextmoRS Tx() 接收数据先调用Rx方法(参数为您需要从串口读取的字节数) 然后读取RxData属性 例如 moRS Rx( )  // 从串口通讯缓冲区里读取 字节Dim sRead as String=moRs RxData需要注意的是 当本类无法用串口读取到所需的字节数 程序线程在超时异常发生前是锁死的 超时时间通过Timout属性设置 如果你没有指明需要读取的字节数 本类默认使用 字节来读取缓冲区里的数据 版本信息 Project History st Public release Beta ( / / )Rev ( ) Added ResetDev SetBreak and ClearBreak to the EscapeCommFunction constants Added the overloaded Open routine Added the modem status routines properties and enum If a read times out it now returns a EndOfStreamException (instead of a simple Exception) Compiled with VS Net finalRev ( )Added Async supportRev ( )Minor bugs fixedRev a ( / / )Fixed BuildCommmDCB problemRev ( / / )Fixed problem with ASCII Encoding truncating th bitRev ( / / )Added IDisposable / Finalize implementationRev ( / / )Fixed problem on DCB fields InitializationRev ( / / )Added XON/XOFF supportRev ( / / )Added support to port number greater than Rev ( / / )Added CommEvent to detect ining chars/events(!)Updated both Tx/Rx method from Non Ovelapped to Overlapped modeRemoved unused Async methods and other stuff Rev ( / / )Fixed incorrect character handling when using EnableEvents()Rev ( / / )Fixed some bugs reported by usersRev ( / / )Removed AutoReset of internal buffers and added PurgeBuffer() methodRev ( / / )Update internal stuff now using Win Exception instead of GetLastError+FormatMessage APIsRev ( / / )Added IsPortAvailable() function (thanks to Tom Lafleur for the hint)Revised some API declarationFixed some problems with Win /Me OS (thanks to Alex Komissarov for the feedback)Rev ( / / )Fixed bug introduced on rev (sorry for that )Rev ( / / )Added SetBreak/ClearBreak methods for sending break signal over the line Rev ( / / )Fixed incorrect field on MCONFIG Structure Rev ( / / )Fixed bug causing troubles accessing already in use ports (folks thanks for the feedback!)Rev ( / / )Fixed bug on DTR property (thanks to Charles Olivier Théroux)Rev ( / / )CommEvent is no more raised on a secondary thread (please note that this is valid only if event handler is not associated with a static method)pEventsWatcher now uses a background threadRev ( / / )Fixed EscapeCommFunction declarationFixed incorrect Pariti enum entryRev ( / / )Fixed memory leak causing random program termination without any message Thanks to Ralf Gedrat for testing this scenario Rev ( / / )Fixed bug DisableEvents not working bug (Thanks to Jean Bédard) lishixinzhi/Article/program/net/201311/11852

用VB.net 里面的SerialPort1.Write( )串口控件,怎么才能发送出去一个16进制的01

直接发数字1。

一般可以直接发10进制的数字,当然要转换,比如16进制的21,你可以直接发33

c#中的串口控件和VB.NET中的Mscomm控件是一回事吗?

是独立的东西,没有依赖,尽管在底层有可能是类似的调用

还有在.net里一般只认为是普通类,并不属于控件,因为没界面


本文标题:vb.net串口控件 vb串口源代码
分享链接:http://cdkjz.cn/article/hgejji.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220