ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:22.70KB ,
资源ID:3953305      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3953305.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(vbvb1net进行串口编程.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

vbvb1net进行串口编程.docx

1、vbvb1net进行串口编程vb/进行串口编程2007-05-28 09:122005中有相对应的类直接使用 2005中有相对应的类直接使用。 2003以及以前的看下面的类 Option Strict On Imports System.Runtime.InteropServices Imports System.Text Imports System.Threading This class provides all the necessary support for communicating with the Comm Port (otherwise known as the Seria

2、l Port, or RS232 port). Public Class Rs232 Declare the necessary class variables, and their initial values. Private mhRS As Integer = -1 Handle to Com Port Private miPort As Integer = 1 Default is COM1 Private miTimeout As Integer = 70 Timeout in ms Private miBaudRate As Integer = 9600 Private mePar

3、ity As DataParity = 0 Private meStopBit As DataStopBit = 0 Private miDataBit As Integer = 8 Private miBufferSize As Integer = 512 Buffers size default to 512 bytes Private mabtRxBuf As Byte() Receive buffer Private meMode As Mode Class working mode Private mbWaitOnRead As Boolean Private mbWaitOnWri

4、te As Boolean Private mbWriteErr As Boolean Private muOverlapped As OVERLAPPED Private muOverlappedW As OVERLAPPED Private muOverlappedE As OVERLAPPED Private mabtTmpTxBuf As Byte() Temporary buffer used by Async Tx Private moThreadTx As Thread Private moThreadRx As Thread Private miTmpBytes2Read As

5、 Integer Private meMask As EventMasks Private Mut As New Mutex #Region Enums This enumeration provides Data Parity values. Public Enum DataParity Parity_None = 0 Pariti_Odd Parity_Even Parity_Mark End Enum This enumeration provides Data Stop Bit values. It is set to begin with a one, so that the enu

6、meration values match the actual values. Public Enum DataStopBit StopBit_1 = 1 StopBit_2 End Enum This enumeration contains values used to purge the various buffers. Private Enum PurgeBuffers RXAbort = &H2 RXClear = &H8 TxAbort = &H1 TxClear = &H4 End Enum This enumeration provides values for the li

7、nes sent to the Comm Port Private Enum Lines SetRts = 3 ClearRts = 4 SetDtr = 5 ClearDtr = 6 ResetDev = 7 Reset device if possible SetBreak = 8 Set the device break line. ClearBreak = 9 Clear the device break line. End Enum This enumeration provides values for the Modem Status, since well be communi

8、cating primarily with a modem. Note that the Flags() attribute is set to allow for a bitwise combination of values. Public Enum ModemStatusBits ClearToSendOn = &H10 DataSetReadyOn = &H20 RingIndicatorOn = &H40 CarrierDetect = &H80 End Enum This enumeration provides values for the Working mode Public

9、 Enum Mode NonOverlapped Overlapped End Enum This enumeration provides values for the Comm Masks used. Note that the Flags() attribute is set to allow for a bitwise combination of values. Public Enum EventMasks RxChar = &H1 RXFlag = &H2 TxBufferEmpty = &H4 ClearToSend = &H8 DataSetReady = &H10 Recei

10、veLine = &H20 Break = &H40 StatusError = &H80 Ring = &H100 End Enum #End Region #Region Structures This is the DCB structure used by the calls to the Windows API. Private Structure DCB Public DCBlength As Integer Public BaudRate As Integer Public Bits1 As Integer Public wReserved As Int16 Public Xon

11、Lim As Int16 Public XoffLim As Int16 Public ByteSize As Byte Public Parity As Byte Public StopBits As Byte Public XonChar As Byte Public XoffChar As Byte Public ErrorChar As Byte Public EofChar As Byte Public EvtChar As Byte Public wReserved2 As Int16 End Structure This is the CommTimeOuts structure

12、 used by the calls to the Windows API. Private Structure COMMTIMEOUTS Public ReadIntervalTimeout As Integer Public ReadTotalTimeoutMultiplier As Integer Public ReadTotalTimeoutConstant As Integer Public WriteTotalTimeoutMultiplier As Integer Public WriteTotalTimeoutConstant As Integer End Structure

13、This is the CommConfig structure used by the calls to the Windows API. Private Structure COMMCONFIG Public dwSize As Integer Public wVersion As Int16 Public wReserved As Int16 Public dcbx As DCB Public dwProviderSubType As Integer Public dwProviderOffset As Integer Public dwProviderSize As Integer P

14、ublic wcProviderData As Byte End Structure This is the OverLapped structure used by the calls to the Windows API. Public Structure OVERLAPPED Public Internal As Integer Public InternalHigh As Integer Public Offset As Integer Public OffsetHigh As Integer Public hEvent As Integer End Structure #End Re

15、gion #Region Exceptions This class defines a customized channel exception. This exception is raised when a NACK is raised. Public Class CIOChannelException : Inherits ApplicationException Sub New(ByVal Message As String) MyBase.New(Message) End Sub Sub New(ByVal Message As String, ByVal InnerExcepti

16、on As Exception) MyBase.New(Message, InnerException) End Sub End Class This class defines a customized timeout exception. Public Class IOTimeoutException : Inherits CIOChannelException Sub New(ByVal Message As String) MyBase.New(Message) End Sub Sub New(ByVal Message As String, ByVal InnerException

17、As Exception) MyBase.New(Message, InnerException) End Sub End Class #End Region #Region Events These events allow the program using this class to react to Comm Port events. Public Event DataReceived(ByVal Source As Rs232, ByVal DataBuffer() As Byte) Public Event TxCompleted(ByVal Source As Rs232) Pu

