Sign in to follow this  
Followers 0
JonBMN

Inserting variables from source code to GUI code

7 posts in this topic

I'm trying to make a speedometer for a gps device using my own source code to decipher the GPS returns. I'm trying to plug in my MPH to my gui speedometer but can't figure it out! please help!

source:

AutoItWinSetTitle("ArchangelProgram")
AutoItSetOption("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client
AutoItSetOption("MustDeclareVars", 1)
#include-once
#include 
Opt("TrayMenuMode", 1)

HotKeySet("{ESC}", "Quit")

$Debug = False
Global $CommPort = "COM6", $Baudrate = 4800, $Received, $GPSHeader, $Dim, $Struct, $Const
Global $IniLongitude, $IniLatitude, $IniTime, $CurLongitude, $CurLatitude, $Longitude, $Latitude, $TimeElapsed, $I, $GetIniTime = True
Global $GetInitial = True, $Knots, $Miles, $Begin, $Dif, $Miles, $Hours, $MPH, $Time
$HerbieError = True
While 1 ; Haven't accounted for Under/Under
If $HerbieError = True Then
InitializeCommunications()
EndIf
$Received = _CommReceiveString(100, 5000, @CR)
$GPSHeader = Parse()
if $GPSHeader == "$GPGSA" Then
DecodeGPGSA()
EndIf
if $GPSHeader == "$GPRMC" Then
DecodeGPRMC()
DecodeKnots()
EndIf
if $GPSHeader == "$GPGGA" Then
DecodeGPGGA()
IF $GetInitial == True Then
$IniLongitude = $Longitude
$IniLatitude = $Latitude
$IniTime = TimerInit()
$GetInitial = False
Else
$CurLongitude = $Longitude
$CurLatitude = $Latitude
$TimeElapsed = TimerDiff($IniTime)
$IniLongitude = $CurLongitude
$IniLatitude = $CurLatitude
$IniTime = TimerInit()
EndIf
EndIf
if $GPSHeader == "GPGSV" Then
DecodeGPGSV()
EndIf


sleep(10)


WEnd

Func Quit()
If $SerialPortHandle <> -1 Then
_CommClose()
EndIf
Exit
EndFunc

Func DecodeKnots()
$MPH = Round($Knots * 1.15077)
ConsoleWrite("My current speed is: " & $MPH & " MPH" & @CR)
EndFunc

Func DecodeGPGSA()
Local $AMode, $2Mode, $blank1, $blank2, $blank3, $blank4, $blank5, $blank6, $blank7, $blank8, $blank9, $blank10, $blank11, $blank12, $PDOP, $HDOP, $VDOP
$AMode = Parse()
$2Mode = Parse()
$blank1 = Parse()
$blank2 = Parse()
$blank3 = Parse()
$blank4 = Parse()
$blank5 = Parse()
$blank6 = Parse()
$blank7 = Parse()
$blank8 = Parse()
$blank9 = Parse()
$blank10 = Parse()
$blank11 = Parse()
$blank12 = Parse()
$PDOP = Parse()
$HDOP = Parse()
$VDOP = Parse()
;ConsoleWrite($AMode & $2Mode & $blank1 & $blank2 & $blank3 & $blank4 & $blank5 & $blank6 & $blank7 & $blank8 & $blank9 & $blank10 & $blank11 & $blank12 & $PDOP & $HDOP & $VDOP & @CR)
EndFunc

Func DecodeGPRMC()
Local $TimeStamp, $Validity, $LatitudeRMC, $NorS, $LongitudeRMC, $WorE, $TrueCourse, $DateStamp, $Variation, $EorW, $Checksum
$TimeStamp = Parse()
$Validity = Parse()
$LatitudeRMC = Parse()
$NorS = Parse()
$LongitudeRMC = Parse()
$WorE = Parse()
$Knots = Parse()
$TrueCourse = Parse()
$DateStamp = Parse()
$Variation = Parse()
$EorW = Parse()
$Checksum = Parse()
;ConsoleWrite($TimeStamp & $Validity & $Latitude & $NorS & $Longitude & $WorE & $Knots & $TrueCourse & $DateStamp & $Variation & $EorW & $Checksum & @CR)
EndFunc

Func DecodeGPGGA()
Local $UTCposition, $NorS, $EorW, $QualityIndicator, $SatellitesInUse, $SeaLevel, $HorizontalDilution, $Meters, $GeoidalSeparation, $MetersSep, $SecLastUpdate, $StationIDchecksum
$UTCposition = Parse()
$Latitude = Parse()
$NorS = Parse()
$Longitude = Parse()
$EorW = Parse()
$QualityIndicator = Parse()
$SatellitesInUse = Parse()
$HorizontalDilution = Parse()
$SeaLevel = Parse()
$Meters = Parse()
$GeoidalSeparation = Parse()
$MetersSep = Parse()
$SecLastUpdate = Parse()
$StationIDchecksum = Parse()
;ConsoleWrite($UTCposition & $Latitude & $NorS & $Longitude & $EorW & $QualityIndicator & $SatellitesInUse & $HorizontalDilution & $SeaLevel & $Meters & $GeoidalSeparation & $MetersSep & $SecLastUpdate & $StationIDchecksum & @CR)
;ConsoleWrite($SeaLevel & @CR)
EndFunc

Func DecodeGPGSV()
Local $MessagesCycle, $MessageNumber, $TotalSVs, $SVprn, $ElevationDegrees, $TrueNorth, $SNR, $SecondSV1, $SecondSV2, $SecondSV3, $SecondSV4, $ThirdSV1, $ThirdSV2, $ThirdSV3, $ThirdSV4, $FourthSV1, $FourthSV2, $FourthSV3, $FourthSV4
$MessagesCycle = Parse()
$MessageNumber = Parse()
$TotalSVs = Parse()
$SVprn = Parse()
$ElevationDegrees = Parse()
$TrueNorth = Parse()
$SNR = Parse()
$SecondSV1 = Parse()
$SecondSV2 = Parse()
$SecondSV3 = Parse()
$SecondSV4 = Parse()
$ThirdSV1 = Parse()
$ThirdSV2 = Parse()
$ThirdSV3 = Parse()
$ThirdSV4 = Parse()
$FourthSV1 = Parse()
$FourthSV2 = Parse()
$FourthSV3 = Parse()
$FourthSV4 = Parse()
;ConsoleWrite($MessagesCycle & $MessageNumber & $TotalSVs & $SVprn & $ElevationDegrees & $TrueNorth & $SNR & $SecondSV1 & $SecondSV2 & $SecondSV3 & $SecondSV4 & $ThirdSV1 & $ThirdSV2 & $ThirdSV3 & $ThirdSV4 & $FourthSV1 & $FourthSV2 & $FourthSV3 & $FourthSV4 & @CR)
EndFunc

Func Parse()
Local $CommaPos, $Result
$Result = ""
$CommaPos = StringInStr($Received, ",")
If $CommaPos == 0 Then
Return $Result
EndIf
$Result = StringLeft($Received, $CommaPos - 1)
$Received = StringRight($Received, StringLen($Received) - $CommaPos)
Return $Result
EndFunc

my GUI code:

#include <INet.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <StaticConstants.au3>
#include <GPStest.au3>


Opt("GUIOnEventMode", 1)

Global $label_speed = $MPH, $meter = 0, $dir = 0, $radius = 40, $okbutton
; stuff to generate data goes here, but isn't included
Global $date = "Sep 21, 2012", $time = @HOUR & ":" & @MIN, $speed = $MPH , $pi = 3.14159, $font = "Arial"

; Create GUI & label controls
$hGUI = GUICreate("Speedometer", 100, 120, -1, -1, $WS_CAPTION, $WS_EX_TOOLWINDOW); BitOr($WS_EX_COMPOSITED,$WS_EX_TOOLWINDOW))
$label_date = GUICtrlCreateLabel("", 10, 0, 80, 14, $SS_Center)
$label_time = GUICtrlCreateLabel("", 10, 15, 80, 14, $SS_Center)
GUIRegisterMsg($WM_PAINT, "RePaint")
GUISetOnEvent($GUI_EVENT_RESTORE, "RePaint")
GUISetOnEvent($GUI_EVENT_CLOSE, "Finish")
GUISetState()
$label_speed = GUICtrlCreateLabel("", 35, 67, 30, 16, $SS_RIGHT)
Paint()

While 1
    Sleep(100)
WEnd


Func RePaint()

    GUICtrlSetGraphic($meter, $GUI_GR_PENSIZE, 2)
    GUICtrlSetGraphic($meter, $GUI_GR_COLOR, 0x000000, 0x888888)
    GUICtrlSetGraphic($meter, $GUI_GR_ELLIPSE, 5, 5, 80, 80)
    GUICtrlSetGraphic($meter, $GUI_GR_COLOR, 0x000000, 0xcccccc)

; tick marks on dial
    For $index = 0 To 16
        $xsp = $radius * Sin($pi * $index / 8)
        $ysp = -1 * $radius * Cos($pi * $index / 8)
        $xep = 1.15 * $radius * Sin($pi * $index / 8)
        $yep = -1.15 * $radius * Cos($pi * $index / 8)
        GUICtrlSetGraphic($meter, $GUI_GR_MOVE, $xsp + 45, $ysp + 45)
        GUICtrlSetGraphic($meter, $GUI_GR_LINE, $xep + 45, $yep + 45)
    Next
    $xpos = 35 * Sin($pi * $dir / 180)
    $ypos = -35 * Cos($pi * $dir / 180)
    GUICtrlSetGraphic($meter, $GUI_GR_MOVE, 45, 45)
    GUICtrlSetGraphic($meter, $GUI_GR_LINE, $xpos + 45, $ypos + 45)

    GUICtrlSetData($label_date, $date)
    GUICtrlSetData($label_time, $time)
    If $label_speed <> 0 Then GUICtrlSetFont($label_speed, 10, 800)
    GUICtrlSetData($label_speed, $speed)

