Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSComm for RS 232 Communication

Status
Not open for further replies.

GPS232

Programmer
Mar 8, 2004
2
US
Hello. I am a novice user of Microsoft Visual Basic 6.0 and I am trying to teach myself how to interface VB 6 with the serial port using RS232. From what I have gathered so far I found that I need to use the control component MSComm to access the serial port using VB. So far I haven't had any luck. All I am trying to do is send some data out of the port and detect the presence of the data on the cable using an oscilloscope. Is there any reason I should not be able to detect this data as such? Is the data perhaps being stored in the transmitt buffer and not being allowed to enter the serial line of the cable. The code I am executing to try and accomplish this is as follows:

Private Sub MSComm1_OnComm()

Dim SampleText As String
SampleText = "ABC"
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.Settings = "9600,N,8,1"

Do While True
MSComm1.Output = SampleText
Loop

End Sub

Inside my hardware manager in Windows XP I have the same settings as in the Settings command in the code I have provided above. I'm pretty stuck. Please help. If there is anything that I need to clarify please let me know. Thanks a lot in advance.
 
As a start have read of article Q151899 in the Microsoft Knowledge Base.

Enjoy.

"Life is full of learning, and then there is wisdom"
 
Looks like it will hang in the loop forever. The "OnComm" event is raised only when the value of the CommEvent property changes. Probably nothing is happening to change that property so the sub is not being run. Try putting a button on your form and place this code (without the infinite loop) in its click event.
 
The new code looks like this:

Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.Settings = "9600,N,8,1"
End Sub

Private Sub Command1_Click()
Dim SampleText As String
SampleText = "ABC"
MSComm1.Output = SampleText
Text1.Text = SampleText
End Sub

I removed the infinte loop, which I purposely put in there, perhaps incorrectly, to make VB send the data continually to the port. That was my reasoning, perhaps it was flawed based on the OnComm stuff you told me about. Honestly, I'm not very familiar with that so I'm not sure what to make of your explaination, but I do apprecaite it. Perhaps you could dumb it down a little for me.

So everytime that I hit the Command1 Button I tested a different of the 9 pins on the serial port and everytime I get no change in the output. Specifically, the output is a 60Hz +/- 14V pulse train. The pulse train is pretty jagged so I'm not sure if thats how it is supposed to look but whether or not I compile the application and press the command button, the output of each pin on the serial port of my computer is exactly the same and never changes.

Another question is how do I figure out what the name of the serial port is. I checked in the hardware profile of windows in the Control Panel and it seems that it is COMM1 but I'm not positive.

Is it possible that the data is being sent but is not making it out of the transmitt buffer, therefore remaining undetectable to me?

Also, koala15, the article ID number you gave me for Microsoft Knowledge base is invalid, it seems the article has been removed. Do you know of another way that I may access this article?

Thanks
 
1. If you have 60Hz everywhere you probably have a floating earth on your 'scope. Solve this one first!

2. Let your software run it's infinite loop while you sort out your hardware problems - you will never see the signal otherwise. You are looking for a 9.6KHz assymetric square wave.

3. Your signal should be on pin 3 of the DB9 connector

4. Handshaking. You need to provide appropriate handshaking. look at :
or any other standard RS232 site for details (look for a 'null-modem' connection)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top