serial communications
serial communications
serial communications
serial communications
serial communications
serial communications serial communications serial communications serial communications serial communications serial communications serial communications serial communications
serial communications serial communications
serial communications
Go Back  Xtreme Visual Basic Talk > > > serial communications


Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2003, 04:19 PM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default serial communications


I’m having trouble with serial communications between a laptop computer and a transmitting set connected together with a RS-232. What should be happening is the transmitting set sends over “A” to the laptop, the laptop receives that “A” and sends “B” to the transmitting set. Then the transmitting set sends over “C” to the laptop, the laptop receives and then sends over “D” to the transmitting set. But right now, I can only receive but cannot send. This is my code. Please help. Thanks.

Private Sub MSComm1_OnComm()
Dim inData As String
Dim outData As String
Select Case MSComm1.CommEvent
Case comEvReceive
inData = MSComm1.Input
If InStr(inData, "A") > 0 Then
MsgBox "A received."
End If
outData = MSComm1.Output
If MSComm1.Output = "B" Then
MsgBox "B sent."
End If
If InStr(inData, "C") > 0 Then
MsgBox "C received."
End If

If MSComm1.Output = "D" Then
MsgBox "D sent."
End If
Case comEvSend
Case comEvEOF
End Select
End Sub
Reply With Quote
  #2  
Old 11-19-2003, 06:22 PM
BillSoo's Avatar
BillSooserial communications BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

This is odd:
If MSComm1.Output = "B" Then

The Output method doesn't return anything (I think) so there is no point doing it like this...

Try:
Code:
If Instr(inData,"A") then mscomm1.output "B" If Instr(inData,"C") then mscomm1.output "D"
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #3  
Old 11-20-2003, 09:19 AM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

Hi BillSoo,

I tried your method and put a break on at Case comEvReceive, but when the transmitting set is turned on, there was an error with MSComm1.Output "B", highlighting Output stating "Invalid use of property." Please help.
Reply With Quote
  #4  
Old 11-20-2003, 01:16 PM
GAS GAS is offline
Newcomer
 
Join Date: Nov 2003
Location: Kingdom of Bahrain
Posts: 3
Default

Quote:
Originally Posted by kasey
Hi BillSoo,

I tried your method and put a break on at Case comEvReceive, but when the transmitting set is turned on, there was an error with MSComm1.Output "B", highlighting Output stating "Invalid use of property." Please help.



The mscomm1.output is a proprty not a method, so you should use '=' as the following:

Code:
If Instr(inData,"A") Then mscomm1.output = "B" If Instr(inData,"C") Then mscomm1.output = "D"
Reply With Quote
  #5  
Old 11-20-2003, 02:06 PM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

I added the equal sign but the property of MSComm1.Output is write only, so it was not able to send out.
Reply With Quote
  #6  
Old 11-20-2003, 02:41 PM
GAS GAS is offline
Newcomer
 
Join Date: Nov 2003
Location: Kingdom of Bahrain
Posts: 3
Default

Quote:
Originally Posted by kasey
I added the equal sign but the property of MSComm1.Output is write only, so it was not able to send out.




Use this code

Code:
Private Sub MSComm1_OnComm() Dim inData As String Select Case MSComm1.CommEvent Case comEvReceive inData = MSComm1.Input If InStr(inData, "A") > 0 Then MsgBox "A received." MSComm1.Output = "B" MsgBox "B sent." ElseIf InStr(inData, "C") > 0 Then MsgBox "C received." MSComm1.Output = "D" MsgBox "D sent." End If Case comEvSend 'DoNothing Case comEvEOF 'DoNothing End Select End Sub
Reply With Quote
  #7  
Old 11-20-2003, 03:02 PM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

I used that exact same code and placed a debugger at Case comEvReceive and stepped through it, when it got to MSComm1.Output, it states <Property is write only>.
Reply With Quote
  #8  
Old 11-21-2003, 11:05 AM
mbruner mbruner is offline
Newcomer
 
