This library is in developement and I have write little documentation. Please considerate this library as a testing version. It is possible non backwards compatible in the future version. But you can enjoy 🥳 and good fly !
For more information on how to use this library, please read example_test.go.
With this library you can in simulator:
- Read SimVar. (ex: Altitude, Longitude, Latitude, AP master status, Fuel, Engine...)
- Write SimVar. All the SimVar have not a possibility to be written show SimVar.Settable
- Send SimEvent for change Throttle or other
- Receive system event (ex: When the aircraft crash). Not all implemented
- Show text in the screen on the simulator
package main
import (
"fmt""log""strings""time"
sim "github.com/micmonay/simconnect"
)
funcmain() {
sc, err:=sim.NewEasySimConnect()
iferr!=nil {
panic(err)
}
sc.SetLoggerLevel(sim.LogInfo) // It is better if you the set before connectc, err:=sc.Connect("MyApp")
iferr!=nil {
panic(err)
}
<-c// Wait connection confirmationcSimVar, err:=sc.ConnectToSimVar(
sim.SimVarPlaneAltitude(),
sim.SimVarPlaneLatitude(sim.UnitDegrees), // You can force the unitssim.SimVarPlaneLongitude(),
sim.SimVarIndicatedAltitude(),
sim.SimVarGeneralEngRpm(1),
sim.SimVarAutopilotMaster(),
)
iferr!=nil {
panic(err)
}
cSimStatus:=sc.ConnectSysEventSim()
//wait sim startfor {
if<-cSimStatus {
break
}
}
crashed:=sc.ConnectSysEventCrashed()
for {
select {
caseresult:=<-cSimVar:
for_, simVar:=rangeresult {
varffloat64varerrerrorifstrings.Contains(string(simVar.Unit), "String") {
log.Printf("%s : %#v\n", simVar.Name, simVar.GetString())
} elseifsimVar.Unit=="SIMCONNECT_DATA_LATLONALT" {
data, _:=simVar.GetDataLatLonAlt()
log.Printf("%s : %#v\n", simVar.Name, data)
} elseifsimVar.Unit=="SIMCONNECT_DATA_XYZ" {
data, _:=simVar.GetDataXYZ()
log.Printf("%s : %#v\n", simVar.Name, data)
} elseifsimVar.Unit=="SIMCONNECT_DATA_WAYPOINT" {
data, _:=simVar.GetDataWaypoint()
log.Printf("%s : %#v\n", simVar.Name, data)
} else {
f, err=simVar.GetFloat64()
log.Println(simVar.Name, fmt.Sprintf("%f", f))
}
iferr!=nil {
log.Println("return error :", err)
}
}
case<-crashed:
log.Println("Your are crashed !!")
<-sc.Close() // Wait close confirmationreturn// This example close after crash in the sim
}
}
}