EndFunc ;==>RePaint

Func Paint()

    $dir += 2

; delete control if it exists

    If $meter <> 0 Then
        GUICtrlDelete($meter)
        $meter = 0
    EndIf

    $meter = GUICtrlCreateGraphic(5, 30, 90, 90)
    repaint()


EndFunc ;==>Paint

Func Finish()
    Exit
EndFunc ;==>Finish

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Keep your archangel program code separate from your GUI code. Include them both into another au3 and have your main loop be in that new au3.

Here is a basic example I cranked out real quick like:

#include "Archangel Program.au3" ; change these names to reflect the actual names of the au3 files

#include "Archangel GUI.au3" ; change these names to reflect the actual names of the au3 files

GUISetState(@SW_SHOWNORMAL)

; Let your main GUI loop reside here
Do
While 1 ; Haven't accounted for Under/Under
     If $herbieerror = True Then InitializeCommunications()

     $received = _CommReceiveString(100, 5000, @CR)

     $gpsheader = Parse()

     If $gpsheader == "$GPGSA" Then DecodeGPGSA()

     If $gpsheader == "$GPRMC" Then
         DecodeGPRMC()
         DecodeKnots()
     EndIf

     If $gpsheader == "$GPGGA" Then
         DecodeGPGGA()

         If $getinitial == True Then
             $inilongitude = $longitude
             $inilatitude = $latitude
             $initime = TimerInit()
             $getinitial = False
         Else
             $curlongitude = $longitude
             $curlatitude = $latitude
             $timeelapsed = TimerDiff($initime)
             $inilongitude = $curlongitude
             $inilatitude = $curlatitude
             $initime = TimerInit()
         EndIf
     EndIf

     If $gpsheader == "GPGSV" Then DecodeGPGSV()
WEnd
Until False

Edited per Martin's suggestion. That's what I get for trying to be first.

Edited by LaCastiglione

Share this post


Link to post
Share on other sites

But you have used GuiOnEventMode so I think you could simply remove the

Do

Switch GUIGetMsg()

Case $gui_event_close

Quit()

EndSwitch

Untill

and just have the While/Wend


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Tried both and it seems to still be writing to the console, not the GUI speedometer.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

[sOLUTION] here's my code for someone else if they need it.

#include <INet.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <StaticConstants.au3>
#include <GPStest.au3>


Opt("GUIOnEventMode", 1)

Global $label_speed = $MPH, $meter = 0, $dir = 0, $radius = 40, $okbutton, $hGUI, $label_date, $label_time, $xsp, $ysp, $xep, $yep, $xpos, $ypos
; stuff to generate data goes here, but isn't included
Global $date = @MON & "/" & @MDAY & "/" & @YEAR , $time = @HOUR & ":" & @MIN, $speed = $MPH , $pi = 3.14159, $font = "Arial"

