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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

vba中使用api串口通信serialport英文.docx

1、vba中使用api串口通信serialport英文-This VB module is a collection of routines to perform serial port I/O withoutusing the Microsoft Comm Control component. This module uses the Windows APIto perform the overlapped I/O operations necessary for serial communications.The routine can handle up to 4 serial ports

2、which are identified with aPort ID.All routines (with the exception of CommRead and CommWrite) return an errorcode or 0 if no error occurs. The routine CommGetError can be used to getthe complete error message.- Public Constants- Output Control Lines (CommSetLine)Const LINE_BREAK = 1Const LINE_DTR =

3、 2Const LINE_RTS = 3 Input Control Lines (CommGetLine)Const LINE_CTS = &H10&Const LINE_DSR = &H20&Const LINE_RING = &H40&Const LINE_RLSD = &H80&Const LINE_CD = &H80&- System Constants-Private Const ERROR_IO_INCOMPLETE = 996&Private Const ERROR_IO_PENDING = 997Private Const GENERIC_READ = &HPrivate C

4、onst GENERIC_WRITE = &HPrivate Const FILE_ATTRIBUTE_NORMAL = &H80Private Const FILE_FLAG_OVERLAPPED = &HPrivate Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000Private Const OPEN_EXISTING = 3 COMM FunctionsPrivate Const MS_CTS_ON = &H10&Private Const MS_DSR_ON = &H20&Private Const MS_RING_ON = &H40&Private

5、 Const MS_RLSD_ON = &H80&Private Const PURGE_RXABORT = &H2Private Const PURGE_RXCLEAR = &H8Private Const PURGE_TXABORT = &H1Private Const PURGE_TXCLEAR = &H4COMM Escape Functions Private Const CLRBREAK = 9 Private Const CLRDTR = 6Private Const CLRRTS = 4Private Const SETBREAK = 8Private Const SETDTR

6、 = 5Private Const SETRTS = 3- System Structures-Private Type COMSTATfBitFields As Long See Comment incbInQue As LongcbOutQue As LongEnd TypePrivate Type COMMTIMEOUTSReadIntervalTimeout As LongReadTotalTimeoutMultiplier As LongReadTotalTimeoutConstant As LongWriteTotalTimeoutMultiplier As LongWriteTo

7、talTimeoutConstant As LongEnd TypeThe DCB structure defines the control setting for a serialcommunications device.Private Type DCBDCBlength As LongBaudRate As LongfBitFields As Long See Comments inwReserved As IntegerXonLim As IntegerXoffLim As IntegerByteSize As ByteParity As ByteStopBits As ByteXo

8、nChar As ByteXoffChar As ByteErrorChar As ByteEofChar As ByteEvtChar As BytewReserved1 As Integer Reserved; Do Not UseEnd TypePrivate Type OVERLAPPEDInternal As LongInternalHigh As Longoffset As LongOffsetHigh As LonghEvent As LongEnd TypePrivate Type SECURITY_ATTRIBUTESnLength As LonglpSecurityDesc

9、riptor As LongbInheritHandle As LongEnd Type- System Functions- Fills a specified DCB structure with values specified in a device-control string.Private Declare Function BuildCommDCB Lib kernel32 Alias BuildCommDCBA _ (ByVal lpDef As String, lpDCB As DCB) As LongRetrieves information about a communi

10、cations error and reportsthe current status of a communications device. The function iscalled when a communications error occurs, and it clears thedevices error flag to enable additional input and output(I/O) operations.Private Declare Function ClearCommError Lib kernel32 _(ByVal hFile As Long, lpEr

11、rors As Long, lpStat As COMSTAT) As LongCloses an open communications device or file handle.Private Declare Function CloseHandle Lib kernel32 (ByVal hObject As Long) As Long Creates or opens a communications resource and returns a handlethat can be used to access the resource.Private Declare Functio

12、n CreateFile Lib kernel32 Alias CreateFileA _ (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _ ByVal dwShareMode As Long, lpSecurityAttributes As Any, _ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _ ByVal hTemplateFile As Long) As Long Directs a specified com

