jaykappy Posted July 31, 2008 Share Posted July 31, 2008 I have been doing some work (VBA) that is allowing my application to Read the Comm POrt on my laptop and listen for a String being sent from a GPS Unit (NMEA String). My code listens for a particular string, once found parces it and grabs the XY coordinate. I am looking to replicate this in php and have no idea where to start. I am extremly green to php and am looking for any help I can get... I know this is a tall order but basically what I am doing is not that complicated. Simply listen to the port. When it finds a string starting with "$GPGGA", grab it and parse it out...I need the 2nd and 4th values (XY) then simply write them to variables. Repeat every few seconds I have placed my VBA code below....if there is anyone out there that is up for a challenge or can help in any way I would be most appreciative... THanks Private Sub Command111_Click() Call Command8_Click End Sub Function Wait(Delay As Integer, DispHrglass As Integer) ' This function creates a time delay you must use a call to run it Call Wait(2,1) Dim DelayEnd As Double DoCmd.Hourglass True DelayEnd = DateAdd("s", Delay, Now) While DateDiff("s", Now, DelayEnd) > 0 Wend DoCmd.Hourglass False End Function Private Sub Command8_Click() 'DoCmd.OpenForm "PROCESSING_GPS_COORDINATE" 'MsgBox "You are entering Command 8" MSComm0.InBufferCount = 0 'Flush the Buffer If (Not MSComm0.PortOpen) Then 'MsgBox "1" Dim Instring As String ' Buffer to hold input string MSComm0.CommPort = 1 ' Use COM1. MSComm0.Settings = "9600,N,8,1" ' 9600 baud, no parity, 8 data, and 1 stop bit. MSComm0.InputLen = 0 ' Tell the control to read entire buffer when Input is used. MSComm0.PortOpen = True ' Open the port. MSComm0.Output = "AT" & vbCr ' Send the attention command to the modem. Ensure that the modem responds with "OK". Buffer$ = Buffer$ & MSComm0.Input ' Wait for data to come back to the serial port. 'MsgBox Buffer$ '==================================================================================== 'TEST CODE TO TEST BEFORE IT REACHES THE OnComm LISTENING EVENT. ' Call Wait(1, 1) ' Buffer = MSComm0.Input ' MsgBox Buffer ' Forms!frm_StreetSigns!TEXTBOX.SetFocus ' TEXTBOX.Text = Buffer 'MsgBox "SMS Port Open", vbOKOnly, "Port State" '==================================================================================== Else 'MsgBox "SMS Port Already Open, It is now closing, and will re-open", vbOKOnly, "Port State" MSComm0.PortOpen = False 'MSComm7.PortOpen = True Call Command8_Click End If End Sub Public Sub MSComm0_OnComm() 'MsgBox "You are entering the OnComm Event" Select Case MSComm0.CommEvent Case comEvReceive Dim Buffer As String 'These two lines allow the Buffer variable 'Forms!frm_StreetSigns!TEXTBOX.SetFocus 'to be passed into TextBox MSComm0.InputLen = 0 'Set Buffer to zero or delete all in buffer Call Wait(1, 1) Buffer = MSComm0.Input 'MsgBox Buffer NMEAString = Buffer NMEAString2 = Buffer NMEAString3 = Buffer If InStr(Buffer, "$GPGGA") > 0 Then 'See if it has GPGGA in front 'TEXTBOX.Text = Buffer 'TEXTBOX.Text = StrConv(Buffer, vbUnicode) 'MsgBox Buffer 'MsgBox StrConv(Buffer, vbUnicode) 'MsgBox "Were in" MSComm0.PortOpen = False 'Close the Port End If '================================================= '================================================= '================================================= Call GetYCoordinate '================================================= '================================================= '================================================= Case Else MsgBox "No NMEA String Found" End Select End Sub Function GetYCoordinate() 'MsgBox "You are entering GetYCoordinate" Dim s As String, sItems() As String Dim i As Integer Dim NMEA As String NMEA = NMEAString 'Sets the Variable from MSComm7 to NMEA sItems = Split(NMEA, ",") 'This splits by a comma. Change if needed"," i = 0 For i = 0 To UBound(sItems) 'Sets i to the Upper Bound of sItems or the NMEA String NewCoords = Trim(sItems(i)) 'Trims the spaces on either side of the string '==================================================================== 'THE BELOW WILL POPULATE THE txt BOXES INTHE MAIN AREA OF THE FORM '==================================================================== If i = 2 Then Dim TestY As String Dim TestY2 As String Dim TestYInteger As Double Dim TestYInteger2 As Double Dim TestYInteger3 As Double Dim TestYInteger4 As Double Dim YCoord_A As String Dim NumY As Double Dim YCoord_String As String Ycoord2 = "" YCoord_A = NewCoords YCoord_String = CStr(YCoord_A) 'YCoord_String = "4576.432143" YCoord_String = CStr(YCoord_String) NumY = 1.66666666666667E-02 If YCoord_String <> "" Then TestY2 = Mid(YCoord_String, 1, 2) TestY = Mid(YCoord_String, 3, 11) TestY = CDbl(TestY) TestY2 = CDbl(TestY2) TestYInteger = (TestY) 'Changing to Double so they can be calculated 'MsgBox TestYInteger TestYInteger2 = (TestY2) 'Changing to Double so they can be calculated 'MsgBox TestYInteger2 TestYInteger = CDbl(TestYInteger) TestYInteger2 = CDbl(TestYInteger2) TestYInteger4 = TestYInteger * NumY 'Dividing wont retain Double. Multiply will 'MsgBox TestYInteger4 'THIS KEEPS RETURNING 0 UNTILL I MUTIPLY. TestYInteger4 = TestYInteger2 + TestYInteger4 'MsgBox TestYInteger4 Ycoord2 = TestYInteger4 YCoord3 = CDbl(Ycoord2) '=========================================== '=========================================== ' Forms!frm_StreetSigns!Y2.SetFocus ' If YCoord3 = "" Then ' Y2.Text = "000.00" ' Else ' Y2.Text = YCoord3 ' End If '=========================================== '=========================================== End If ''==================================================================== 'ElseIf i = 3 Then ' LongHem2 = NewCoords ''===================================================================== ElseIf i = 4 Then Dim TestX As String Dim TestX2 As String Dim TestXInteger As Double Dim TestXInteger2 As Double Dim TestXInteger3 As Double Dim TestXInteger4 As Double Dim XCoord_A As String Dim NumX As Double Dim Num2 As Double Dim XCoord_String As String Xcoord2 = "" XCoord_A = NewCoords XCoord_String = CStr(XCoord_A) XCoord_String = CStr(XCoord_String) NumX = 1.66666666666667E-02 ' There are 30 6s in this number to get divide 2 by 120 Num2 = -1 'THis is derived from dividing the degree by 60, but it 'wont work cause divide does not support double precision 'Multiply will so 120/6=2....take 2/120=.0166666666666666666666666666667 If XCoord_String <> "" Then TestX2 = Mid(XCoord_String, 2, 2) TestX = Mid(XCoord_String, 4, 11) TestX = CDbl(TestX) TestX2 = CDbl(TestX2) TestXInteger = (TestX) 'Changing to Double so they can be calculated 'MsgBox TestXInteger TestXInteger2 = (TestX2) 'Changing to Double so they can be calculated 'MsgBox TestXInteger2 TestXInteger = CDbl(TestXInteger) TestXInteger2 = CDbl(TestXInteger2) TestXInteger4 = TestXInteger * NumX 'Dividing wont retain Double. Multiply will 'MsgBox TestXInteger4 'THIS KEEPS RETURNING 0 UNTILL I MUTIPLY. TestXInteger4 = TestXInteger2 + TestXInteger4 'MsgBox TestXInteger4 Xcoord2 = TestXInteger4 Xcoord2 = Xcoord2 * Num2 XCoord3 = CDbl(Xcoord2) End If End If Next End Function Link to comment https://forums.phpfreaks.com/topic/117558-capturing-nmea-string-from-comm-port/ Share on other sites More sharing options...
phpSensei Posted July 31, 2008 Share Posted July 31, 2008 You cant do this with PHP. Link to comment https://forums.phpfreaks.com/topic/117558-capturing-nmea-string-from-comm-port/#findComment-604703 Share on other sites More sharing options...
jaykappy Posted July 31, 2008 Author Share Posted July 31, 2008 Can you explain a bit further....why... Can I accomplish this with Java Script? THanks for you reply Link to comment https://forums.phpfreaks.com/topic/117558-capturing-nmea-string-from-comm-port/#findComment-604725 Share on other sites More sharing options...
phpSensei Posted July 31, 2008 Share Posted July 31, 2008 You cant access the port directly, maybe if you used exec command or something to access. I think someone else might share more light with you, cause I don't know much about it. Link to comment https://forums.phpfreaks.com/topic/117558-capturing-nmea-string-from-comm-port/#findComment-604732 Share on other sites More sharing options...
jaykappy Posted August 1, 2008 Author Share Posted August 1, 2008 Are you saying that I cannot access the port directly using php... I am using VBA and can do this....I am in a web environment...how can I accomplish this. Python? Java? JavaScript? Html? Thanks Link to comment https://forums.phpfreaks.com/topic/117558-capturing-nmea-string-from-comm-port/#findComment-605578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.