; Create GUI & label controls
$hGUI = GUICreate("Speedometer", 100, 120, -1, -1, $WS_CAPTION, $WS_EX_TOOLWINDOW); BitOr($WS_EX_COMPOSITED,$WS_EX_TOOLWINDOW))
;msgbox(0, "", $hGUI)
$label_date = GUICtrlCreateLabel("", 10, 0, 80, 14, $SS_Center)
$label_time = GUICtrlCreateLabel("", 10, 15, 80, 14, $SS_Center)
$label_speed = GUICtrlCreateLabel($MPH, 35, 67, 30, 16, $SS_Right)
GUIRegisterMsg($WM_PAINT, "RePaint")
GUISetOnEvent($GUI_EVENT_RESTORE, "RePaint")
GUISetOnEvent($GUI_EVENT_CLOSE, "Finish")
GUISetState()
Paint()

While 1
If $HerbieError = True Then
InitializeCommunications()
EndIf
$Received = _CommReceiveString(100, 5000, @CR)
$GPSHeader = Parse()
if $GPSHeader == "$GPGSA" Then
DecodeGPGSA()
EndIf
if $GPSHeader == "$GPRMC" Then
DecodeGPRMC()
DecodeKnots()
$date = @MON & "/" & @MDAY & "/" & @YEAR
$time = @HOUR & ":" & @MIN
GUICtrlSetData($label_date, $date)
GUICtrlSetData($label_time, $time)
GUICtrlSetData($label_speed, $MPH)
;ConsoleWrite("My current speed is: " & $MPH & " MPH" & @CR)
sleep(50)
EndIf
if $GPSHeader == "$GPGGA" Then
DecodeGPGGA()
IF $GetInitial == True Then
$IniLongitude = $Longitude
$IniLatitude = $Latitude
$IniTime = TimerInit()
$GetInitial = False
Else
$CurLongitude = $Longitude
$CurLatitude = $Latitude
$TimeElapsed = TimerDiff($IniTime)
$IniLongitude = $CurLongitude
$IniLatitude = $CurLatitude
$IniTime = TimerInit()
EndIf
EndIf
if $GPSHeader == "GPGSV" Then
DecodeGPGSV()
EndIf

WEnd


Func RePaint()

GUICtrlSetGraphic($meter, $GUI_GR_PENSIZE, 2)
GUICtrlSetGraphic($meter, $GUI_GR_COLOR, 0x000000, 0x888888)
GUICtrlSetGraphic($meter, $GUI_GR_ELLIPSE, 5, 5, 80, 80)
GUICtrlSetGraphic($meter, $GUI_GR_COLOR, 0x000000, 0xcccccc)

; tick marks on dial
For $index = 0 To 16
$xsp = $radius * Sin($pi * $index / 8)
$ysp = -1 * $radius * Cos($pi * $index / 8)
$xep = 1.15 * $radius * Sin($pi * $index / 8)
$yep = -1.15 * $radius * Cos($pi * $index / 8)
GUICtrlSetGraphic($meter, $GUI_GR_MOVE, $xsp + 45, $ysp + 45)
GUICtrlSetGraphic($meter, $GUI_GR_LINE, $xep + 45, $yep + 45)
Next
$xpos = 35 * Sin($pi * $dir / 180)
$ypos = -35 * Cos($pi * $dir / 180)
GUICtrlSetGraphic($meter, $GUI_GR_MOVE, 45, 45)
GUICtrlSetGraphic($meter, $GUI_GR_LINE, $xpos + 45, $ypos + 45)

GUICtrlSetData($label_date, $date)
GUICtrlSetData($label_time, $time)
If $label_speed <> 0 Then GUICtrlSetFont($label_speed, 10, 800)
GUICtrlSetData($label_speed, $MPH)

EndFunc ;==>RePaint

Func Paint()

$dir += 2

; delete control if it exists

If $meter <> 0 Then
GUICtrlDelete($meter)
$meter = 0
EndIf

$meter = GUICtrlCreateGraphic(5, 30, 90, 90)
repaint()


EndFunc ;==>Paint

Func Finish()
Exit
EndFunc ;==>Finish
Edited by JonBMN

Share this post


Link to post
Share on other sites

JonBMN,

Then please post the solution you found so that others might benefit. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0