Serial communication problem with BS2 and VB.NET
millitant
Posts: 15
Hey,
Im new to the forum, and havent had the time to skim through all the posts, perhaps this problem has already been solved, but i havent found anything that can help.
this is the problem, i managed to get my bs2 to communicate with my pc, it sends and receives perfectly fine. but all of a sudden last night all my work has come crashing. my app just keeps hanging when i try to connect to the COM port and closing or opening the port doesnt work. so i went back to basics.
this is my bs2 code:
basically a small parallax ping is attached and measured the distance to my ceiling. nothing big.
anyway here is my .net code:
it worked before, i just cant seem to figure out why it wont work any more.
the design is simple just three buttons and 1 textblok. the serout code should be displayed in the textblok, every time i press button 1 it should read the line on the serial port again and post that in the textblok.
this is as soon as i press button1, it just hangs. i put a readtimeout to try to stop the crash but no such luck.
anyone know of any code i can try that does work with this set-up?
thanks.
Im new to the forum, and havent had the time to skim through all the posts, perhaps this problem has already been solved, but i havent found anything that can help.
this is the problem, i managed to get my bs2 to communicate with my pc, it sends and receives perfectly fine. but all of a sudden last night all my work has come crashing. my app just keeps hanging when i try to connect to the COM port and closing or opening the port doesnt work. so i went back to basics.
this is my bs2 code:
' {$STAMP BS2} ' {$PBASIC 2.5} Trigger CON 1 rawDist VAR Word Ping PIN 15 DO Ping = 0 PULSOUT Ping, Trigger PULSIN Ping, 1, rawDist rawDist = rawDist * 2 rawDist = rawDist / 2 rawDist = rawDist / 30 SEROUT 16, 16468, 100, [DEC rawDist, LF] ' baudmode: 9600,8,N,1 PAUSE 100 LOOP
basically a small parallax ping is attached and measured the distance to my ceiling. nothing big.
anyway here is my .net code:
Public Class Form1 Dim WithEvents serialPort As New IO.Ports.SerialPort Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) serialPort.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Try With serialPort .PortName = "COM3" .BaudRate = 9600 .Parity = IO.Ports.Parity.None .DataBits = 8 .StopBits = IO.Ports.StopBits.One .Handshake = IO.Ports.Handshake.None .ReadTimeout = 250 .WriteTimeout = 250 End With Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim myMessage As String myMessage = serialPort.ReadLine txtData.Text = myMessage Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try serialPort.Open() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try serialPort.Close() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class
it worked before, i just cant seem to figure out why it wont work any more.
the design is simple just three buttons and 1 textblok. the serout code should be displayed in the textblok, every time i press button 1 it should read the line on the serial port again and post that in the textblok.
this is as soon as i press button1, it just hangs. i put a readtimeout to try to stop the crash but no such luck.
anyone know of any code i can try that does work with this set-up?
thanks.
Comments
Hi,
It happened to me once. And don't know why, but my system decided to change the port # on me.
So I changed it accordingly and everything was tickeedeeboo!
I used Hyperterminal to finally find out that the port was no longer the same!
Might give it a try...
Cheers
Thanks for the reply, i checked to see what port im using with Hyperterminal, its strange, but it says im using COM port 5, but when i use BASIC stamp editor, it says im using COM port 3.
i found out the hard way that you cant allow two programs to use a single COM port, just got me a blue screen of death error.
told me that some midi device was causing a lot of problems. it seems that vs 2010 and Basic stamp editor can not use the same port at the same time. i didnt know that. causes my computer to flip.
i changed my code to COM 5, and close BASIC stamp editor, no luck still nothing coming through. out of pure frustration i reset everything, closed Basic stamp editor and tried just receiving a string from my BS2, and what do you know it works again on COM port 3. my original COM port.
its a little weird, im going to have to add some code to check which COM port is active.
sorry if this is not really a Basic stamp problem, i dont know why my computer is giving me a hard time.
im just going to try some of the examples in one of the other posts. see if i can get some results.
Hi,
Forgot about that one. When I installed the Basic editor, If I remember well, I had to de-install my PALM stuff (or at least to disable it) so both software are not trying to communicate on the same port.
Cheers
im having problems with a little vb code while communicating with my basic stamp. im trying to reset my basic stamp, and it does work but the second it reset my vb code gives me an exception.
i cant figure out what the problem is. it looks like my vb code is trying to keep the connection open, but my reset code shouldnt close the COM port.
anyone have any ideas?
this is my reset code:
the error that springs up:
"The I/O operation has been aborted because of either a thread exit or an application request."
this bit of code come from one of the template examples on the forum. so probably someone already figured it out and perhaps can give me a hand.
thanks.