VBA中使用API串口通信SerialPort英文Word文档下载推荐.docx
- 文档编号:16846128
- 上传时间:2022-11-26
- 格式:DOCX
- 页数:28
- 大小:20.48KB
VBA中使用API串口通信SerialPort英文Word文档下载推荐.docx
《VBA中使用API串口通信SerialPort英文Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《VBA中使用API串口通信SerialPort英文Word文档下载推荐.docx(28页珍藏版)》请在冰豆网上搜索。
H20&
ConstLINE_RING=&
H40&
ConstLINE_RLSD=&
H80&
ConstLINE_CD=&
SystemConstants
PrivateConstERROR_IO_INCOMPLETE=996&
PrivateConstERROR_IO_PENDING=997
PrivateConstGENERIC_READ=&
H80000000
PrivateConstGENERIC_WRITE=&
H40000000
PrivateConstFILE_ATTRIBUTE_NORMAL=&
H80
PrivateConstFILE_FLAG_OVERLAPPED=&
PrivateConstFORMAT_MESSAGE_FROM_SYSTEM=&
H1000
PrivateConstOPEN_EXISTING=3
COMMFunctions
PrivateConstMS_CTS_ON=&
PrivateConstMS_DSR_ON=&
PrivateConstMS_RING_ON=&
PrivateConstMS_RLSD_ON=&
PrivateConstPURGE_RXABORT=&
H2
PrivateConstPURGE_RXCLEAR=&
H8
PrivateConstPURGE_TXABORT=&
H1
PrivateConstPURGE_TXCLEAR=&
H4
COMMEscapeFunctions
PrivateConstCLRBREAK=9
PrivateConstCLRDTR=6
PrivateConstCLRRTS=4
PrivateConstSETBREAK=8
PrivateConstSETDTR=5
PrivateConstSETRTS=3
SystemStructures
PrivateTypeCOMSTAT
fBitFieldsAsLong'
SeeCommentinWin32API.Txt
cbInQueAsLong
cbOutQueAsLong
EndType
PrivateTypeCOMMTIMEOUTS
ReadIntervalTimeoutAsLong
ReadTotalTimeoutMultiplierAsLong
ReadTotalTimeoutConstantAsLong
WriteTotalTimeoutMultiplierAsLong
WriteTotalTimeoutConstantAsLong
TheDCBstructuredefinesthecontrolsettingforaserial
communicationsdevice.
PrivateTypeDCB
DCBlengthAsLong
BaudRateAsLong
SeeCommentsinWin32API.Txt
wReservedAsInteger
XonLimAsInteger
XoffLimAsInteger
ByteSizeAsByte
ParityAsByte
StopBitsAsByte
XonCharAsByte
XoffCharAsByte
ErrorCharAsByte
EofCharAsByte
EvtCharAsByte
wReserved1AsInteger'
Reserved;
DoNotUse
PrivateTypeOVERLAPPED
InternalAsLong
InternalHighAsLong
offsetAsLong
OffsetHighAsLong
hEventAsLong
PrivateTypeSECURITY_ATTRIBUTES
nLengthAsLong
lpSecurityDescriptorAsLong
bInheritHandleAsLong
SystemFunctions
FillsaspecifiedDCBstructurewithvaluesspecifiedin
adevice-controlstring.
PrivateDeclareFunctionBuildCommDCBLib"
kernel32"
Alias"
BuildCommDCBA"
_
(ByVallpDefAsString,lpDCBAsDCB)AsLong
Retrievesinformationaboutacommunicationserrorandreports
thecurrentstatusofacommunicationsdevice.Thefunctionis
calledwhenacommunicationserroroccurs,anditclearsthe
device'
serrorflagtoenableadditionalinputandoutput
(I/O)operations.
PrivateDeclareFunctionClearCommErrorLib"
(ByValhFileAsLong,lpErrorsAsLong,lpStatAsCOMSTAT)AsLong
Closesanopencommunicationsdeviceorfilehandle.
PrivateDeclareFunctionCloseHandleLib"
(ByValhObjectAsLong)AsLong
Createsoropensacommunicationsresourceandreturnsahandle
thatcanbeusedtoaccesstheresource.
PrivateDeclareFunctionCreateFileLib"
CreateFileA"
(ByVallpFileNameAsString,ByValdwDesiredAccessAsLong,_
ByValdwShareModeAsLong,lpSecurityAttributesAsAny,_
ByValdwCreationDispositionAsLong,ByValdwFlagsAndAttributesAsLong,_
ByValhTemplateFileAsLong)AsLong
Directsaspecifiedcommunicationsdevicetoperformafunction.
PrivateDeclareFunctionEscapeCommFunctionLib"
(ByValnCidAsLong,ByValnFuncAsLong)AsLong
Formatsamessagestringsuchasanerrorstringreturned
byanoherfunction.
PrivateDeclareFunctionFormatMessageLib"
FormatMessageA"
(ByValdwFlagsAsLong,lpSourceAsAny,ByValdwMessageIdAsLong,_
ByValdwLanguageIdAsLong,ByVallpBufferAsString,ByValnSizeAsLong,_
ArgumentsAsLong)AsLong
Retrievesmodemcontrol-registervalues.
PrivateDeclareFunctionGetCommModemStatusLib"
(ByValhFileAsLong,lpModemStatAsLong)AsLong
Retrievesthecurrentcontrolsettingsforaspecified
PrivateDeclareFunctionGetCommStateLib"
(ByValnCidAsLong,lpDCBAsDCB)AsLong
Retrievesthecallingthread'
slast-errorcodevalue.
PrivateDeclareFunctionGetLastErrorLib"
()AsLong
Retrievestheresultsofanoverlappedoperationonthe
specifiedfile,namedpipe,orcommunicationsdevice.
PrivateDeclareFunctionGetOverlappedResultLib"
(ByValhFileAsLong,lpOverlappedAsOVERLAPPED,_
lpNumberOfBytesTransferredAsLong,ByValbWaitAsLong)AsLong
Discardsallcharactersfromtheoutputorinputbufferofa
specifiedcommunicationsresource.Itcanalsoterminate
pendingreadorwriteoperationsontheresource.
PrivateDeclareFunctionPurgeCommLib"
(ByValhFileAsLong,ByValdwFlagsAsLong)AsLong
Readsdatafromafile,startingatthepositionindicatedbythe
filepointer.Afterthereadoperationhasbeencompleted,the
filepointerisadjustedbythenumberofbytesactuallyread,
unlessthefilehandleiscreatedwiththeoverlappedattribute.
Ifthefilehandleiscreatedforoverlappedinputandoutput
(I/O),theapplicationmustadjustthepositionofthefilepointer
afterthereadoperation.
PrivateDeclareFunctionReadFileLib"
(ByValhFileAsLong,ByVallpBufferAsString,_
ByValnNumberOfBytesToReadAsLong,ByReflpNumberOfBytesReadAsLong,_
lpOverlappedAsOVERLAPPED)AsLong
Configuresacommunicationsdeviceaccordingtothespecifications
inadevice-controlblock(aDCBstructure).Thefunction
reinitializesallhardwareandcontrolsettings,butitdoesnot
emptyoutputorinputqueues.
PrivateDeclareFunctionSetCommStateLib"
(ByValhCommDevAsLong,lpDCBAsDCB)AsLong
Setsthetime-outparametersforallreadandwriteoperationsona
specifiedcommunicationsdevice.
PrivateDeclareFunctionSetCommTimeoutsLib"
(ByValhFileAsLong,lpCommTimeoutsAsCOMMTIMEOUTS)AsLong
Initializesthecommunicationsparametersforaspecified
PrivateDeclareFunctionSetupCommLib"
(ByValhFileAsLong,ByValdwInQueueAsLong,ByValdwOutQueueAsLong)AsLong
Writesdatatoafileandisdesignedforbothsynchronousanda
synchronousoperation.Thefunctionstartswritingdatatothefile
atthepositionindicatedbythefilepointer.Afterthewrite
operationhasbeencompleted,thefilepointerisadjustedbythe
numberofbytesactuallywritten,exceptwhenthefileisopenedwith
FILE_FLAG_OVERLAPPED.Ifthefilehandlewascreatedforoverlapped
inputandoutput(I/O),theapplicationmustadjustthepositionof
thefilepointerafterthewriteoperationisfinished.
PrivateDeclareFunctionWriteFileLib"
ByValnNumberOfBytesToWriteAsLong,lpNumberOfBytesWrittenAsLong,_
PrivateDeclareSubAppSleepLib"
Sleep"
(ByValdwMillisecondsAsLong)
ProgramConstants
PrivateConstMAX_PORTS=4
ProgramStructures
PrivateTypeCOMM_ERROR
lngErrorCodeAsLong
strFunctionAsString
strErrorMessageAsString
PrivateTypeCOMM_PORT
lngHandleAsLong
blnPortOpenAsBoolean
udtDCBAsDCB
ProgramStorage
PrivateudtCommOverlapAsOVERLAPPED
PrivateudtCommErrorAsCOMM_ERROR
PrivateudtPorts(1ToMAX_PORTS)AsCOMM_PORT
GetSystemMessage-Getssystemerrortextforthespecifiederrorcode.
PublicFunctionGetSystemMessage(lngErrorCodeAsLong)AsString
DimintPos
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VBA 使用 API 串口 通信 SerialPort 英文