如果是普通的字符串,直接发送就可以了。如果是大文件,请使用下面的函数将文件分解,再发送。Public Sub FiletoBlob(filename As String, Optional ChunkSize As Long = 8192)'8192是每段的大小,可以任意调整,和你的Buffer匹配就可以了。Dim fnum As Integer, bytesleft As Long, bytes As Long Dim tmp() As ByteIf (fld.Attributes And adFldLong) = 0 Then Err.Raise 1001, , "field doesn't support the GetChunk method." End IfIf Dir$(filename) = "" Then Err.Raise 53, , "文件未找到"fnum = FreeFile Open filename For Binary As fnum bytesleft = LOF(fnum)Do While bytesleft bytes = bytesleftIf bytes > ChunkSize Then bytes = ChunkSize ReDim tmp(1 To bytes) As Byte Get fnum, , tmp'==========================tmp就是分好的小段,你在这里写发送代码。bytesleft = bytesleft - bytesLoop Close #fnum End Sub
MSComm1.Output = txtSend.Text
接收数据: MSComm1.PortOpen = True '别忘了关闭串口哈
buf = MSComm1.Input串口的其他参数,你自己定义哈。
QQ180040059(请注明:CSDN),
Dim tmp() As ByteIf (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "field doesn't support the GetChunk method."
End IfIf Dir$(filename) = "" Then Err.Raise 53, , "文件未找到"fnum = FreeFile
Open filename For Binary As fnum
bytesleft = LOF(fnum)Do While bytesleft
bytes = bytesleftIf bytes > ChunkSize Then bytes = ChunkSize
ReDim tmp(1 To bytes) As Byte
Get fnum, , tmp'==========================tmp就是分好的小段,你在这里写发送代码。bytesleft = bytesleft - bytesLoop
Close #fnum
End Sub