|
-
Mar 23rd, 2006, 05:25 AM
#1
Thread Starter
Hyperactive Member
-
Mar 23rd, 2006, 08:18 AM
#2
Re: MSCOMM send 4kb binary data to device
 Originally Posted by VB Client/Server
In my curent project, I send all data, but last 16 bytes what I send become 17 bytes ( WHY )? 
Welcome to the forums. 
Post the code you are using for this.
-
Mar 23rd, 2006, 09:37 AM
#3
Thread Starter
Hyperactive Member
Re: MSCOMM send 4kb binary data to device
Private Sub Command1_Click()
Cdlg.DialogTitle = "Send file..."
Cdlg.Filter = "Binary File (*.BIN)|*.bin|All Files (*.*)|*.*"
Cdlg.InitDir = App.Path
Cdlg.FileName = ""
Cdlg.ShowOpen
' The Function Call
If Cdlg.FileName <> "" Then SendFile (Cdlg.FileName)
End Sub
Private Sub Form_Load()
' Opens the selected com port
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub
' here is the function
Function SendFile(tmp$)
Dim temp$
Dim hsend, bsize, LF&
' Open file
Open tmp$ For Binary Access Read As #2
' Check size on Mscomm1 OutBuffer
bsize = MSComm1.OutBufferSize
' Check file length
LF& = LOF(2)
' This code makes tiny pieces of data (Buffer sized)
' And send's it
Do Until EOF(2)
If LF& - Loc(2) <= bsize Then
bsize = LF& - Loc(2) + 1
End If
' Make room for some data
temp$ = Space$(bsize)
' Put the data piece in the Temp$ string
Get #2, , temp$
MSComm1.Output = temp$
Do
' Wait until the buffer is empty
Loop Until MSComm1.OutBufferCount = 0
Loop
' close file
Close #2
End Function
And MSCOMM settings are:
DTREnable=False
EOFEnable=True
Handshaking=0
InBufferSize=16384
InputMode=1 - comInputModeBinary
OutBufferSize=16
ParityReplace=N
RThreshold=1
RTSEnable=False
Settings=115200,n,8,1
SThreshold=1
And thanx for welcoming note
B.R
Last edited by VB Client/Server; Mar 23rd, 2006 at 10:52 AM.
-
Mar 24th, 2006, 03:41 AM
#4
Thread Starter
Hyperactive Member
Re: MSCOMM send 4kb binary data to device
Function SendFile(tmp$)
On Error GoTo Error
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
If Option1.Value = True Then MSComm1.CommPort = 1
If Option2.Value = True Then MSComm1.CommPort = 6
If Option3.Value = True Then MSComm1.Settings = "57600,N,8,1"
If Option4.Value = True Then MSComm1.Settings = "115200,N,8,1"
MSComm1.RTSEnable = True
MSComm1.DTREnable = False
MSComm1.PortOpen = True
' Send binary data to prepare device for writing
Binary ("06")
' wait for device become ready
pause (10)
Dim temp$
Dim hsend, bsize, LF&
' Open file
Open tmp$ For Binary Access Read As #2
' Check size on Mscomm1 OutBuffer
bsize = MSComm1.OutBufferSize
' Check file length
LF& = LOF(2)
' This code makes tiny pieces of data (Buffer sized)
' And send's it
Do Until EOF(2)
If LF& - Loc(2) <= bsize Then
bsize = LF& - Loc(2) + 0
End If
' Make room for some data
temp$ = Space$(bsize)
' Put the data piece in the Temp$ string
Get #2, , temp$
MSComm1.Output = temp$
Do
pause 10
Loop Until MSComm1.OutBufferCount = 0
Loop
Error:
MsgBox "xxxxx", vbInformation, "xxxxx"
Close #2
End Function
Now I have make some changes to code and device are programmed OK.
But still some error's like, when I send all data, COM Port still stay's active
and I just dont know how to make code that afther sending all data
when buffer is empty close Port.
Any sugestion's "HACK" ?
I know that code must be somwhere in Do - Loop...
B.R
-
Mar 24th, 2006, 10:13 AM
#5
Thread Starter
Hyperactive Member
Re: MSCOMM send 4kb binary data to device
Problem solved!
I put timer to close port few sec afther all data are sent.
Maybe not best solution, but it works OK on few PC-s.
B.R
-
Apr 23rd, 2006, 08:53 AM
#6
Thread Starter
Hyperactive Member
Re: MSCOMM send 4kb binary data to device
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|