Join Date: Nov 2003
Location: Longmont, CO
Posts: 21
Default

Why don't you back track a bit and see if you can get it to work without mscomm.

http://www.thescarms.com/vbasic/CommIO.asp

You also may want to verify the mscomm properties to insure that they are set correctly. I would write a quick and dirty program to send a byte whenever a key is pressed.

Is it possible that you are getting the <Property is write only> message because the debugger is trying to read it?

good luck,

Marty
Reply With Quote
  #9  
Old 11-22-2003, 08:22 PM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

Hi! These are the properties that I have set for MSComm1 in the Sub Form_Load():

Code:
With MSComm1 .Handshaking = 2 .RThreshold = 1 .RTSEnable = true .Settings = "1200,n,8,1" .SThreshold = 1 If .PortOpen = False Then .PortOpen = True End If End With
Please help. Thanks.
Reply With Quote
  #10  
Old 11-22-2003, 08:38 PM
mbruner mbruner is offline
Newcomer
 
Join Date: Nov 2003
Location: Longmont, CO
Posts: 21
Default

Quote:
Originally Posted by kasey
Hi! These are the properties that I have set for MSComm1 in the Sub Form_Load():

Code:
With MSComm1 .Handshaking = 2 .RThreshold = 1 .RTSEnable = true .Settings = "1200,n,8,1" .SThreshold = 1 If .PortOpen = False Then .PortOpen = True End If End With
Please help. Thanks.



It looks like you have RTS/CTS set. Now if the device you are talking to does not send a CTS, I don't think the UART will transmit. How about trying to set Handshaking to 0.
Reply With Quote
  #11  
Old 11-22-2003, 10:50 PM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

The laptop computer is receiving just fine, but not able to transmit. So if it can receive, then would setting handshaking to 0 matters? I'm new at this, so I might be asking some odd questions :-)
Reply With Quote
  #12  
Old 11-23-2003, 01:26 AM
mbruner mbruner is offline
Newcomer
 
Join Date: Nov 2003
Location: Longmont, CO
Posts: 21
Default

Quote:
Originally Posted by kasey
The laptop computer is receiving just fine, but not able to transmit. So if it can receive, then would setting handshaking to 0 matters? I'm new at this, so I might be asking some odd questions :-)



Yes it does...If your "transmitting set" is ignoring the handshake signal, of course. Handshaking is used to control the transmitting of characters.
Reply With Quote
  #13  
Old 11-24-2003, 10:31 AM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

I set handshaking equals to 0, but it is still not sending data to the transmitting set. I still get the same error "Property is write only." Is there a way to set it so the property won't be write only. Thanks.
Reply With Quote
  #14  
Old 11-24-2003, 10:40 AM
mbruner mbruner is offline
Newcomer
 
Join Date: Nov 2003
Location: Longmont, CO
Posts: 21
Default

Quote:
Originally Posted by kasey
I set handshaking equals to 0, but it is still not sending data to the transmitting set. I still get the same error "Property is write only." Is there a way to set it so the property won't be write only. Thanks.



When you say "Transmitting set" What are you referring too? is is another computer?
Reply With Quote
  #15  
Old 11-24-2003, 10:45 AM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

No, it's not another computer, it's actually a transmitting test set that contains circuit boards, and that transmitting test set is connected to the laptop with a RS-232.
Reply With Quote
  #16  
Old 11-24-2003, 11:55 PM
BillSoo's Avatar
BillSooserial communications BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

OK, there is no way you should be getting that error message....I've NEVER seen that message in regard to mscomm before!

So post your code. I'm sure you must be doing something odd in there....
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #17  
Old 11-25-2003, 08:16 AM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

Here is my code:

