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...
thaburnerAsked:
Who is Participating?
 
VR4Commented:
once you read the MSCOmm1.Input it is reset to an empty string.
So second time you read it it will A. Be empty (as in your case) B it will have data that arrived after you first read it.

Since your got data out of the buffer with readdata = readdata & Me.MSComm1.Input
then Text box (txtID.Text = txtID.Text & MSComm1.Input will return nothing , since by then MSCOmm1.Input="")
The point of reading it in the readdata is to buffer it in your own little buffer.
Make sure to clear it once you get what you need out of it.

In general your :
      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

should be elswhere and you buffering mechanism should be in MSComm1_OnComm.

Then at your leasure you can do anything you want with readdata.

Or if you want you can make your Text1.Text be your buffer (in your case it will not make much difference). At least then you will see how data gets into your buffer.

---------
so for your testing try this:
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
        Case comEvReceive   ' Received RThreshold # of chars.
                  txtID.Text = txtID.Text & MSComm1.Input
End Select
End Sub
0
 
VR4Commented:
drop Mscomm on the form,

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 ...
0
 
thaburnerAuthor Commented:
I can connect fine and send the command for output fine with out errors, but I'm not receiving any data?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
VR4Commented:
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.

0
 
thaburnerAuthor Commented:
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.
0
 
thaburnerAuthor Commented:
In hyper terminal this is what the settings are at.

Baud = 38400
Data Bits = 8
party = none
stop bits = 1
Flow control = none
0
 
VR4Commented:
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).


0
 
thaburnerAuthor Commented:
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
0
 
thaburnerAuthor Commented:
that did the trick.... Thanks alot for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.