13、munications device to perform a function.Private Declare Function EscapeCommFunction Lib kernel32 _ (ByVal nCid As Long, ByVal nFunc As Long) As LongFormats a message string such as an error string returnedby anoher function.Private Declare Function FormatMessage Lib kernel32 Alias FormatMessageA _

14、(ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, _ ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, _ Arguments As Long) As LongRetrieves modem control-register values.Private Declare Function GetCommModemStatus Lib kernel32 _ (ByVal hFile As Long, lpMode

15、mStat As Long) As LongRetrieves the current control settings for a specifiedcommunications device.Private Declare Function GetCommState Lib kernel32 _(ByVal nCid As Long, lpDCB As DCB) As LongRetrieves the calling threads last-error code value.Private Declare Function GetLastError Lib kernel32 () As

16、 LongRetrieves the results of an overlapped operation on thespecified file, named pipe, or communications device.Private Declare Function GetOverlappedResult Lib kernel32 _ (ByVal hFile As Long, lpOverlapped As OVERLAPPED, _ lpNumberOfBytesTransferred As Long, ByVal bWait As Long) As LongDiscards al

17、l characters from the output or input buffer of aspecified communications resource. It can also terminatepending read or write operations on the resource.Private Declare Function PurgeComm Lib kernel32 _ (ByVal hFile As Long, ByVal dwFlags As Long) As LongReads data from a file, starting at the posi

18、tion indicated by thefile pointer. After the read operation has been completed, thefile pointer is adjusted by the number of bytes actually read,unless the file handle is created with the overlapped attribute.If the file handle is created for overlapped input and output(I/O), the application must ad

19、just the position of the file pointerafter the read operation.Private Declare Function ReadFile Lib kernel32 _ (ByVal hFile As Long, ByVal lpBuffer As String, _ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, _ lpOverlapped As OVERLAPPED) As LongConfigures a communications devi

20、ce according to the specificationsin a device-control block (a DCB structure). The functionreinitializes all hardware and control settings, but it does notempty output or input queues.Private Declare Function SetCommState Lib kernel32 _ (ByVal hCommDev As Long, lpDCB As DCB) As LongSets the time-out

21、 parameters for all read and write operations on aspecified communications device.Private Declare Function SetCommTimeouts Lib kernel32 _(ByVal hFile As Long, lpCommTimeouts As COMMTIMEOUTS) As LongInitializes the communications parameters for a specifiedcommunications device.Private Declare Functio

22、n SetupComm Lib kernel32 _(ByVal hFile As Long, ByVal dwInQueue As Long, ByVal dwOutQueue As Long) As LongWrites data to a file and is designed for both synchronous and asynchronous operation. The function starts writing data to the fileat the position indicated by the file pointer. After the writeo

23、peration has been completed, the file pointer is adjusted by thenumber of bytes actually written, except when the file is opened withFILE_FLAG_OVERLAPPED. If the file handle was created for overlappedinput and output (I/O), the application must adjust the position ofthe file pointer after the write

24、operation is finished.Private Declare Function WriteFile Lib kernel32 _ (ByVal hFile As Long, ByVal lpBuffer As String, _ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, _ lpOverlapped As OVERLAPPED) As LongPrivate Declare Sub AppSleep Lib kernel32 Alias Sleep (ByVal dwMillisecon

25、ds As Long) - Program Constants-Private Const MAX_PORTS = 4- Program Structures-Private Type COMM_ERRORlngErrorCode As LongstrFunction As StringstrErrorMessage As StringEnd TypePrivate Type COMM_PORTlngHandle As LongblnPortOpen As BooleanudtDCB As DCBEnd Type- Program Storage-Private udtCommOverlap

26、As OVERLAPPEDPrivate udtCommError As COMM_ERRORPrivate udtPorts(1 To MAX_PORTS) As COMM_PORT-GetSystemMessage - Gets system error text for the specified error code. -Public Function GetSystemMessage(lngErrorCode As Long) As StringDim intPos As IntegerDim strMessage As String, strMsgBuff As String * 256Call FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, lngErrorCode, 0, strMsgBuff, 255, 0)intPos =

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

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