JustinIO的vb.NET版本!(串口操作类)__教程 |
|
日期:2007-5-20 1:23:19 人气:94 [大 中 小] |
|
|
|
Public StopBits As Byte '// 指定端口当前使用的停止位数,可能为:ONESTOPBIT,ONE5STOPBITS,TWOSTOPBITS 0,1,2 = 1, 1.5, 2 Public XonChar As Char '// 指定用于发送和接收字符XON的值 Tx and Rx XON character Public XoffChar As Char '// 指定用于发送和接收字符XOFF值 Tx and Rx XOFF character Public ErrorChar As Char '// 本字符用来代替接收到的奇偶校验发生错误时的值 error replacement character Public EofChar As Char '// 当没有使用二进制模式时,本字符可用来指示数据的结束 end of input character Public EvtChar As Char '// 当接收到此字符时,会产生一个事件 received event character Public wReserved1 As UInt16 '// 未使用 reserved; do not use End Structure <StructLayout(LayoutKind.Sequential)> _ 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 <StructLayout(LayoutKind.Sequential)> _ Private 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 Region
#Region "Windows API" <DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _ Private Shared Function CreateFile( _ ByVal lpFileName As String, _ ByVal dwDesiredAccess As UInt32, _ ByVal dwShareMode As Integer, _ ByVal lpSecurityAttributes As Integer, _ ByVal dwCreationDisposition As Integer, _ ByVal dwFlagsAndAttributes As Integer, _ ByVal hTemplateFile As Integer) As Integer End Function '参数介绍: 'lpFileName 要打开的串口名称 'dwDesiredAccess 指定串口的访问方式,一般设置为可读可写方式 'dwShareMode 指定串口的共享模式,串口不能共享,所以设置为0 'lpSecurityAttributes 设置串口的安全属性,WIN9X下不支持,应设为NULL 'dwCreationDisposition 对于串口通信,创建方式只能为OPEN_EXISTING 'dwFlagsAndAttributes 指定串口属性与标志,设置为FILE_FLAG_OVERLAPPED(重叠I/O操作),指定串口以异步方式通信 'hTemplateFile 对于串口通信必须设置为NULL <DllImport("kernel32.dll")> _ Private Shared Function GetCommState(ByVal hFile As Integer, ByRef lpDCB As DCB) As Boolean End Function '参数介绍 'hFile 通信设备句柄 'DCB lpDCB 设备控制块DCB
<DllImport("kernel32.dll")> _ Private Shared Function BuildCommDCB(ByVal lpDef As String, ByRef lpDCB As DCB) As Boolean End Function '参数介绍 'lpDef 设备控制字符串 'lpDCB 设备控制块DCB <DllImport("kernel32.dll")> _ Private Shared Function SetCommState(ByVal hfile As Integer, ByRef lpDCB As DCB) As Boolean End Function '参数说明 'hFile 通信设备句柄 'lpDCB 设备控制块 <DllImport("kernel32.dll")> _ Private Shared Function GetCommTimeouts(ByVal hfile As Integer, ByRef lpCommTimeouts As COMMTIMEOUTS) As Boolean End Function '参数说明 'hFile 通信设备句柄 handle to comm device 'lpCommTimeouts 超时时间 time-out values <DllImport("kernel32.dll")> _ |
|
出处:本站原创 作者:佚名 |
|
|