Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Hyper Terminal - Send/Receive Data

Posted on 2007-08-10
9
Medium Priority
?
481 Views
Last Modified: 2013-11-05
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...
0
Comment
Question by:thaburner
  • 5
  • 4
9 Comments
 
LVL 3

Expert Comment

by:VR4
ID: 19675004
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
 

Author Comment

by:thaburner
ID: 19685150
I can connect fine and send the command for output fine with out errors, but I'm not receiving any data?
0
 
LVL 3

Expert Comment

by:VR4
ID: 19688677
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:thaburner
ID: 19730080
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
 

Author Comment

by:thaburner
ID: 19730084
In hyper terminal this is what the settings are at.

Baud = 38400
Data Bits = 8
party = none
stop bits = 1
Flow control = none
0
 
LVL 3

Expert Comment

by:VR4
ID: 19730718
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
 

Author Comment

by:thaburner
ID: 19733691
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
 
LVL 3

Accepted Solution

by:
VR4 earned 2000 total points
ID: 19733809
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
 

Author Comment

by:thaburner
ID: 19734059
that did the trick.... Thanks alot for your help
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question