Code:
Option Explicit Private Sub Form_Load() 'Communication with test set to receive data With MSComm1 .Handshaking = 2 - comRTS .RThreshold = 1 .RTSEnable = True .Settings = "1200,n,8,1" 'baud rate, parity, data bits, stop bits .SThreshold = 1 If .PortOpen = False Then .PortOpen = True End If ' Leave all other settings as default values. End With End Sub Private Sub MSComm1_OnComm() Dim inData As String Dim outData As String Dim EVMsg$ Select Case MSComm1.CommEvent Case comEventBreak ' A Break was received. EVMsg$ = "Break Received" Case comEventCTSTO ' CTS Timeout. EVMsg$ = "Change in CTS Detected" Case comEventDSRTO ' DSR Timeout. EVMsg$ = "Change in DSR Detected" Case comEventFrame ' Framing Error. EVMsg$ = "Framing Error Detected" Case comEventOverrun ' Data Lost. EVMsg$ = "Overrun Error Detected" Case comEventRxOver ' Receive buffer overflow. EVMsg$ = "Receive Buffer Overflow" Case comEventRxParity ' Parity Error. EVMsg$ = "Parity Error" Case comEventTxFull ' Transmit buffer full. EVMsg$ = "Transmit Buffer Full" Case comEventDCB ' Unexpected error retrieving DCB EVMsg$ = "Unexpected Error Retrieved" Case comEvCD ' Change in the CD line. Case comEvCTS ' Change in the CTS line. Case comEvDSR ' Change in the DSR line. Case comEvRing ' Change in the Ring Indicator. Case comEvReceive ' Received RThreshold # of chars. 'Receiving test data sent from test set to display on screen inData = MSComm1.Input MSComm1.Output = outData If InStr(inData, "A") > 0 Then Label5.Visible = False 'Awaiting Handshake... Label23.Visible = True 'Handshake Received MsgBox "A received." If MSComm1.Output = "B" Then Label24.Visible = True 'Handshake Returned MsgBox "B sent." End If End If If InStr(inData, "C") > 0 Then MsgBox "C received." Label2.Visible = False 'Awaiting Reprogram Flag... Label4.Visible = False 'Awaiting Reprogram Handshake... If MSComm1.Output = "D" Then Label22.Visible = True 'Reprogram Flag Received MsgBox "D sent." End If End If Case comEvSend ' SThreshold number of characters in the transmit buffer. Case comEvEOF ' An EOF character was found in the input stream. End Select End Sub
Reply With Quote
  #18  
Old 11-25-2003, 06:11 PM
BillSoo's Avatar
BillSooserial communications BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

You are READING the output property in a couple of places. Here is one of them:

If MSComm1.Output = "B" Then

Don't do this.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #19  
Old 11-25-2003, 10:24 PM
kasey kasey is offline
Freshman
 
Join Date: Nov 2003
Location: CA
Posts: 43
Default

You said I shouldn't be reading the output from more than 1 place, but the requirement of the project is to transmit every time a character is received. What are your suggestions? Please show me how I can fix the errors. Thanks.
Reply With Quote
  #20  
Old 11-26-2003, 01:10 AM
BillSoo's Avatar
BillSooserial communications BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

You misunderstand me....I'm saying you cannot READ the OUTPUT property at all.

At a guess, just drop the IF structure.

For instance, instead of:
Code:
If MSComm1.Output = "B" Then Label24.Visible = True 'Handshake Returned MsgBox "B sent." End If

change it to:
Code:
MSComm1.Output = "B" Label24.Visible = True 'Handshake Returned MsgBox "B sent."

Since I don't know what you are trying to do, I don't know if it will work for you, but at least it should fix the error.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MSComm serial communications brian93 Communications 1 11-12-2003 04:43 AM
Serial Communications Thanatos Communications 0 06-09-2003 12:59 PM
Problems with a serial communications Faust Communications 6 01-28-2003 07:56 AM
Serial port communications dwfvb Communications 1 07-05-2002 10:12 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
serial communications
serial communications
serial communications serial communications
serial communications
serial communications
serial communications serial communications serial communications serial communications serial communications serial communications serial communications
serial communications
serial communications
 
serial communications
serial communications
 
-->