thaburner
asked on
Hyper Terminal - Send/Receive Data
I have some hardware that I connect through RS485 and use Hyper Termanal to talk to right now. I would like to use MSCOMM to send the Command "GetData" so i can receive the following data for Input.
SerialNumber=192034 Points=10939 etc...
SerialNumber=192034 Points=10939 etc...
ASKER
I can connect fine and send the command for output fine with out errors, but I'm not receiving any data?
A. Make sure you have the protocol, handshaking, stop bits etc. correct.
B. You might have to send vbCR or vbCRLF or vbLF to actualy have the device register the input.
i.e. Just like when you hit enter in hyperterminal....
i.e. Output=My String & chr$(13) - ookup ascii tablefor future reference 13 is a carriage return
or
Output=MyString & vbCR (although I like to send CHRs ...
C.Put a breakpoint in you MSCOMM OnComm event and see if it ever fires.
B. You might have to send vbCR or vbCRLF or vbLF to actualy have the device register the input.
i.e. Just like when you hit enter in hyperterminal....
i.e. Output=My String & chr$(13) - ookup ascii tablefor future reference 13 is a carriage return
or
Output=MyString & vbCR (although I like to send CHRs ...
C.Put a breakpoint in you MSCOMM OnComm event and see if it ever fires.
ASKER
I have the Stop bits etc is all correct and I tried the vbCR & etc and i get char's back; just some funcky symbols. Is their another setting that I should try to add? I should just get a bunch of numbers and spaces back.
ASKER
In hyper terminal this is what the settings are at.
Baud = 38400
Data Bits = 8
party = none
stop bits = 1
Flow control = none
Baud = 38400
Data Bits = 8
party = none
stop bits = 1
Flow control = none
I hate to say, but its a red flag that your settings are not correct if you see stuff coming back, but its garbage looking. Its not FlowControl, since if it was wrong you'd see nothing or only beginning of a message.
most likely your MSCCOMM1.Setting strings is wrong
it should be something like:
MSComm1.Settings = "38400,N,8,1"
Check your InputMode to be 0 i.e. text (even if you are, or will be sending binary data)
Check your CommPort property to be set to the correct comm port (sorry, but you never know).
most likely your MSCCOMM1.Setting strings is wrong
it should be something like:
MSComm1.Settings = "38400,N,8,1"
Check your InputMode to be 0 i.e. text (even if you are, or will be sending binary data)
Check your CommPort property to be set to the correct comm port (sorry, but you never know).
ASKER
OK I dont know what I did but I got it working, except for one problem I can't figure out. For some reason it will only show me the data in the text box if i call the mscomm1.input by msgbox first.
This is the line that has to be called first before it will copy the input to the textbox, but when this line is called it also shows up empty in the Msgbox.
If Check1.Value = vbChecked Then MsgBox "Input: " & Me.MSComm1.Input
Dim sData As String
Private Sub Command1_Click()
'MSComm1.Output = Text1.Text
MSComm1.Output = Text1.Text & vbCrLf
'MSComm1.Output = Text1.Text & vbLf
'MSComm1.Output = Text1.Text & vbcr
'MsgBox "Data sent: " & Text1.Text
End Sub
Private Sub Command2_Click()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = 3
MSComm1.Settings = "38400,N,8,1"
MSComm1.RThreshold = 1
MSComm1.InputMode = 0
'MSComm1.InputLen = 0
MSComm1.OutBufferSize = 1024
MSComm1.InBufferSize = 1024
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Label1.Caption = "Connected"
Else
Label1.Caption = "Not Connected"
End If
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive ' Received RThreshold # of chars.
readdata = readdata & Me.MSComm1.Input
If Check1.Value = vbChecked Then MsgBox "Input: " & Me.MSComm1.Input
txtID.Text = txtID.Text & MSComm1.Input
If Right$(readdata, 2) = vbCrLf Then
'MsgBox "Received Data: " & readdata
txtID.Text = txtID.Text & readdata
Else
'MsgBox "Connection Failed"
End If
End Select
End Sub
This is the line that has to be called first before it will copy the input to the textbox, but when this line is called it also shows up empty in the Msgbox.
If Check1.Value = vbChecked Then MsgBox "Input: " & Me.MSComm1.Input
Dim sData As String
Private Sub Command1_Click()
'MSComm1.Output = Text1.Text
MSComm1.Output = Text1.Text & vbCrLf
'MSComm1.Output = Text1.Text & vbLf
'MSComm1.Output = Text1.Text & vbcr
'MsgBox "Data sent: " & Text1.Text
End Sub
Private Sub Command2_Click()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
MSComm1.CommPort = 3
MSComm1.Settings = "38400,N,8,1"
MSComm1.RThreshold = 1
MSComm1.InputMode = 0
'MSComm1.InputLen = 0
MSComm1.OutBufferSize = 1024
MSComm1.InBufferSize = 1024
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
Label1.Caption = "Connected"
Else
Label1.Caption = "Not Connected"
End If
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive ' Received RThreshold # of chars.
readdata = readdata & Me.MSComm1.Input
If Check1.Value = vbChecked Then MsgBox "Input: " & Me.MSComm1.Input
txtID.Text = txtID.Text & MSComm1.Input
If Right$(readdata, 2) = vbCrLf Then
'MsgBox "Received Data: " & readdata
txtID.Text = txtID.Text & readdata
Else
'MsgBox "Connection Failed"
End If
End Select
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that did the trick.... Thanks alot for your help
The setup for the port looks something like this:
MSComm1.CommPort = 1
MSComm1.Settings = "38400,O,8,1"
MSComm1.RThreshold = 1
MSComm1.InputMode = 1
MSComm1.InputLen = 1
If MSComm1.PortOpen = False Then MSComm1.PortOpen = True
-----------
To send you do something like:
MSComm1.Outout = String you want to send to the device.
--------------
To receive data, you will pick it up in the MSComm event:
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent ' event causation
Case comEvReceive ' received data
MSComm1.InputLen = 1
Do While MSComm1.InBufferCount > 0 ' get each char
MyBuffer = Mybuffer & MSComm1.Input
Loop
End Select
end sub
There are plenty of events to look at if you want to capture other things ...
Also keep in mind that once you read MSComm1.Iput (i.e. copy it anywhere) its emptied of its data,
that is why its adding data to some buffer, remember to clear out your "buffer" after you get the data.
You could also just wait for the MSComm1.inputbuffer to be greater or equal to something before you get data out of MSComm1.Input.
Also the MSComm1.RThreshold = 1 at the top sets up when you comm event fires, i.e. after 1 character received in the buffer. If you know you will always receive 10 you could set it to 10...
--------------------------
Another way , simpler but more limited is to set RThreshold=0 this will disable the OnComm event
the after doing the .Output you could sit in the loop and wait for your data to come in by reading the .Input ...