Imports System Imports System.Runtime.InteropServices Namespace JustinIO Class CommPort Public PortNum As String Public BaudRate As Integer Public ByteSize As Byte Public Parity As Byte ''''// 0-4=no,odd,even,mark,space Public StopBits As Byte ''''// 0,1,2 = 1, 1.5, 2 Public ReadTimeout As Integer ''''//comm port win32 file handle Private hComm As Integer = -1 Public Opened As Boolean = False ''''//win32 api constants Private Const GENERIC_READ As Int64 = &H80000000 Private Const GENERIC_WRITE As Int64 = &H40000000 Private Const OPEN_EXISTING As Integer = 3 Private Const INVALID_HANDLE_VALUE As Integer = -1 #Region "struct" <StructLayout(LayoutKind.Sequential)> _ Public Structure DCB ''''//taken from c struct in platform sdk Public DCBlength As Integer ''''// sizeof(DCB) Public BaudRate As Integer ''''// 指定当前波特率 current baud rate ''''// these are the c struct bit fields, bit twiddle flag to set Public fBinary As Integer ''''// 指定是否允许二进制模式,在windows95中必须主TRUE binary mode, no EOF check Public fParity As Integer ''''// 指定是否允许奇偶校验 enable parity checking Public fOutxCtsFlow As Integer ''''// 指定CTS是否用于检测发送控制,当为TRUE是CTS为OFF,发送将被挂起。 CTS output flow control Public fOutxDsrFlow As Integer ''''// 指定CTS是否用于检测发送控制 DSR output flow control Public fDtrControl As Integer ''''// DTR_CONTROL_DISABLE值将DTR置为OFF, DTR_CONTROL_ENABLE值将DTR置为ON, DTR_CONTROL_HANDSHAKE允许DTR"握手" DTR flow control type Public fDsrSensitivity As Integer ''''// 当该值为TRUE时DSR为OFF时接收的字节被忽略 DSR sensitivity Public fTXContinueOnXoff As Integer ''''// 指定当接收缓冲区已满,并且驱动程序已经发送出XoffChar字符时发送是否停止。TRUE时,在接收缓冲区接收到缓冲区已满的字节XoffLim且驱动程序已经发送出XoffChar字符中止接收字节之后,发送继续进行。 FALSE时,在接收缓冲区接收到代表缓冲区已空的字节XonChar且驱动程序已经发送出恢复发送的XonChar之后,发送继续进行。XOFF continues Tx Public fOutX As Integer ''''// TRUE时,接收到XoffChar之后便停止发送接收到XonChar之后将重新开始 XON/XOFF out flow control Public fInX As Integer ''''// TRUE时,接收缓冲区接收到代表缓冲区满的XoffLim之后,XoffChar发送出去接收缓冲区接收到代表缓冲区空的XonLim之后,XonChar发送出去 XON/XOFF in flow control Public fErrorChar As Integer ''''// 该值为TRUE且fParity为TRUE时,用ErrorChar 成员指定的字符代替奇偶校验错误的接收字符 enable error replacement Public fNull As Integer ''''// eTRUE时,接收时去掉空(0值)字节 enable null stripping Public fRtsControl As Integer ''''// RTS flow control ''''/*RTS_CONTROL_DISABLE时,RTS置为OFF '''' * RTS_CONTROL_ENABLE时, RTS置为ON '''' * RTS_CONTROL_HANDSHAKE时, '''' * 当接收缓冲区小于半满时RTS为ON '''' * 当接收缓冲区超过四分之三满时RTS为OFF '''' * RTS_CONTROL_TOGGLE时, '''' * 当接收缓冲区仍有剩余字节时RTS为ON ,否则缺省为OFF*/ Public fAbortOnError As Integer ''''// TRUE时,有错误发生时中止读和写操作 abort on error Public fDummy2 As Integer ''''// 未使用 reserved Public flags As Int64 Public wReserved As UInt16 ''''// 未使用,必须为0 not currently used Public XonLim As UInt16 ''''// 指定在XON字符发送这前接收缓冲区中可允许的最小字节数 transmit XON threshold Public XoffLim As UInt16 ''''// 指定在XOFF字符发送这前接收缓冲区中可允许的最小字节数 transmit XOFF threshold Public ByteSize As Byte ''''// 指定端口当前使用的数据位 number of bits/byte, 4-8 Public Parity As Byte ''''// 指定端口当前使用的奇偶校验方法,可能为:EVENPARITY,MARKPARITY,NOPARITY,ODDPARITY 0-4=no,odd,even,mark,space 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   [1] [2] [3] 下一页 [C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET) [VB.NET程序]Henry手记-VB.NET中动态加载Treeview节点(二)
|