Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,

I'm working in vb6 with an external device connected through rs232. the data was loaded in external device in hex format and now using rs232 i want to download that data to my computer using vb6 programming but i'm unable to download

the hex code i should receive is

:108000000000000300000000000603000304030456
:108010000605030303030404000000000000000041
:10802000000000000000000001000000000000014E
:10803000FFFFFFFFFFFFFFFFFFFFFFFF0202020244

please help me
Thank You

What I have tried:

Option Explicit
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim buf As String
Dim ff As Integer

Private Sub configure_Click()

Form2.Show

End Sub

'Private Sub Form_KeyPress(KeyAscii As Integer)

'MSComm1.Output = KeyAscii
'MSComm1.PortOpen = False

'End Sub

Private Sub MSComm1_OnComm()

MSComm1.Settings = "115200,N,8,1"
MSComm1.DTREnable = True
MSComm1.RThreshold = 1
MSComm1.RTSEnable = True
MSComm1.SThreshold = 1
MSComm1.InputLen = 1

Select Case MSComm1.CommEvent
Case comBreak
MsgBox ("Break Received")
Case comCDTO
Case comCTSTO
Case comDSRTO
Case comFrame
Case comOverrun
Case comRxOver
Case comRxParity
Case comTxFull
Case comEvCD
Case comEvCTS
Case comEvDSR
Case comEvRing
Case comEvReceive
MSComm1.Output = buf
Case comEvSend
End Select

End Sub

Private Sub download_Click()

If MSComm1.PortOpen = True Then

With CommonDialog1
.InitDir = App.Path
.FileName = ""
.Filter = "Hex File (*.hex)|*.hex"
.ShowSave

ff = FreeFile
Open .FileName For Output As #ff
Write #ff, buf
Close #ff

End With
End If

End Sub
Posted
Comments
[no name] 24-Mar-18 4:50am    
Where is the code to read from the device? You should also be reading in raw bytes, as that is what is generally transferred across communication lines.
Member 13396059 24-Mar-18 6:50am    
Private Sub opencmd_Click()

MSComm1.CommPort = 4
MSComm1.Settings = "115200,N,8,1"
MSComm1.PortOpen = True
lblstatus.Caption = "Open"
lblstatus.ForeColor = &HC000&

End Sub

Private Sub Receive_Click()


Dim data As Variant
Dim ff

Do
ff = FreeFile
data = MSComm1.Input
Open "C:\Data.hex" For Append As #ff
Print #ff, data
Close #ff

Loop Until MSComm1.InBufferCount = 0 'As long as there is data in the buffer OR Returns 0 if user clicks "Close Port"

End Sub

when i'm using this code i'm getting printed 1
but not getting hexcode
[no name] 24-Mar-18 6:53am    
"but not getting hexcode"
No, because the device will be sending raw bytes.You should check the device documentation to see what is being returned.
Member 13396059 24-Mar-18 7:41am    
okay,thank u so much..i will check the document

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900