Instantly share code, notes, and snippets.
Created
December 13, 2020 14:42
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save dj1711572002/950cea5031e4c0f9ae1755cc64903952 to your computer and use it in GitHub Desktop.
F9P_MovingBase8Hz_GraphicMonitor_RealTImeGraph_Logging rev02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Serial Port Recieve Sample Program | |
'Form1 Object must create ,button1,2 & textbox 1,2 | |
Imports System.Drawing | |
Imports System.IO.Ports | |
Imports Microsoft.VisualBasic.FileIO | |
Imports System.IO | |
Imports System.Text | |
Imports System.Collections | |
Public Class Form1 | |
'Dim bdat As Byte() | |
Dim sdat As String() | |
Dim i, j, k, l As Integer | |
Dim NN As Integer | |
Dim NVC As Integer = 0 'NAV data Counter | |
Dim NVi As Integer = 0 | |
Dim PVTflag As Integer = 0 | |
Dim RELPflag As Integer = 0 | |
Dim startIndex As Integer | |
Dim strPVT As String | |
Dim sbPVT As String() | |
Dim bPVT As Byte(,) | |
Dim strRELP As String | |
Dim sbRELP As String() | |
Dim bRELP As Byte(,) | |
Dim sw As New System.Diagnostics.Stopwatch() | |
'================PVT RELP Paramers============================ | |
Dim parPVT As Long() | |
Dim parRELP As Long() | |
Public headPVT As String | |
Public headRELP As String | |
'=============File declarations ================ | |
Public file As System.IO.StreamWriter | |
Public file1 As System.IO.StreamWriter | |
Public fileH As System.IO.StreamWriter | |
Public file_dgv As System.IO.StreamWriter | |
'------file para------------ | |
Public cindex As Integer | |
Public dreadata(1000, 1000) As String | |
Public dcIndex As Integer | |
Public dcIndex_max As Integer | |
Public rdataN As Integer | |
Public fopen As Integer | |
Public f1open As Integer | |
Public fnameH As String | |
Public fStr1, fstr2 As String | |
'---plotC parameters------------ | |
Public startrowN As Integer | |
Public plotrowN As Integer | |
Public zLon, zLat, zHeight As Integer '緯度経度高度plot 中心基準点 | |
Public zRelN, zRelE, zRelD As Integer 'RELPOSNED 基準点 | |
Public zsetFlag As Integer | |
'=============================START PROGRM================================================================================================= | |
Delegate Sub DataDelegate(ByVal sdata As String) | |
'========================================================================================================================================== | |
Private Sub PrintData(ByVal sdata As String) | |
k = k + 1 | |
'Debug.Print("slen=" & CStr(sdata.Length) & "sdata(" & CStr(k) & ")=" & sdata) | |
startIndex = sdata.IndexOf("B5-62-01-07") | |
If startIndex >= 0 And sdata.Length >= 299 Then | |
sw.Stop() | |
Debug.Print("--------------PVT_time=" & sw.ElapsedMilliseconds) | |
sw.Start() | |
strPVT = sdata.Substring(startIndex, 299) 'PVT 100bytex3=300 最後のデリミタが無いから299 | |
sbPVT = strPVT.Split("-") | |
' Debug.Print("PVT:start=" & CStr(startIndex) & "len=" & CStr(sdata.Length) & "strPVT=" & strPVT) | |
PVTflag = 1 | |
End If | |
startIndex = sdata.IndexOf("B5-62-01-3C") | |
If startIndex >= 0 And sdata.Length >= 215 Then | |
sw.Stop() | |
Debug.Print("--------------RELPOSNED_time=" & sw.ElapsedMilliseconds) | |
sw.Start() | |
strRELP = sdata.Substring(startIndex, 215) ' RELPOSNED 72bytex3=216 最後のデリミタが無いから215 | |
sbRELP = strRELP.Split("-") | |
' Debug.Print("RELPOSNED:start=" & CStr(startIndex) & "len=" & CStr(sdata.Length) & "strRELP=" & strRELP) | |
RELPflag = 1 | |
End If | |
If PVTflag = 1 And RELPflag = 1 Then | |
NVC += 1 'NAV data set Counter | |
' Debug.Print("NVC=" & CStr(NVC)) | |
'--------PVTとRELPOSNED16進数string配列を2次元Byte配列に変換-------------------------------------------- | |
For i = 0 To 99 | |
bPVT(NVC, i) = Convert.ToByte(sbPVT(i), 16) | |
' Debug.Print("bPVT(" & CStr(NVC) & "," & CStr(i) & ")=" & CStr(bPVT(NVC, i)) & ":" & sbPVT(i)) | |
Next | |
For i = 0 To 71 | |
bRELP(NVC, i) = Convert.ToByte(sbRELP(i), 16) | |
' Debug.Print("bRELP(" & CStr(NVC) & "," & CStr(i) & ")=" & CStr(bRELP(NVC, i)) & ":" & sbRELP(i)) | |
Next | |
'------------------------------------------------------------------------------------------------------- | |
'=========================================================================================================================================================== | |
'DGVデータ表示============================================================================================================================================= | |
'=========================================================================================================================================================== | |
Dim rowN As Integer | |
rowN = (NVC - 1) 'Data Printing 繰り返し行指定 | |
'----------------変換 SUB----------------------------------------------- | |
PVT_Trans(NVC) ' PVT Binary を実数データに変換 parPVT(1-33) as integer | |
RELP_Trans(NVC) ' RELPOSNED Binary を実数データに変換 parRELP(1-15) as integer | |
'--------------ファイルWrite parPVTとparRELP dgv表示ではなく全データ保存---------------------------------------------------- | |
If fopen = 1 Then | |
Label2.Text = "-Logging-" | |
Dim fStr As String | |
fStr = CStr(NVC) | |
For i = 1 To 33 'parPVT(1-33) to fStr | |
fStr = fStr + "," + CStr(parPVT(i)) | |
Next | |
For i = 1 To 15 'parRELP(1-15) to fStr | |
fStr = fStr + "," + CStr(parRELP(i)) | |
Next | |
fStr = fStr + vbCrLf | |
file.Write(fStr) | |
End If | |
'-------------DGV1 サイズ決め------------------------------- | |
dgv1.ColumnCount = 23 | |
'----Rows(0)=time sec | |
dgv1.Columns(0).HeaderText = "Sec" | |
dgv1.Columns(0).Width = 40 | |
Dim tSec As Single = NVC * 0.125 ' Sampling time sec | |
'--PVTヘッダー | |
dgv1.Columns(1).HeaderText = "iTow" | |
Dim iTow As Integer = parPVT(1) | |
dgv1.Columns(1).Width = 60 | |
dgv1.Columns(2).HeaderText = "fixType" | |
Dim fixType As Integer = parPVT(11) | |
dgv1.Columns(3).HeaderText = "numSV" | |
Dim numSV As Integer = parPVT(14) | |
dgv1.Columns(4).HeaderText = "lon" | |
Dim lon As Integer = parPVT(15) | |
dgv1.Columns(5).HeaderText = "lat" | |
Dim lat As Integer = parPVT(16) | |
dgv1.Columns(6).HeaderText = "height" | |
Dim height As Integer = parPVT(17) | |
dgv1.Columns(7).HeaderText = "hAcc" | |
Dim hAcc As Integer = parPVT(19) | |
dgv1.Columns(8).HeaderText = "vAcc" | |
Dim vAcc As Integer = parPVT(20) | |
dgv1.Columns(9).HeaderText = "velN" | |
Dim velN As Integer = parPVT(21) | |
dgv1.Columns(10).HeaderText = "velE" | |
Dim velE As Integer = parPVT(22) | |
dgv1.Columns(11).HeaderText = "velD" | |
Dim velD As Integer = parPVT(23) | |
'--RELPOSNED ヘッダー | |
dgv1.Columns(12).HeaderText = "RELP_iTow" | |
Dim RELP_iTOW As Integer = parRELP(1) | |
dgv1.Columns(13).HeaderText = "relPosN" | |
Dim relPosN As Single = parRELP(2) + parRELP(7) * 0.1 | |
dgv1.Columns(14).HeaderText = "relPosE" | |
Dim relPosE As Single = parRELP(3) + parRELP(8) * 0.1 | |
dgv1.Columns(15).HeaderText = "relPosD" | |
Dim relPosD As Single = parRELP(4) + parRELP(9) * 0.1 | |
dgv1.Columns(16).HeaderText = "relPosLength" | |
Dim relPosLength As Single = parRELP(5) + parRELP(10) * 0.1 | |
dgv1.Columns(17).HeaderText = "relPosHeading" | |
Dim relPosHeading As Single = parRELP(6) * 0.00001 | |
dgv1.Columns(18).HeaderText = "accN" | |
Dim accN As Single = parRELP(11) * 0.01 | |
dgv1.Columns(19).HeaderText = "accE" | |
Dim accE As Single = parRELP(12) * 0.01 | |
dgv1.Columns(20).HeaderText = "accD" | |
Dim accD As Single = parRELP(13) * 0.01 | |
dgv1.Columns(21).HeaderText = "accLength" | |
Dim accLength As Single = parRELP(14) * 0.01 | |
dgv1.Columns(22).HeaderText = "accHeading" | |
Dim accHeading As Single = parRELP(15) * 0.00001 | |
'===================行追加と一括書き込み=============================== | |
'PVT=1:iTow,11:fixType,14:numSV,15:lon,16:lat,17:height,19:hAcc ,20:vAcc,21:velN,22:velE,23:velD | |
'RELPOSNED=1:iTOW,2:relPosN,3:relPosE,4:relPosD,5:relPosLength,6:relPosHeading, | |
'11:accN,12:accE,13:accD,14:accLength,15:accHeading | |
dgv1.Rows.Add(tSec, iTow, fixType, numSV, lon, lat, height, hAcc, vAcc, velN, velE, velD, | |
RELP_iTOW, relPosN, relPosE, relPosD, relPosLength, relPosHeading, | |
accN, accE, accD, accLength, accHeading) | |
'------------dgv1 行ヘッダー番号 -------------------------------- | |
dgv1.Rows(rowN).HeaderCell.Value = NVC.ToString() '行ヘッダーにデータ番号NVC | |
dgv1.RowHeadersWidth = 60 | |
'-----Focus Row------------------------------------ | |
If rowN > 5 Then | |
dgv1.FirstDisplayedScrollingRowIndex = rowN | |
End If | |
PVTflag = 0 | |
RELPflag = 0 | |
'================================================================================================================================================ | |
'================================================================================================================================================ | |
'plotC グラフィック描画======================================================================================================================= | |
'================================================================================================================================================ | |
'================================================================================================================================================ | |
'------wait 時間制御 NVCカウントする hscrollbar1でwait時間調整 | |
' waitN=0停止で手動プロットモード waitN=10で実速度0.125sec | |
Dim waitN As Integer | |
Dim ctime As Integer | |
Dim ctime_1 As Integer = 0 | |
TextBox1.Text = waitN | |
'RealTimeMotion | |
If CheckBox2.Checked = True Then | |
plotC(NVC - 1) | |
End If | |
End If | |
End Sub | |
'------------手動モーション位置マウスクリック指定 | |
Private Sub dgv1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv1.CellClick | |
If zsetFlag = 1 Then | |
plotrowN = dgv1.CurrentCell.RowIndex | |
Label4.Text = plotrowN + 1 | |
plotC(plotrowN) | |
End If | |
End Sub | |
'---------------センタリングボタン 現在セル位置をスタート座標とする--------------- | |
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click | |
centering() | |
End Sub | |
Private Sub centering() | |
startrowN = NVC - 1 'dgv1.CurrentCell.RowIndex | |
zLon = dgv1.Rows(startrowN).Cells(4).Value '基準Long | |
zLat = dgv1.Rows(startrowN).Cells(5).Value '基準Lati | |
zHeight = dgv1.Rows(startrowN).Cells(6).Value '基準Lati | |
zRelN = dgv1.Rows(startrowN).Cells(13).Value '基準Lati | |
zRelE = dgv1.Rows(startrowN).Cells(14).Value '基準Lati | |
zRelD = dgv1.Rows(startrowN).Cells(15).Value '基準Lati | |
TextBox3.Text = startrowN + 1 '行ヘッダー番号に合わせると+1 | |
zsetFlag = 1 | |
End Sub | |
'============================================================================================================================================= | |
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click | |
SerialPort1.PortName = ComboBox1.SelectedItem ' "COM18" ' TextBox1.Text 'オープンするポート名を格納 | |
SerialPort1.Open() 'ポートオープン | |
End Sub | |
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click | |
If fopen = 1 Then | |
file.Close() | |
End If | |
Label2.Text = "" | |
If SerialPort1.IsOpen = True Then 'ポートオープン済み | |
SerialPort1.Close() 'ポートクローズ | |
End If | |
End Sub | |
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived | |
Dim ReceivedData As String = "" '受信データ用変数を宣言します | |
If CheckBox1.Checked = True Then | |
Try | |
Dim arrByte As Byte() = New Byte(SerialPort1.BytesToRead - 1) {} | |
SerialPort1.Read(arrByte, 0, arrByte.GetLength(0)) 'Binary Receive | |
ReceivedData = BitConverter.ToString(arrByte) ' & vbCrLf | |
Catch ex As Exception | |
ReceivedData = ex.Message '例外処理を行います | |
End Try | |
'Invokeメソッドにより実行されるメソッドへのデリゲートの宣言を行い、受信データを表示します | |
Dim adre As New DataDelegate(AddressOf PrintData) | |
Me.Invoke(adre, ReceivedData) | |
End If | |
End Sub | |
Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated | |
'============DIM initialize=============================== | |
ReDim sbPVT(100) | |
ReDim sbRELP(72) | |
ReDim bPVT(30000, 100) | |
ReDim bRELP(30000, 72) | |
'dgv1.ColumnCount = 172 | |
'dgv1.RowCount = 2000 | |
ReDim parPVT(100) | |
ReDim parRELP(72) | |
For Each sp As String In My.Computer.Ports.SerialPortNames | |
ComboBox1.Items.Add(sp) | |
Next | |
'dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells | |
'For i = 0 To dgv1.ColumnCount - 1 | |
' dgv1.Columns(i).Width = 40 | |
'Next | |
headPVT = "iTOW,Year,month,day,hour,min,sec,valid,tAcc,nano,fixType,flags,flags2,numSV,lon,lat,height,hMSL,hAcc,vAcc,velN,velE,velD,gSpeed,headMot,sAcc,headAcc,pDOP,flags3,reserved1,headVeh,magDec,magAcc" | |
headRELP = "R_iTOW,relPosN,relPosE,relPosD,relPosLength,relPosHeading,relPosHPN,relPosHPE,relPosHPD,relPosHPLength,accN,accE,accD,accLength,accHeading" | |
End Sub | |
'=======================UBX Translation============================================================================= | |
Private Sub PVT_Trans(ByVal NVC As Integer) | |
'----------------PVT Trans--------------------------------------- | |
' headPVT = "iTOW,Year,month,day,hour,min,sec,valid,tAcc,nano,fixType,flags,flags2,numSV,lon,lat,height,hMSL,hAcc,vAcc,velN,velE,velD,gSpeed,headMot,sAcc,headAcc,pDOP,flags3,reserved1,headVeh,magDec,magAcc" | |
'Byte OFFSET=5 (header: B5,62,01,07,5C 5 Byte) | |
Dim off As Integer = 6 | |
'1:iTOW 0-3 | |
parPVT(1) = pvtI4(NVC, 0 + off) | |
' Debug.Print("parPVT(1)=" & CStr(parPVT(1))) | |
'2:Year 4-5 | |
parPVT(2) = pvtI2(NVC, 4 + off) | |
' Debug.Print("parPVT(2)=" & CStr(parPVT(2))) | |
'3:month 6 | |
parPVT(3) = CInt(bPVT(NVC, 6 + off)) | |
' Debug.Print("parPVT(3)=" & CStr(parPVT(3))) | |
'4:day 7 | |
parPVT(4) = CInt(bPVT(NVC, 7 + off)) | |
' Debug.Print("parPVT(4)=" & CStr(parPVT(4))) | |
'5:hour 8 | |
parPVT(5) = CInt(bPVT(NVC, 8 + off)) | |
' Debug.Print("parPVT(5)=" & CStr(parPVT(5))) | |
'6:min 9 | |
parPVT(6) = CInt(bPVT(NVC, 9 + off)) | |
' Debug.Print("parPVT(6)=" & CStr(parPVT(6))) | |
'7:sec 10 | |
parPVT(7) = CInt(bPVT(NVC, 10 + off)) | |
Debug.Print("parPVT(7)=" & CStr(parPVT(7))) | |
'8:valid 11 | |
parPVT(8) = CInt(bPVT(NVC, 11 + off)) | |
'Debug.Print("parPVT(8)=" & CStr(parPVT(8))) | |
'9:tAcc 12,13,14,15 | |
parPVT(9) = pvtI4(NVC, 12 + off) | |
' Debug.Print("parPVT(9)=" & CStr(parPVT(9))) | |
'10:nano 16 | |
parPVT(10) = CInt(bPVT(NVC, 16 + off)) | |
'Debug.Print("parPVT(10)=" & CStr(parPVT(10))) | |
'11:fixType 20 | |
parPVT(11) = CInt(bPVT(NVC, 20 + off)) | |
'Debug.Print("parPVT(11)=" & CStr(parPVT(11))) | |
'12:flags 21 | |
parPVT(12) = CInt(bPVT(NVC, 21 + off)) | |
' Debug.Print("parPVT(12)=" & CStr(parPVT(12))) | |
'13:flags2 22 | |
parPVT(13) = CInt(bPVT(NVC, 22 + off)) | |
' Debug.Print("parPVT(13)=" & CStr(parPVT(13))) | |
'14:numSV 23 | |
parPVT(14) = CInt(bPVT(NVC, 23 + off)) | |
' Debug.Print("parPVT(14)=" & CStr(parPVT(14))) | |
'15:lon'24,25,26,27 | |
parPVT(15) = pvtI4(NVC, 24 + off) | |
' Debug.Print("parPVT(15)=" & CStr(parPVT(15))) | |
'16:lat 28,29,30,31 | |
parPVT(16) = pvtI4(NVC, 28 + off) | |
' Debug.Print("parPVT(16)=" & CStr(parPVT(16))) | |
'17:height 32,33,34,35 | |
parPVT(17) = pvtI4(NVC, 32 + off) | |
' Debug.Print("parPVT(17)=" & CStr(parPVT(17))) | |
'18:hMSL 36,37,38,39 | |
parPVT(18) = pvtI4(NVC, 36 + off) | |
' Debug.Print("parPVT(18)=" & CStr(parPVT(18))) | |
'19:hAcc 40,41,42,43 | |
parPVT(19) = pvtI4(NVC, 40 + off) | |
' Debug.Print("parPVT(19)=" & CStr(parPVT(19))) | |
'20:vAcc 44,45,46,47 | |
parPVT(20) = pvtI4(NVC, 44 + off) | |
' Debug.Print("parPVT(20)=" & CStr(parPVT(20))) | |
'21:velN 48,49,50,51 | |
parPVT(21) = pvtI4(NVC, 48 + off) | |
' Debug.Print("parPVT(21)=" & CStr(parPVT(21))) | |
'22:velE 52,53,54,55 | |
parPVT(22) = pvtI4(NVC, 52 + off) | |
' Debug.Print("parPVT(22)=" & CStr(parPVT(22))) | |
'23:velD 56,57,58,59 | |
parPVT(23) = pvtI4(NVC, 56 + off) | |
' Debug.Print("parPVT(23)=" & CStr(parPVT(23))) | |
'24:gSpeed 60,61,62,63 | |
parPVT(24) = pvtI4(NVC, 60 + off) | |
'Debug.Print("parPVT(24)=" & CStr(parPVT(24))) | |
'25:headMot 64,65,66,67 | |
parPVT(25) = pvtI4(NVC, 64 + off) | |
' Debug.Print("parPVT(25)=" & CStr(parPVT(25))) | |
'26:sAcc 68,69,70,71 | |
parPVT(26) = pvtI4(NVC, 68 + off) | |
' Debug.Print("parPVT(26)=" & CStr(parPVT(26))) | |
'27:headAcc 72,73,74,75 | |
parPVT(27) = pvtI4(NVC, 72 + off) | |
' Debug.Print("parPVT(27)=" & CStr(parPVT(27))) | |
'28:pDOP 76,77 | |
parPVT(28) = pvtI2(NVC, 76 + off) | |
' Debug.Print("parPVT(28)=" & CStr(parPVT(28))) | |
'29:flags3 78 | |
parPVT(29) = CInt(bPVT(NVC, 78 + off)) | |
' Debug.Print("parPVT(29)=" & CStr(parPVT(29))) | |
'30:reserved1 79,80,81,82 | |
parPVT(30) = pvtI4(NVC, 79 + off) | |
' Debug.Print("parPVT(30)=" & CStr(parPVT(30))) | |
'31:headVeh 83,84,85,86 | |
parPVT(31) = pvtI4(NVC, 83 + off) | |
'Debug.Print("parPVT(31)=" & CStr(parPVT(31))) | |
'32:magDec 88,89 | |
parPVT(32) = pvtI2(NVC, 88 + off) | |
' Debug.Print("parPVT(32)=" & CStr(parPVT(32))) | |
'33:magAcc 90,91 | |
parPVT(33) = pvtI2(NVC, 90 + off) | |
' Debug.Print("parPVT(33)=" & CStr(parPVT(33))) | |
End Sub | |
Private Sub RELP_Trans(ByVal NVC As Integer) | |
'----------------PVT Trans--------------------------------------- | |
' headRELP = "R_iTOW,relPosN,relPosE,relPosD,relPosLength,relPosHeading,relPosHPN,relPosHPE,relPosHPD,relPosHPLength,accN,accE,accD,accLength,accHeading" | |
'Byte OFFSET=5 (header: B5,62,01,07,5C 5 Byte) | |
Dim off As Integer = 6 | |
'---------1:iTOW 4-7 | |
parRELP(1) = relpI4(NVC, 4 + off) | |
'Debug.Print("parRELP(1)=" & CStr(parRELP(1))) | |
'---------2:relPosN 8-11 | |
parRELP(2) = relpI4(NVC, 8 + off) | |
'Debug.Print("parRELP(2)=" & CStr(parRELP(2))) | |
'---------3:relPosE 12-15 | |
parRELP(3) = relpI4(NVC, 12 + off) | |
'Debug.Print("parRELP(3)=" & CStr(parRELP(3))) | |
'---------4:relPosD 16-19 | |
parRELP(4) = relpI4(NVC, 16 + off) | |
'Debug.Print("parRELP(4)=" & CStr(parRELP(4))) | |
'---------5:relPosLength 20-23 | |
parRELP(5) = relpI4(NVC, 20 + off) | |
'Debug.Print("parRELP(5)=" & CStr(parRELP(5))) | |
'---------6:relPosHeading 24-27 | |
parRELP(6) = relpI4(NVC, 24 + off) | |
'Debug.Print("parRELP(6)=" & CStr(parRELP(6))) | |
'---------7:relPosHPN 32 | |
parRELP(7) = CInt(bRELP(NVC, 32 + off)) | |
'Debug.Print("parRELP(7)=" & CStr(parRELP(7))) | |
'---------8:relPosHPE 33 | |
parRELP(8) = CInt(bPVT(NVC, 36 + off)) | |
'Debug.Print("parRELP(8)=" & CStr(parRELP(8))) | |
'---------9:relPosHPD 34 | |
parPVT(9) = CInt(bPVT(NVC, 34 + off)) | |
'Debug.Print("parRELP(9)=" & CStr(parRELP(9))) | |
'--------10:relPosHPLength 35 | |
parRELP(10) = CInt(bPVT(NVC, 35 + off)) | |
'Debug.Print("parRELP(10)=" & CStr(parRELP(10))) | |
'--------11:accN 36-39 | |
parRELP(11) = relpI4(NVC, 36 + off) | |
'Debug.Print("parRELP(11)=" & CStr(parRELP(11))) | |
'--------12:accE 40-43 | |
parRELP(12) = relpI4(NVC, 40 + off) | |
'Debug.Print("parRELP(12)=" & CStr(parRELP(12))) | |
'--------13:accD 44-47 | |
parRELP(13) = relpI4(NVC, 44 + off) | |
'Debug.Print("parRELP(13)=" & CStr(parRELP(13))) | |
'--------14:accLength 48-51 | |
parRELP(14) = relpI4(NVC, 48 + off) | |
'Debug.Print("parRELP(14)=" & CStr(parRELP(14))) | |
'--------15:accHeading 52-55 | |
parRELP(15) = relpI4(NVC, 52 + off) | |
'Debug.Print("parRELP(15)=" & CStr(parRELP(15))) | |
End Sub | |
'=====================================================BInary To Decimal =============================================================================== | |
'-------------------------------PVT---------------------------------------------------- | |
Private Function pvtI4(ByVal dnum As Integer, ByVal sN As Integer) As Integer | |
Dim i4 As Integer | |
Debug.Print("In_pvtI4:bPVT()=" & CStr(sN) & "::" & CStr(bPVT(dnum, sN)) & "," & CStr(bPVT(dnum, sN + 1)) & "," & CStr(bPVT(dnum, sN + 2)) & "," & CStr(bPVT(dnum, sN + 3))) | |
If (bPVT(dnum, sN + 3) And &H80) And &H80 Then '{//4番目のBYTEの最上位ビットたっていればマイナス | |
'Debug.Print("-bPVT*65536=" & CStr(CLng((bPVT(dnum, sN + 2) * 65536)))) | |
'Debug.Print("-bPVT*256*256*256=" & CStr(CLng(255 - bPVT(dnum, sN + 3)) * 16777216)) | |
i4 = -CLng(256 - (bPVT(dnum, sN)) + CLng(255 - bPVT(dnum, sN + 1)) * 256 + CLng(255 - bPVT(dnum, sN + 2)) * 65536 + CLng(255 - bPVT(dnum, sN + 3)) * 16777216) | |
Else | |
'Debug.Print("+bPVT*65536=" & CStr(sN) & "::" & CStr(bPVT(dnum, sN + 2) * 65536)) | |
'Debug.Print("+bPVT*256*256*256=" & CStr(sN) & "::" & CStr(bPVT(dnum, sN + 3) * 256 * 256 * 256)) | |
i4 = CLng(bPVT(dnum, sN) * 1 + CLng(bPVT(dnum, sN + 1)) * 256 + CLng(bPVT(dnum, sN + 2)) * 65536 + CLng(bPVT(dnum, sN + 3)) * 256 * 256 * 256) | |
End If | |
Return i4 | |
End Function | |
Private Function pvtI2(ByVal dnum As Integer, ByVal sN As Integer) As Integer | |
Dim i2 As Integer | |
i2 = bPVT(dnum, sN + 1) * 1 + bPVT(dnum, sN) * 256 | |
Return i2 | |
End Function | |
'------------------RELPOSNED -------------------------------------------------- | |
Private Function relpI4(ByVal dnum As Integer, ByVal sN As Integer) As Integer | |
Dim i4 As Integer | |
If (bRELP(dnum, sN + 3) And &H80) And &H80 Then '{//4番目のBYTEの最上位ビットたっていればマイナス | |
i4 = -CLng(256 - (bRELP(dnum, sN)) + CLng(255 - bRELP(dnum, sN + 1)) * 256 + CLng(255 - bRELP(dnum, sN + 2)) * 65536 + CLng(255 - bRELP(dnum, sN + 3)) * 16777216) | |
Else | |
i4 = CLng(bRELP(dnum, sN) * 1 + CLng(bRELP(dnum, sN + 1)) * 256 + CLng(bRELP(dnum, sN + 2)) * 65536 + CLng(bRELP(dnum, sN + 3)) * 256 * 256 * 256) | |
End If | |
Return i4 | |
End Function | |
Private Function relpI2(ByVal dnum As Integer, ByVal sN As Integer) As Integer | |
Dim i2 As Integer | |
i2 = bRELP(dnum, sN + 1) * 1 + bRELP(dnum, sN) * 256 | |
Return i2 | |
End Function | |
'========================================================================================================================================================= | |
'========================================================================================================================================================= | |
'FILE READ /Write Sub | |
'========================================================================================================================================================= | |
'======================================================================================================================================================== | |
'【MB_LogFile名指定ボタン 3 file Open 】 | |
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click | |
'===================FILE Name================= | |
'------FILE SAVE---------------------- | |
Dim sfd As New SaveFileDialog() | |
Dim fname As String | |
fname = Format(Now, "yyyyMMdd_HHmmss") | |
' 'debug.Print("fname=" & fname) | |
sfd.FileName = "MB_" + fname | |
sfd.Filter = "TXTファイル|*.txt|CSVファイル|*.csv|すべてのファイル|*.*" | |
sfd.InitialDirectory = "C:\RTK_Log " | |
sfd.FilterIndex = 2 | |
sfd.Title = "保存先のファイルを選択してください" | |
' ダイアログボックスを閉じる前に現在のディレクトリを復元する (初期値 False) | |
sfd.RestoreDirectory = True | |
If sfd.ShowDialog() = DialogResult.OK Then | |
'OKボタンがクリックされたとき、選択されたファイル名を表示する | |
Console.WriteLine(sfd.FileName) | |
TextBox2.Text = sfd.FileName | |
End If | |
fname = TextBox2.Text | |
' fname = "C:\RTK_Log\MB_" & fname & ".csv" | |
'TextBox2.Text = fname | |
'---MS Example------------------------------ | |
'Dim file As System.IO.StreamWriter | |
'file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True) | |
'file.WriteLine("Here is the first string.") | |
'file.Close() | |
'------------------------------------------ | |
Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding(“Shift_JIS”) | |
file = My.Computer.FileSystem.OpenTextFileWriter(fname, False, enc) | |
fopen = 1 'file Open Flag | |
file.Write(fname + vbCrLf) 'File Name write | |
' file.Close() | |
'------Header text write---------------------- | |
file.Write("NVC," + headPVT + "," + headRELP + vbCrLf) | |
End Sub | |
'=============================CSVファイル READ ボタン======================================= | |
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click | |
CSV_DGV(1) | |
End Sub | |
Private Sub CSV_DGV(dN As Integer) | |
Dim datasu As Integer | |
Dim maxRowCSV As Integer | |
Dim headerFlg As Integer | |
Dim rIndex As Integer | |
'dgN = dN | |
''---------dgv サイズ表示------- | |
'TextBox4.Text = dgv1.Columns.Count | |
'TextBox5.Text = dgv1.Rows.Count | |
''---------------------------------- | |
'If CheckBox26.Checked = True Then | |
'-----dgvに表示------------ | |
'------dgv初期化-------------- | |
dgv1.Columns.Clear() | |
dgv1.DataSource = Nothing | |
'------File名Path------------------- | |
Dim Path As String = readfile() 'Dialogから読み込むファイル名指定 | |
Label3.Text = Path | |
'-------ファイルの行数---------------- | |
maxRowCSV = GetLinesOfTextFile(Path) | |
'Label1.Text = CStr(maxRowCSV) & "行" | |
'--------CSVァイル読み込み----------------- | |
Label2.Text = "CSV File Loaded" | |
datasu = CSV_crlf(Path) 'ファイルの改行数なのでHeader行も含まれる行数なのでRowではない | |
'Label2.Text = "CSV File Read Finished" | |
'--------dgv ヘッダー処理-------------------- | |
Dim hIndex As Integer = 0 | |
If dreadata(0, 0).IndexOf(".csv") >= 0 Then | |
hIndex = 1 | |
End If | |
If IsNumeric(dreadata(hIndex, 0)) = False Then 'ヘッダーあり | |
' Label1.Text = "ヘッダーあり" | |
dgv1.RowCount = datasu - 1 'ヘッダー行を差し引いてDGVの行を作る | |
'debug.Print("dcIndex_max=" & CStr(dcIndex_max)) | |
dgv1.ColumnCount = dcIndex_max | |
headerFlg = 1 | |
End If | |
If IsNumeric(dreadata(hIndex, 0)) = True Then 'ヘッダーなし | |
'Label1.Text = "ヘッダーなし" | |
dgv1.RowCount = datasu 'データ数分DGVの行を作る | |
'debug.Print("dcIndex_max=" & CStr(dcIndex_max)) | |
dgv1.ColumnCount = dcIndex_max | |
headerFlg = 0 | |
End If | |
''========================Header Col作成================= | |
If IsNumeric(dreadata(hIndex, 0)) = False Then 'ヘッダーがある場合 | |
For j = 0 To dcIndex_max - 1 | |
dgv1.Columns(j).HeaderText = dreadata(hIndex, j) 'dgvの列Header Property定義 | |
Next | |
End If | |
'=========CSVから全データ配列 redata(maxRowCSV,cIndex)========== | |
rIndex += 1 | |
For i = 0 To dgv1.RowCount - 1 | |
For j = 0 To dgv1.ColumnCount - 1 '1その行の列数は、dreadata(行,0)に格納されている | |
''debug.Print("DGV_rdata(" & CStr(i) & "," & CStr(j) & ")=" & CStr(dreadata(i, j))) | |
dgv1.Rows(i).Cells(j).Value = dreadata(i + headerFlg + hIndex, j) | |
Next j | |
Next i | |
'End If | |
'maxRowCol() | |
End Sub | |
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged | |
If CheckBox1.Checked = False Then | |
Button2.Enabled = True | |
Else | |
Button2.Enabled = False | |
End If | |
End Sub | |
Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar1.Scroll | |
End Sub | |
Private Function readfile() As String | |
Dim ofd As New OpenFileDialog() | |
'はじめのファイル名を指定する | |
'はじめに「ファイル名」で表示される文字列を指定する | |
ofd.FileName = "yyyyMMdd_HHmmss" '"default.html" | |
'はじめに表示されるフォルダを指定する | |
'指定しない(空の文字列)の時は、現在のディレクトリが表示される | |
ofd.InitialDirectory = "C:\RTK_Log " | |
'[ファイルの種類]に表示される選択肢を指定する | |
'指定しないとすべてのファイルが表示される | |
ofd.Filter = "TXTファイル|*.txt|CSVファイル|*.csv|すべてのファイル|*.*" | |
'[ファイルの種類]ではじめに選択されるものを指定する | |
'2番目の「すべてのファイル」が選択されているようにする | |
ofd.FilterIndex = 2 | |
'タイトルを設定する | |
ofd.Title = "開くファイルを選択してください" | |
'ダイアログボックスを閉じる前に現在のディレクトリを復元するようにする | |
ofd.RestoreDirectory = True | |
'存在しないファイルの名前が指定されたとき警告を表示する | |
'デフォルトでTrueなので指定する必要はない | |
ofd.CheckFileExists = True | |
'存在しないパスが指定されたとき警告を表示する | |
'デフォルトでTrueなので指定する必要はない | |
ofd.CheckPathExists = True | |
If ofd.ShowDialog() = DialogResult.OK Then | |
'OKボタンがクリックされたとき、選択されたファイル名を表示する | |
'debug.Print(ofd.FileName) | |
End If | |
Return ofd.FileName | |
End Function | |
'========================================================================================== | |
'===================CSVファイル読み込み CrLf付 FILE Read Function================================================= | |
'====================================================================================== | |
Private Function CSV_crlf(ByVal fnm As String) As Integer '戻り値はデータ行数 データはdreadata(rdataN,dcindex) | |
Using parser As New TextFieldParser(fnm, System.Text.Encoding.GetEncoding("Shift_JIS")) | |
parser.TextFieldType = FieldType.Delimited | |
parser.SetDelimiters(",") ' 区切り文字はコンマ | |
' parser.HasFieldsEnclosedInQuotes = False | |
' parser.TrimWhiteSpace = False | |
dcIndex = 0 | |
dcIndex_max = 0 | |
rdataN = 0 | |
While Not parser.EndOfData | |
Dim row As String() = parser.ReadFields() ' 1行読み込み | |
For Each field As String In row | |
dreadata(rdataN, dcIndex) = field | |
Debug.Print("field=" & field) | |
Debug.Print("dreadata(" & CStr(rdataN) & "," & CStr(dcIndex) & ")=" & dreadata(rdataN, dcIndex)) | |
dcIndex += 1 | |
Next | |
If dcIndex > dcIndex_max Then | |
dcIndex_max = dcIndex | |
End If | |
dcIndex = 0 | |
rdataN += 1 | |
End While | |
End Using | |
Return rdataN | |
End Function | |
'============================CSVファイル 総行数カウントFunction============================== | |
Public Function GetLinesOfTextFile(ByVal FileName As String) As Integer | |
Dim StReader As New System.IO.StreamReader(FileName) | |
Dim LineCount As Integer | |
While (StReader.Peek() >= 0) | |
StReader.ReadLine() | |
LineCount += 1 | |
End While | |
Return LineCount | |
End Function | |
'【DGV まるごとSave】 | |
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click | |
'---------dgv SCPmode保存ファイル準備------------------------------ | |
fnameH = Format(Now, "yyyyMMdd_HHmmss") | |
fStr1 = "DGV_" 'ComboBox9.SelectedItem.ToString() | |
fnameH = "C:\RTK_Log\" & fStr1 & fnameH & ".csv" | |
fstr2 = "FileOpen:" + fnameH | |
' RichTextBox1.AppendText(fStr2) | |
' RichTextBox1.ScrollToCaret() | |
Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding(“Shift_JIS”) | |
file_dgv = My.Computer.FileSystem.OpenTextFileWriter(fnameH, False, enc) | |
f1open = 1 | |
Label1.Text = fnameH | |
'dgN = ComboBox37.SelectedIndex | |
'--------dgvから読んでファイル保存----------------------- | |
Dim SCPheadstr As String = "" | |
'---Header Str Save------------------ | |
For i = 0 To dgv1.ColumnCount - 1 | |
SCPheadstr += dgv1.Columns(i).HeaderText + "," | |
Next i | |
SCPheadstr += vbCrLf | |
file_dgv.Write(SCPheadstr) | |
'----------LoadNo,X,Y,Z save------------ | |
Dim SCPstr As String = "" | |
For i = 0 To dgv1.RowCount - 1 | |
'If CStr(dgv(dgN).Rows(i).Cells(0).Value) <> "" Then | |
'---Header Str Save------------------ | |
For j = 0 To dgv1.ColumnCount - 1 | |
SCPstr += CStr(dgv1.Rows(i).Cells(j).Value) + "," | |
'End If | |
Next j | |
SCPstr += vbCrLf | |
file_dgv.Write(SCPstr) | |
SCPstr = "" | |
Next i | |
file_dgv.Close() | |
f1open = 0 | |
End Sub | |
'=================== Graphic Start ================================================================= | |
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged | |
If CheckBox2.Checked = True Then | |
PictureBox1.Visible = True | |
centering() | |
plotC(plotrowN) | |
End If | |
If CheckBox2.Checked = False Then | |
PictureBox1.Visible = False | |
End If | |
End Sub | |
'=========================Graph Clear=================================== | |
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click | |
PictureBox1.Image = Nothing | |
End Sub | |
Sub plotC(ByVal rN As Integer) 'ByVal dataNo As Integer, ByVal value As Integer, ByVal value_1 As Integer, ByVal colorN As Integer) | |
Dim xsize As Integer = 1200 | |
Dim ysize As Integer = 400 | |
Dim xCenter As Integer = xsize / 2 | |
Dim yCenter As Integer = ysize / 2 | |
If PictureBox1.Image Is Nothing Then '初回だけBITMAPを定義する Picture1.imageという名称をつかうこと | |
PictureBox1.Image = New Bitmap(xsize, ysize) | |
End If | |
'If PictureBox2.Image Is Nothing Then '初回だけBITMAPを定義する Picture2.imageという名称をつかうこと | |
' PictureBox2.Image = New Bitmap(720, 240) | |
'End If | |
Dim g As Graphics = Graphics.FromImage(PictureBox1.Image) | |
'Dim g2 As Graphics = Graphics.FromImage(PictureBox2.Image) | |
'g.FillRectangle(Brushes.Black, 0, 0, xsize, ysize) | |
'lon=4,lat=5,height=6,relN=13,relE=14,relD=15 | |
Dim scale As Single | |
scale = HScrollBar1.Value / 10 | |
TextBox1.Text = scale | |
Dim rNlon As Integer = dgv1.Rows(rN).Cells(4).Value | |
Dim rNlat As Integer = dgv1.Rows(rN).Cells(5).Value | |
Dim rNheight As Integer = dgv1.Rows(rN).Cells(6).Value | |
Dim rNrelN As Integer = dgv1.Rows(rN).Cells(13).Value | |
Dim rNrelE As Integer = dgv1.Rows(rN).Cells(14).Value | |
Dim rNrelD As Integer = dgv1.Rows(rN).Cells(15).Value | |
Dim pxb As Integer = (CInt((rNlon - zLon) * scale) + xCenter) | |
Dim pyb As Integer = ysize - (CInt((rNlat - zLat) * scale) + yCenter) | |
Dim pxr As Integer = (CInt(((rNlon - zLon + rNrelE)) * scale) + xCenter) | |
Dim pyr As Integer = ysize - (CInt(((rNlat - zLat + rNrelN)) * scale) + yCenter) | |
Dim p As New Pen(Color.White) | |
p.Width = 0.1 | |
If pxb < xsize And pyb < ysize And pxr < xsize And pyr < ysize Then | |
g.FillEllipse(Brushes.LawnGreen, pxb, pyb, 3, 3) | |
g.FillEllipse(Brushes.Red, pxr, pyr, 3, 3) | |
If CheckBox3.Checked = True Then | |
g.DrawLine(p, pxb, pyb, pxr, pyr) | |
End If | |
End If | |
Label5.Text = "pxb=" & CStr(pxb) | |
Label6.Text = "pyb=" & CStr(pyb) | |
Label7.Text = "pxr=" & CStr(pxr) | |
Label8.Text = "pyr=" & CStr(pyr) | |
g.Dispose() | |
'b.Dispose() | |
PictureBox1.Invalidate() | |
End Sub ' plotC end | |
Private Function Hubeny(ByVal Lon1 As Double, ByVal Lat1 As Double, ByVal Lon2 As Double, ByVal Lat2 As Double) As Double | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment