-
Sep 6th, 2013, 04:33 AM
#1
Thread Starter
Lively Member
open internal GPS; and pervent standby
Hi
How do I open the internal GPS on my device?
Sounds like a stupid question, I know.
But doing the usual it's not working.
The internal GPS is set on COM4.
Set baudrate 4800,
I checked ....Manage GPS automatically (recommended) on my device.
And on my application I definitively open the COM4.
But there is no data coming even after 30 minutes under the clear sky.
The same internal GPS (on COM4) works fine with TomTom, and another GPS application.
But not with mine.
I have put a combobox and get all the ComPorts from my device.
If I choose COM4 (the internal GPS), the ap won't receive any data.
But if I pick the external bluetooth GPS (set on COM8) it works perfect.
Is there something else I should be aware of when opening this internal COM4?
As a second matter,
how do I prevent the backlight to go off, and the device to go into standby mode when my ap is running?
(other than changing the settings of the device)
Thanks.
-
Sep 6th, 2013, 06:20 AM
#2
Fanatic Member
Re: open internal GPS; and pervent standby
Try:
Code:
Dim WithEvents serialPort As New IO.Ports.SerialPort
Public Function openCom4() As String
Try
If serialPort.IsOpen Then
serialPort.Close()
End If
With serialPort
.PortName = "COM4"
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With
serialPort.Open()
Catch ex As Exception
Return ex.Message
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
Return "Ok."
End Function
Public Sub printCom4(Optional ByRef Linha As String = "")
Try
If Not serialPort.IsOpen Then
openCom4()
End If
serialPort.WriteLine(Linha)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Reset IdleTimer, using a timer and your device won't lock
Declare Sub SystemTimerReset Lib "coredll.dll" Alias "SystemIdleTimerReset" ()
check this url for other options
-
Sep 6th, 2013, 07:48 AM
#3
Thread Starter
Lively Member
Re: open internal GPS; and pervent standby
Thank you for your help, but unfortunately it doesn't work.
This is the code I've used in the first :
Private Sub Connect_GPS_Port()
' device params
With SerialPort_GPS
.ParityReplace = &H3B
.PortName = cmb_GPS_Port.Text
.BaudRate = 4800
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
.RtsEnable = False
.ReceivedBytesThreshold = 1
End With
' check whether device is avaiable:
Try
SerialPort_GPS.Open()
GPS_ComOpen = SerialPort_GPS.IsOpen
Catch ex As Exception
GPS_ComOpen = False
' MsgBox("Error Open: " & ex.Message)
MsgBox("GPS out of range")
End Try
If GPS_ComOpen Then
cmb_GPS_Port.Enabled = False ' disable the com port select box
bt_gps_discon.Enabled = True ' disconnect
bt_gps_con.Enabled = False ' connect
bt_connect_gps.Enabled = False ' connect
bt_disconnect_gps.Enabled = True ' disconnect
bt_dev.Enabled = True
bt_puge.Enabled = True
bt_so.Enabled = True
' enable the buttons for:
bt_glpl_st.Enabled = True
bt_glpl_stp.Enabled = True
bt_stt.Enabled = True
bt_stp.Enabled = True
tab_start.Enabled = True
End If
End Sub
it did not work with my code, and it still doesn't work with your code:
Public Function openCom4() As String
Try
If SerialPort_GPS.IsOpen Then
SerialPort_GPS.Close()
End If
With SerialPort_GPS
' .PortName = "COM4"
.PortName = cmb_GPS_Port.Text
.BaudRate = 4800
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
End With
SerialPort_GPS.Open()
GPS_ComOpen = SerialPort_GPS.IsOpen
Catch ex As Exception
Return ex.Message
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
Return "Ok."
End Function
Public Sub printCom4(Optional ByRef Linha As String = "")
Try
If Not SerialPort_GPS.IsOpen Then
openCom4()
End If
SerialPort_GPS.WriteLine(Linha)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
as for the standby prevention I've used this:
Declare Sub IdleTimerReset Lib "coredll.dll" Alias "SystemIdleTimerReset" ()
Private Sub tmr_standby_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_standby.Tick
IdleTimerReset()
'timer tmr_standby is set to 5000 and is enabled at form load
End Sub
but it's not working
Last edited by HyperUniverse; Sep 6th, 2013 at 07:53 AM.
-
Sep 6th, 2013, 08:42 AM
#4
Thread Starter
Lively Member
Re: open internal GPS; and pervent standby
I have found a port splitter
GPS Gate
I've installed a trial version and now my application works fine with a virtual COM created by the GPS Gate.
But this GPS Gate is set to use Com4 and 4800 baud rate.
and is creating a virtual port 1
now my ap is working "fine" with this virtual port, but not with the com4
I just can't open the port 4
although the virtual port has got the same settings as port 4.
-
Sep 9th, 2013, 07:31 AM
#5
Fanatic Member
Re: open internal GPS; and pervent standby
That's odd, I'm using that same code on my omnia and it seems to be working fine.
Have a try with this for the screen timeout
-
Sep 24th, 2013, 07:58 AM
#6
Thread Starter
Lively Member
Re: open internal GPS; and pervent standby
I am going slightly mad!
I can't read (or open???) the internal GPS that is set on COM4 with my app.
To explain better my problem is that if I use ReadExisting with my internal COM4, then I get NOTHING in my textbox (as if the com port did not open).
But it is working FINE with the Bluetooth COM8.
And if I use ReadLine, then BOTH COM4 & 8 are WORKING, but data is coming too slow, not in real time...I get a delay of few seconds.
I really want to use ReadExisting, as it's working PERFECT with the COM8 from bluetooth, but I want to use only the internal GPS.
this is my code:
Code:
Public Class Form1
Public Delegate Sub mydelegate(ByVal a_string As String)
Private Delegate Sub UpdateTextBoxGPSDelegate(ByVal myText_4 As String)
Dim Latitude As String
Dim Longitude As String
Private GPS_ComOpen As Boolean
#Region "Form load/unload"
' <summary>
' close application and COM Port
' </summary>
' Private Sub Form1_FormClosed(ByVal sender As System.Object, _
' ByVal e As System.Windows.Forms.FormClosedEventArgs) _
' Handles MyBase.FormClosed
Private Sub Form1_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closing ' , MyBase.Load
If GPS_ComOpen Then SerialPort_GPS.Close()
End Sub
''' <summary>
''' open Windows Form
''' </summary>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Portnames As String() = IO.Ports.SerialPort.GetPortNames()
Array.Sort(Portnames) ' sort out the PORTS in alphabetically order
' Add port name Into a comboBox control
For Each Port In Portnames
cmb_GPS_Port.Items.Add(Port)
Next Port
If Portnames Is Nothing Then
MsgBox("There are no Com Ports detected!")
Me.Close()
End If
cmb_GPS_Port.Text = Portnames(1) ' Select GPS ComPort
cmbGPS_Baud.Items.Add(1200)
cmbGPS_Baud.Items.Add(2400)
cmbGPS_Baud.Items.Add(4800)
cmbGPS_Baud.Items.Add(9600) 'Populate the cmbBaud Combo box to common baud rates used
cmbGPS_Baud.Items.Add(19200)
cmbGPS_Baud.Text = cmbGPS_Baud.Items.Item(2) 'Set cmbBaud text to the first Baud rate on the list
End Sub
#End Region
Private Sub bt_connect_gps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_connect_gps.Click
Connect_GPS_Port()
End Sub
Private Sub bt_disconnect_gps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_disconnect_gps.Click
DisConnect_GPS_Port()
End Sub
Private Sub Connect_GPS_Port()
With SerialPort_GPS
.PortName = cmb_GPS_Port.Text
.BaudRate = cmbGPS_Baud.Text
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.RequestToSend
.RtsEnable = False
.DtrEnable = False
.ReceivedBytesThreshold = 1 'threshold: one byte in buffer > event is fired
.ReadTimeout = 10
End With
' check whether device is avaiable:
Try
If SerialPort_GPS.IsOpen Then
SerialPort_GPS.Close()
End If
SerialPort_GPS.Open()
GPS_ComOpen = SerialPort_GPS.IsOpen
Catch ex As Exception
GPS_ComOpen = False
MsgBox("GPS out of range")
End Try
If GPS_ComOpen Then
cmb_GPS_Port.Enabled = False ' disable the com port select box
cmbGPS_Baud.Enabled = False ' disable the com baud select box
bt_connect_gps.Enabled = False ' connect
bt_disconnect_gps.Enabled = True ' disconnect
End If
End Sub
Private Sub DisConnect_GPS_Port()
On Error Resume Next
If GPS_ComOpen Then
' clear input buffer
SerialPort_GPS.DiscardInBuffer()
' MsgBox("GPS Port has been Discarded")
SerialPort_GPS.Close()
' MsgBox("GPS Port has been Closed")
End If
GPS_ComOpen = False
cmb_GPS_Port.Enabled = True
cmbGPS_Baud.Enabled = True
bt_connect_gps.Enabled = True
bt_disconnect_gps.Enabled = False
End Sub
#Region "ComPorts read data"
Private Sub SerialPort_GPS_DataReceived(ByVal sender As Object, ByVal e As _
System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort_GPS.DataReceived
Dim myResponse_gps As String = String.Empty
Try
myResponse_gps = SerialPort_GPS.ReadExisting ' ReadLine
Me.BeginInvoke(New mydelegate(AddressOf UpdateTextBoxGPS), myResponse_gps)
Catch ex As Exception
End Try
End Sub
Private Sub UpdateTextBoxGPS(ByVal mytext_4 As String) 'handles gps comport
txt_inc.Text = mytext_4
Dim data As String = txt_inc.Text
Dim strArr() As String = data.Split("$")
Dim i As Integer = 0
If strArr.Length > 1 Then
Try
For i = 0 To strArr.Length
Dim strTemp As String = strArr(i)
Dim lineArr() As String = strTemp.Split(",")
Select Case lineArr(0)
Case "GPRMC"
If (lineArr(2) = "A") Then
lbl_gps.BackColor = Color.Lime
Else
lbl_gps.BackColor = Color.Red
End If
Try
' Latitude
Dim dLat As Double = Convert.ToDouble(lineArr(3))
dLat = dLat / 100
Dim lat() As String = dLat.ToString().Split(".")
Latitude = lineArr(4).ToString() + " " + lat(0).ToString + "." + ((Convert.ToDouble(lat(1)) / 60)).ToString("#####")
' Longitude
Dim dLon As Double = Convert.ToDouble(lineArr(5))
dLon = dLon / 100
Dim lon() As String = dLon.ToString().Split(".")
Longitude = lineArr(6).ToString() + " " + lon(0).ToString + "." + ((Convert.ToDouble(lon(1)) / 60)).ToString("#####")
' Display them
txt_lat.Text = Latitude
txt_long.Text = Longitude
Catch
' do nothing
End Try
Case "GPVTG"
txt_sp.Text = lineArr(7) & " Km/h" ' Speed over ground in km/h
Case "GPGGA"
txt_alt.Text = lineArr(9) - 1 & " m" ' altitude in meters above the sea level
txt_nrsat.Text = lineArr(7) ' Number of satellites in use [not those in view]
End Select
Next
Catch
'do nothing
End Try
Else
' Can't Read GPS values
txt_lat.Text = "GPS Unavailable"
txt_long.Text = "GPS Unavailable"
End If
End Sub
#End Region
End Class
any suggestions?
thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|