Closing serial port problem

camolas

Member
Licensed User
Longtime User
Hi,

I have a problem i want to connect my PPC (wm5) to a bluetooth and have done it so far so god, but i need to close de connection form 5 min and start it again automatic (beacuse i want to connect other device in the time with the BT) i have wrote this simple code for testing conection and disconection but the PPC freezes !! (on wm5 and 6 ) and a have to switch off the PPC. Can you experts tell me how can i open the serial port and after 5min close it automatic ( with out the need of pressing some bottun) ?

Thanks,


Sub Globals

End Sub

Sub App_Start
Form1.Show

Form1.Show
serial.New1
serial.CommPort = 8
serial.BitRate = 9600
serial.PortOpen = False
serial.EnableOnComm = True


End Sub


Sub Serial_OnCom
TextBox1.Text = TextBox1.Text & serial.InputString

End Sub

Sub Button3_Click
If serial.PortOpen = False Then
serial.CommPort = 8
serial.BitRate = 9600
serial.PortOpen = True
Sleep (1000) ' for BT conection
serial.Output="HI"
Sleep(1000)
serial.PortOpen = False
End If

End Sub
Sub btnReceive_Click
If serial.PortOpen = True Then TextBox1.Text = TextBox1.Text & serial.InputString
End Sub

Sub btnSend_Click
If serial.PortOpen = True Then serial.Output(textBox1.Text)
End Sub

Sub Button5_Click
AppClose
End Sub
 

mjcoon

Well-Known Member
Licensed User
You would need to set up a timer and do the close when the timer event occurs.

The code as you showed us never has the serial port open except when Sub Button3_Click is still executing, so the other buttons (except button 5!) are not going to do anything.

Mike.
 

camolas

Member
Licensed User
Longtime User
Hi and thanks mjcoon

I have tried just like you said but the PPC stops .Can you please write the timer event for me to test? because my won dosent work :signOops:

Thanks again
 

mjcoon

Well-Known Member
Licensed User
...Can you please write the timer event for me to test?

No, not me. I didn't understand the code snippet that you posted before (as I said).

Perhaps you should attach your complete code so that someone with BT could try it out on their device.

Mike.
 

camolas

Member
Licensed User
Longtime User
Hi,

The code as more buttons for later funcions for now i only need hellp on closing the comport for starting point for my program see the code now please.

Thankzz for caring (im very noob at this)

Sub Globals

End Sub

Sub App_Start
Form1.Show

Form1.Show
serial.New1
serial.CommPort = 8
serial.BitRate = 9600
serial.PortOpen = False
serial.EnableOnComm = True


End Sub
Sub Serial_OnCom
TextBox1.Text = TextBox1.Text & serial.InputString
End Sub

Sub Button3_Click
If serial.PortOpen = False Then
serial.CommPort = 8
serial.BitRate = 9600
serial.PortOpen = True
Sleep (1000) ' for BT conection
serial.Output="HI"
Sleep(1000)
serial.PortOpen = False
End If


Sub Button5_Click
AppClose
End Sub
 

mjcoon

Well-Known Member
Licensed User
1) Unless you attach the complete SBP file we cannot run your code because it refers to buttons and objects (serial) that are not visible.

2) You are still closing the serial port in the Sub Button3_Click code so why would you want to close it on a timer when it is already closed? And you cannot get the Serial_OnCom event because the Sleep() does not allow events. I presume that closing the serial port will discard any events that otherwise might be pending.

My other comments still apply.

Mike.
 

camolas

Member
Licensed User
Longtime User
Hi,

The soluction it dosent solve the problem :BangHead: , its not stable some times it count the time right some times dont and some times stops the program ( im talking about the "timer" funcion to close the com port)
Big mess that im in.. :sign0148:
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…