18、blic Event CommEvent(ByVal Source As Rs232, ByVal Mask As EventMasks) #End Region #Region Constants These constants are used to make the code clearer. Private Const PURGE_RXABORT As Integer = &H2 Private Const PURGE_RXCLEAR As Integer = &H8 Private Const PURGE_TXABORT As Integer = &H1 Private Const

19、PURGE_TXCLEAR As Integer = &H4 Private Const GENERIC_READ As Integer = &H80000000 Private Const GENERIC_WRITE As Integer = &H40000000 Private Const OPEN_EXISTING As Integer = 3 Private Const INVALID_HANDLE_VALUE As Integer = -1 Private Const IO_BUFFER_SIZE As Integer = 1024 Private Const FILE_FLAG_O

20、VERLAPPED As Integer = &H40000000 Private Const ERROR_IO_PENDING As Integer = 997 Private Const WAIT_OBJECT_0 As Integer = 0 Private Const ERROR_IO_INCOMPLETE As Integer = 996 Private Const WAIT_TIMEOUT As Integer = &H102& Private Const INFINITE As Integer = &HFFFFFFFF #End Region #Region Properties

21、 This property gets or sets the BaudRate Public Property BaudRate() As Integer Get Return miBaudRate End Get Set(ByVal Value As Integer) miBaudRate = Value End Set End Property This property gets or sets the BufferSize Public Property BufferSize() As Integer Get Return miBufferSize End Get Set(ByVal

22、 Value As Integer) miBufferSize = Value End Set End Property This property gets or sets the DataBit. Public Property DataBit() As Integer Get Return miDataBit End Get Set(ByVal Value As Integer) miDataBit = Value End Set End Property This write-only property sets or resets the DTR line. Public Write

23、Only Property Dtr() As Boolean Set(ByVal Value As Boolean) If Not mhRS = -1 Then If Value Then EscapeCommFunction(mhRS, Lines.SetDtr) Else EscapeCommFunction(mhRS, Lines.ClearDtr) End If End If End Set End Property This read-only property returns an array of bytes that represents the input coming in

24、to the Comm Port. Overridable ReadOnly Property InputStream() As Byte() Get Return mabtRxBuf End Get End Property This read-only property returns a string that represents the data coming into to the Comm Port. Overridable ReadOnly Property InputStreamString() As String Get Dim oEncoder As New System.Text.ASCIIEncoding Return oEncoder.GetString(Me.InputStream) End Get End Property This property returns the open status of the Comm Port. ReadOnly Property IsOpen() As Boolean Get

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1