Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Serial Port


Serial Port

Author
Message
mvPradeepemb
mvPradeepemb
Forum God
Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)

Group: Forum Members
Posts: 46, Visits: 85
Hi All,

         I am new to VB....  I am using serial port to interface the controller with PC... My VB code as follows:


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

End Sub
   

Private Sub Form_Unload(Cancel As Integer)
       MSComm1.PortOpen = False
 End Sub


Private Sub MSComm1_OnComm()
       Text1.Text = Text1.text & MSComm1.input

End Sub

 

                I transmitted a number (03) from controller, but i am receiving garbage value like (*?????|||......)  and finally my serial port now doesn't work.... Kindly help me to solve the Problem...

Best Regards

Pradeep

Keithuk
Keithuk
Forum God
Forum God (54K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
Welcome to A1vbcode Pradeep

mvPradeepemb (11/6/2008)
Hi All,

Private Sub Form_Unload(Cancel As Integer)
       MSComm1.PortOpen = False
 End Sub

I haven't used MSComm1 that much I would think Chris (CDRIVE) can help you when he comes around.

What I would do in your Form_Unload is. Wink

Private Sub Form_Unload(Cancel As Integer)

If MSComm1.PortOpen = True Then
      MSComm1.PortOpen = False
End If

End Sub


Keith

I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

CDRIVE
CDRIVE
Forum God
Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
mvPradeepemb (11/6/2008)
Hi All,


Private Sub MSComm1_OnComm()
       Text1.Text = Text1.text & MSComm1.input

End Sub

First off, do as Keith suggested in the Form1_Unload event. Secondly, the way you're using the On_Comm event is like firing a scatter gun with a 6 inch barrel. That is to say it's not discriminating as to what fired On_Comm. On_Comm will fire when any change at the port occurs, including changes in Output, DTR, CTS, Received data, Input & Output Buffer properties and a bunch more.

The code below is suitable for inputting text data. The Input mode doesn't typically have to be defined at run time because it's the default value at design (Properties Window) time.

 

Option Explicit

Private Sub Form_Load()
   MSComm1.InputMode = comInputModeText        ' Default in properties window
End Sub

Private Sub MSComm1_OnComm()
   Dim InBuffer As String
   InBuffer = MSComm1.Input
   
      If MSComm1.CommEvent = comEvReceive Then
         Text1.Text = Text1.Text & InBuffer
      End If
End Sub

 

Now some Microcontrollers can TX & RX both ASCII and Byte data as HEX. Which are you attempting to input and do you also have to send data to the controller?

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

Edited
11/6/2008 by CDRIVE
CDRIVE
CDRIVE
Forum God
Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
BTW, if you would like to read through a very similar topic, then check this out.

http://www.martin2k.co.uk/forums/index.php?s=606e1bb5e0eb9a8eb27abd1b53cb3dd0&showtopic=5017

Yes Keith, I still don't know how to format these links like you do!

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

mvPradeepemb
mvPradeepemb
Forum God
Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)Forum God (2.8K reputation)

Group: Forum Members
Posts: 46, Visits: 85
Thanks for your valuable information.... Whether my earlier code will affect the serial port, because the port doesn't works now.....  Whether it is possible to access the USB port instead of serial port without any firmware(USB to Serial converter)......

Best Regards

Pradeep 

CDRIVE
CDRIVE
Forum God
Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
mvPradeepemb (11/7/2008)
Thanks for your valuable information.... Whether my earlier code will affect the serial port, because the port doesn't works now.....  Whether it is possible to access the USB port instead of serial port without any firmware(USB to Serial converter)......

Best Regards

Pradeep 

Yes, VB can access a USB port but your controller expects RS232 protocol which MSComm and your USB/Serial converter provides. Direct USB microcontrollers are not that common as yet and are much more expensive. You say that your USB/Serial converter stopped working. Do you have it plugged into the same USB port that it was in when it was working? Some USB/Serial converters (not all) must be plugged into the same physical USB port that it was set up with when the drivers were installed. Also try unplugging and re-plugging and check the Device Manager to make sure it was recognized when plugged in.

Also, tell me what microcontroller you are using and the brand of USB/Serial converter. Lastly; No, MSComm code can't do anything permanent to the port. When the port is closed or the app ends, the port is closed and released from VB.

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

Edited
11/7/2008 by CDRIVE
Mark
Mark
Forum God
Forum God (26K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
CDRIVE (11/7/2008)
Yes Keith, I still don't know how to format these links like you do!

This is the format you need. Of course without spaces in the tag

[url=http://www.google.com]Google[ /url]

CDRIVE
CDRIVE
Forum God
Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Mark (11/7/2008)
CDRIVE (11/7/2008)
Yes Keith, I still don't know how to format these links like you do!

This is the format you need. Of course without spaces in the tag

[url=http://www.google.com]Google[ /url]

No Mark, that's not what I meant. When Keith posts a link, no matter how long it is, or what the address is, he makes it look like this:

Click Here

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

Mark
Mark
Forum God
Forum God (26K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K
And did you try what I suggested?

Click Here

EDIT: If you try to quote this post you should see how the url tag is setup

Edited
11/7/2008 by Mark
CDRIVE
CDRIVE
Forum God
Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)Forum God (18K reputation)

Group: Forum Members
Posts: 548, Visits: 2.6K
Mark (11/7/2008)
And did you try what I suggested?

Click Here

EDIT: If you try to quote this post you should see how the url tag is setup

Like this? VoteForKeith

To do this I copied a link, pasted into Notepad (to strip the link) and then pasted it here and then typed in the url tags and the Keith text.

This one was done by pasting a link into the Insert Hyperlink window and adding the tags and my Keith text.

Vote For Keith

Somehow I don't think you do this either of the ways I did it. Do you manually type in the [url=  tags or am I misunderstanding how you do it? w00t

________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

Edited
11/7/2008 by CDRIVE
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search