📄 sim.frm
字号:
End If
Next i%
If stbd_rudder.FloodPercent = 0 Then stbd_rudder.FloodPercent = 3
If txt_hdg.Text <= "359" Then
txt_hdg.Text = Format(Val(txt_hdg.Text) + 1, "000")
End If
If txt_hdg.Text = "360" Then
txt_hdg.Text = "000"
End If
If txt_hdg.Text > "360" Then
txt_hdg.Text = Format(Val(txt_hdg.Text) + 1, "000")
End If
txt_hdg.Text = Format(Val(txt_hdg.Text), "000")
End Sub
Private Sub SSCommand1_Click()
If nmea_com.PortOpen Then
nmea_com.PortOpen = False
End If
On Error Resume Next
'Select COM port
If opt_com3.Value Then
nmea_com.CommPort = 3
nmea_com.PortOpen = True
If Err Then
MsgBox "COM3: not available. Change the CommPort to another port."
nmea_com.PortOpen = False
End If
ElseIf opt_com2.Value Then
nmea_com.CommPort = 2
nmea_com.PortOpen = True
If Err Then
MsgBox "COM2: not available. Change the CommPort to another port."
nmea_com.PortOpen = False
End If
Else
nmea_com.CommPort = 1
nmea_com.PortOpen = True
If Err Then
MsgBox "COM1: not available. Change the CommPort to another port."
nmea_com.PortOpen = False
End If
End If
If port_open_flag = True Then
nmea_com.PortOpen = True
Else
nmea_com.PortOpen = False
End If
fra_com.Visible = False
Exit Sub
PortError:
MsgBox "This COM port not available. Change the CommPort to another port."
nmea_com.PortOpen = False
Exit Sub
End Sub
Private Sub Timer1_Timer()
Dim GGA$, RMC$, GLL$, NMEA$
Dim lat_count
start_lat = 0
start_lon = 0
i% = DoEvents
For i% = 3 To (port_rudder.FloodPercent / 10)
If Val(txt_hdg.Text) = "000" Then txt_hdg.Text = "360"
txt_hdg.Text = Abs(Format(Val(txt_hdg.Text) - i%, "000"))
Next i%
For i% = 3 To (stbd_rudder.FloodPercent / 10)
If Val(txt_hdg.Text) = 360 Then txt_hdg.Text = "000"
txt_hdg.Text = Abs(Format(Val(txt_hdg.Text) + i%, "000"))
Next i%
If txt_hdg.Text > 360 Then
txt_hdg.Text = Abs(360 - txt_hdg.Text)
End If
txt_hdg.Text = Format(Val(txt_hdg.Text), "000")
distance = ((Val(txt_speed.Text) * 2024) / 3600) 'Distance in 1 second (timer interval)
'Get current position (from start position first time around)
If Counter >= 1 Then
start_lat = end_lat
start_lon = end_lon
Else
start_lat = Val(txt_st_lat_deg.Text) + (Val(txt_st_lat_min.Text) / 60)
start_lon = Val(txt_st_lon_deg.Text) + (Val(txt_st_lon_min.Text) / 60)
lbl_ns.Caption = txt_ns.Text
lbl_ew.Caption = txt_ew.Text
End If
Timer1.Enabled = False
Counter = 1
hdg = txt_hdg.Text
'Check for Greenwich crossing
If start_lon = 0 Then
lbl_end_lon_deg.Caption = Format(lbl_end_lon_deg.Caption, "000")
lbl_end_lon_min.Caption = Format(lbl_end_lon_min.Caption, "00.00")
If lbl_ew.Caption = "E" Then
lbl_ew.Caption = "W"
Else
lbl_ew.Caption = "E"
End If
End If
'Check for equator crossing
If start_lat < 0.01 Then
If lat_count = 0 Then
If Trim(Val(txt_hdg.Text)) > 91 Then
lbl_ns.Caption = "S"
Else
lbl_ns.Caption = "N"
End If
If Trim(Val(txt_hdg.Text)) > 269 Then
lbl_ns.Caption = "N"
End If
lat_count = 1
End If
End If
'Check for dateline crossing
Call check_dateline
'Calculate distance moved
If txt_hdg.Text = 360 Then txt_hdg.Text = Format(Val(txt_hdg.Text), "000")
If txt_hdg.Text > 270 And txt_hdg.Text <= 359 Then
If lbl_ns.Caption = "N" Then
end_lat = start_lat + (((distance * Cos(((360 - hdg)) / rad))) / 2024) / 60
If lbl_ew.Caption = "W" Then
end_lon = start_lon + (((distance * Sin(((360 - hdg)) / rad))) / 2024) / 60
Else
end_lon = start_lon - (((distance * Sin(((360 - hdg)) / rad))) / 2024) / 60
End If
Else
end_lat = start_lat - (((distance * Cos(((360 - hdg)) / rad))) / 2024) / 60
If lbl_ew.Caption = "W" Then
end_lon = start_lon + (((distance * Sin(((360 - hdg)) / rad))) / 2024) / 60
Else
end_lon = start_lon - (((distance * Sin(((360 - hdg)) / rad))) / 2024) / 60
End If
End If
End If
If txt_hdg.Text >= 180 And txt_hdg.Text <= 270 Then
If lbl_ns.Caption = "N" Then
end_lat = start_lat - (((distance * Sin(((270 - hdg)) / rad))) / 2024) / 60
If lbl_ew.Caption = "W" Then
end_lon = start_lon + (((distance * Cos(((270 - hdg)) / rad))) / 2024) / 60
Else
end_lon = start_lon - (((distance * Cos(((270 - hdg)) / rad))) / 2024) / 60
End If
Else
end_lat = start_lat + (((distance * Sin(((270 - hdg)) / rad))) / 2024) / 60
If lbl_ew.Caption = "W" Then
end_lon = start_lon + (((distance * Cos(((270 - hdg)) / rad))) / 2024) / 60
Else
end_lon = start_lon - (((distance * Cos(((270 - hdg)) / rad))) / 2024) / 60
End If
End If
End If
If txt_hdg.Text > 90 And txt_hdg.Text < 180 Then
If lbl_ns.Caption = "N" Then
end_lat = start_lat - (((distance * Cos(((180 - hdg)) / rad))) / 2024) / 60
If lbl_ew.Caption = "W" Then
end_lon = start_lon - (((distance * Sin(((180 - hdg)) / rad))) / 2024) / 60
Else
end_lon = start_lon + (((distance * Sin(((180 - hdg)) / rad))) / 2024) / 60
End If
Else
end_lat = start_lat + (((distance * Cos(((180 - hdg)) / rad))) / 2024) / 60
If lbl_ew.Caption = "W" Then
end_lon = start_lon - (((distance * Cos(((180 - hdg)) / rad))) / 2024) / 60
Else
end_lon = start_lon + (((distance * Cos(((180 - hdg)) / rad))) / 2024) / 60
End If
End If
End If
If txt_hdg.Text >= 0 And txt_hdg.Text <= 90 Then
If lbl_ns.Caption = "N" Then
'end_lat = start_lat + ((distance * Cos(hdg / rad)))
end_lat = start_lat + (((distance * Cos(hdg / rad))) / 2024) / 60 'lat + nm
'Stop
If lbl_ew.Caption = "W" Then
end_lon = start_lon - (((distance * Sin(hdg / rad))) / 2024) / 60
Else
end_lon = start_lon + (((distance * Sin(hdg / rad))) / 2024) / 60
End If
Else
end_lat = start_lat - (((distance * Cos(hdg / rad))) / 2024) / 60
If lbl_ew.Caption = "W" Then
end_lon = start_lon - (((distance * Sin(hdg / rad))) / 2024) / 60
Else
end_lon = start_lon + (((distance * Sin(hdg / rad))) / 2024) / 60
End If
End If
End If
'Display current latitiude
lbl_end_lat_deg.Caption = Int(Abs(end_lat))
lbl_end_lat_min.Caption = Format(((end_lat - Int(end_lat)) * 60), "00.00")
If lbl_end_lat_min.Caption >= 60 Then
lbl_end_lat_deg.Caption = Int(Abs(end_lat)) + 1
lbl_end_lat_min.Caption = Format(((lbl_end_lat_deg.Caption - Int(lbl_end_lat_deg.Caption)) * 60), "00.00")
End If
'Display current longitude
lbl_end_lon_deg.Caption = Format(Int(Abs(end_lon)), "00#")
lbl_end_lon_min.Caption = Format(((end_lon - Int(end_lon)) * 60), "00.00")
If lbl_end_lon_min.Caption >= 60 Then
lbl_end_lon_deg.Caption = Int(Abs(end_lon)) + 1
lbl_end_lon_min.Caption = Format(((lbl_end_lon_deg.Caption - Int(lbl_end_lon_deg.Caption)) * 60), "00.00")
End If
sim_lat = end_lat
sim_lon = end_lon
Select Case com_nmea.Text
Case "All"
GLL$ = "$GPGLL," + Format$(Left$(lbl_end_lat_deg.Caption + lbl_end_lat_min.Caption, 7), "00##.00") + "," + lbl_ns.Caption + "," + Format$(Left$(lbl_end_lon_deg.Caption + lbl_end_lon_min.Caption, 8), "00###.00") + "," + lbl_ew.Caption + "," + Format$(Time$, "hhmmss.ss") + ",A" + Chr(13) + Chr(10)
RMC$ = "$GPRMC," + Format$(Time$, "hhmmss.ss") + "," + "A" + "," + Format$(Left$(lbl_end_lat_deg.Caption + lbl_end_lat_min.Caption, 7), "00##.00") + "," + lbl_ns.Caption + "," + Format$(Left$(lbl_end_lon_deg.Caption + lbl_end_lon_min.Caption, 8), "00###.00") + "," + lbl_ew.Caption + "," + txt_speed.Text + "," + txt_hdg.Text + "," + Format$(Date$, "ddmmyy") + "," + "4.5" + ",A" + Chr(13) + Chr(10)
GGA$ = "$GPGGA," + Format$(Time$, "hhmmss.ss") + "," + Format$(Left$(lbl_end_lat_deg.Caption + lbl_end_lat_min.Caption, 7), "00##.00") + "," + lbl_ns.Caption + "," + Format$(Left$(lbl_end_lon_deg.Caption + lbl_end_lon_min.Caption, 8), "00###.00") + "," + lbl_ew.Caption + "," + "1" + "," + "06" + "," + "0.0" + "," + "1.2" + "," + "M" + "," + "1.2" + "," + "M" + "," + "" + "," + "0000" + Chr(13) + Chr(10)
NMEA$ = GLL$ + RMC$ + GGA$
Case "GLL"
NMEA$ = "$GPGLL," + Format$(Left$(lbl_end_lat_deg.Caption + lbl_end_lat_min.Caption, 7), "00##.00") + "," + lbl_ns.Caption + "," + Format$(Left$(lbl_end_lon_deg.Caption + lbl_end_lon_min.Caption, 8), "00###.00") + "," + lbl_ew.Caption + "," + Format$(Time$, "hhmmss.ss") + ",A" + Chr(13) + Chr(10)
Case "RMC"
NMEA$ = "$GPRMC," + Format$(Time$, "hhmmss.ss") + "," + "A" + "," + Format$(Left$(lbl_end_lat_deg.Caption + lbl_end_lat_min.Caption, 7), "00##.00") + "," + lbl_ns.Caption + "," + Format$(Left$(lbl_end_lon_deg.Caption + lbl_end_lon_min.Caption, 8), "00###.00") + "," + lbl_ew.Caption + "," + txt_speed.Text + "," + txt_hdg.Text + "," + Format$(Date$, "ddmmyy") + "," + "4.5" + ",A" + Chr(13) + Chr(10)
Case "GGA"
NMEA$ = "$GPGGA," + Format$(Time$, "hhmmss.ss") + "," + Format$(Left$(lbl_end_lat_deg.Caption + lbl_end_lat_min.Caption, 7), "00##.00") + "," + lbl_ns.Caption + "," + Format$(Left$(lbl_end_lon_deg.Caption + lbl_end_lon_min.Caption, 8), "00###.00") + "," + lbl_ew.Caption + "," + "1" + "," + "06" + "," + "0.0" + "," + "1.2" + "," + "M" + "," + "1.2" + "," + "M" + "," + "" + "," + "0000" + Chr(13) + Chr(10)
Case Else
End Select
last_update = Format$(Time$, "ss.ss")
If last_update >= 59 Then last_update = 0
Do
If Format$(Time$, "ss.ss") + 1 >= Trim(last_update) Then
'Output NMEA message
nmea_com.Output = NMEA$
Exit Do
Else
i% = DoEvents
End If
Loop
Text1.Text = NMEA$
'Loop for next position
Call cmd_start_Click
End Sub
Private Sub txt_ew_Change()
txt_ew.Text = Trim(UCase(txt_ew.Text))
If Len(txt_ew.Text) >= 2 Then
MsgBox "Illegal entry."
txt_ew.Text = ""
Exit Sub
End If
End Sub
Private Sub txt_hdg_Change()
If Len(txt_hdg.Text) >= 4 Or Val(txt_hdg.Text) > 360 Then
MsgBox "Illegal entry."
txt_hdg.Text = ""
Exit Sub
End If
End Sub
Private Sub txt_ns_Change()
txt_ns.Text = UCase(txt_ns.Text)
If Len(txt_ns.Text) >= 2 Then
MsgBox "Illegal entry."
txt_ns.Text = ""
Exit Sub
End If
End Sub
Private Sub txt_speed_Change()
If Len(txt_speed.Text) >= 3 Then
MsgBox "Illegal entry."
txt_speed.Text = ""
Exit Sub
End If
End Sub
Private Sub txt_st_lon_deg_Change()
If Len(txt_st_lon_deg) >= 4 Then
MsgBox "Illegal entry."
txt_st_lon_deg = ""
Exit Sub
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -