Created
September 6, 2020 22:34
-
-
Save dj1711572002/580544a86669ce72455a3341c030edfe to your computer and use it in GitHub Desktop.
VB.NET SerialRecieving RealTime Graph and GraphAdjust
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
'Seril Port Recieve Realtime Graphic Monitor rev1.0 | |
'Shinshu-Makers 2020/09/07 | |
'SerialPort1 property COM10,115200 | |
'data 7ch "ch1_data,ch2_data,ch3_data,ch4_data,ch5\data,ch6_data,ch7_data vbcr" | |
Imports System.Drawing | |
Imports System.IO.Ports | |
Public Class Form1 | |
'=========Receive Stop=========== | |
Public rFlag As Integer = 1 | |
Public rcFlag As Integer = 0 | |
'=======file=============== | |
Public fname As String = "" | |
Public file As System.IO.StreamWriter | |
'======PictureBoxSize======== | |
Const yh = 240 | |
Const xw = 600 | |
Private onetime As Integer = 1 | |
Delegate Sub DataDelegate(ByVal sdata As String) | |
'=========Available Parameters in thie Calss================= | |
Private dataAry(600000, 7) As Long | |
Private dataNo As Long | |
'---------Plotting parameters-------------- | |
Private rate() As Double | |
Private Mag As Double | |
Private midvalue() As Double | |
Private dstep As Double 'x軸ドット単位 dot/dataNo | |
Private dvalue As Double = 1 'Y軸ドット単位 dot/mV 10mvで1ドット | |
'----------------------------------------- | |
Private Mave() As Double | |
Private sw As New System.Diagnostics.Stopwatch() | |
Private tp As TimeSpan | |
Private timestamp As Integer | |
Private stime As Integer 'plot start sampling time | |
Private etime As Integer 'plot end sampling time | |
Private totalsec As Double | |
Private startFlag As Integer = 0 | |
Private px As Integer | |
Private py As Integer | |
Private px_1 As Integer | |
Private py_1 As Integer '1個前のY座標 | |
'============================================================= | |
Private Sub PrintData(ByVal sdata As String) | |
'========First CSV File Declaration====================== | |
If CheckBox8.Checked = True And fname = "" Then | |
fname = Format(Now, "yyyyMMdd_HHmmss") | |
fname = "C:\vb_LOG\" & fname & ".csv" | |
TextBox21.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) | |
End If | |
'========================================================= | |
Dim delimiter As String = "," | |
Dim i As Integer | |
Dim dcount As String | |
'================sdata File writing==================== | |
If System.IO.File.Exists(fname) Then | |
file.Write(sdata) | |
Label7.Text = "Logging" | |
End If | |
'dcount = sdata & ":" & TextBox2.Text | |
'ListBox1.Items.Add(dcount) | |
'Debug.Print("sdata=" & sdata) | |
'Debug.Print("timestamp=" & CStr(timestamp)) | |
Dim dStr() As String = Split(sdata, delimiter, -1, CompareMethod.Text) | |
Dim colN As Integer | |
colN = 7 | |
Debug.Print("dStr.length=" & CStr(dStr.Length) & "sdata.Length=" & CStr(sdata.Length)) | |
If (dStr.Length = 7) Then | |
dataNo += 1 | |
'dStr(0) = dataNo | |
For i = 0 To dStr.Length - 1 | |
dataAry(dataNo, i) = CInt(dStr(i)) | |
Next | |
If startFlag = 1 Then | |
'=================PLOT SUBへ================= | |
'If i < 6 Then | |
plotC(dataNo, dataAry(dataNo, i), dataAry(dataNo - 1, i), i) 'plotC(x,y,colorN) | |
'Debug.Print("dataAry()=" & CStr(dataAry(dataNo, i)) & "i=" & CStr(i)) | |
'End If | |
'=========================================== | |
End If | |
TextBox2.Text = dataNo | |
TextBox3.Text = dStr.Length | |
TextBox4.Text = dStr(0) | |
TextBox5.Text = dStr(1) | |
TextBox6.Text = dStr(2) | |
TextBox7.Text = dStr(3) | |
TextBox8.Text = dStr(4) | |
TextBox9.Text = dStr(5) | |
TextBox10.Text = dStr(6) | |
'Debug.Print("dataAry(" & CStr(dataNo) & "," & CStr(i) & ")=" & CStr(dataAry(dataNo, i))) | |
End If | |
End Sub | |
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click | |
SerialPort1.PortName = TextBox1.Text 'オープンするポート名を格納 | |
SerialPort1.Open() 'ポートオープン | |
Label2.Text = "OPENED" | |
CheckBox9.Checked = True | |
End Sub | |
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click | |
Dim k As Integer | |
If System.IO.File.Exists(fname) Then | |
file.Close() | |
Label7.Text = "FileClosed" | |
fname = "" | |
TextBox21.Text = fname | |
End If | |
If SerialPort1.IsOpen = True Then 'ポートオープン済み | |
SerialPort1.Close() 'ポートクローズ | |
Label2.Text = "CLOSED" | |
End If | |
End Sub | |
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived | |
Dim ReceivedData As String = " " '受信データ用変数を宣言します | |
If CheckBox9.Checked = True Then | |
Try | |
ReceivedData = SerialPort1.ReadLine 'データを受信します | |
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 | |
'===============Sampling Start======================= | |
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click | |
If startFlag = 0 Then | |
startFlag = 1 | |
End If | |
End Sub | |
'===============Sampling STOp=================================== | |
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click | |
If startFlag = 1 Then | |
startFlag = 0 | |
End If | |
End Sub | |
'================================メソッドPlotc()=================================================== | |
'===========-PLOT パラメータの定義 計算方式=================================================== | |
'===========ゼロレベルでデフォルト平均値(1650mV)をとってCenteringを実施してY軸中心にそろえる=============== | |
'===========負荷をいれながらrate値(ドット/mV)を手動で変えて最適値にセット======================== | |
'========================================================================================== | |
Sub plotC(ByVal dataNo As Integer, ByVal value As Integer, ByVal value_1 As Integer, ByVal colorN As Integer) | |
If PictureBox1.Image Is Nothing Then '初回だけBITMAPを定義する Picture1.imageという名称をつかうこと | |
PictureBox1.Image = New Bitmap(600, 240) | |
End If | |
Dim g As Graphics = Graphics.FromImage(PictureBox1.Image) | |
Dim Ch_sel(7) As Integer | |
Ch_sel = CheckBR() 'CheckBox Checked array 1=ON 0=OFF | |
'==============Text Box Value Reading=================================== | |
Dim rate(7) As Double | |
Dim midvalue(7) As Double | |
rate = RateCR() ' rate(0-6)はdot/mV | |
midvalue = AvTR() 'midvalue(0-6)はゼロレベル値 | |
'==============TrackBar value Read============== | |
Dim TBvalue As Integer | |
Dim TBposition As Integer | |
TBvalue = TrackBar1.Value | |
TBposition = CInt(TBvalue / 100 * yh) | |
TextBox20.Text = CStr(TBvalue) | |
'=======Pen COLORS================ | |
'Dim b As Brush | |
Dim p1, p2, p3, p4, p5, p6 As New Pen(Color.Black) | |
'b = Brushes.Black | |
p1.Width = 0.1 | |
p2.Width = 0.1 | |
p3.Width = 0.1 | |
p4.Width = 0.1 | |
p5.Width = 0.1 | |
p6.Width = 0.1 | |
p1 = Pens.Red | |
p2 = Pens.Blue | |
p3 = Pens.Green | |
p4 = Pens.Magenta | |
p5 = Pens.Orange | |
p6 = Pens.Black | |
'=============PLOT パラメータ準備============== | |
Dim xscale As Integer = 2 | |
'--Y軸 | |
'-------------ドット変換値設定------- | |
dstep = 1 'X軸基本 | |
Mag = CDbl(ComboBox8.SelectedItem) 'X軸倍率 0.01-0.5 1-10 dot/dataNo | |
'===================スクロール クリア&時間測定======================================== | |
Debug.Print("dataNo=" & CStr(dataNo) & "cstr(600/Mag)=" & CStr(600 / Mag)) | |
If dataNo Mod CInt(600 / Mag) = 0 Then '1画面終了したらimageクリア | |
tp = sw.Elapsed | |
totalsec = tp.TotalSeconds | |
' Debug.Print("tp.sec=" & totalsec) | |
sw.Stop() | |
If totalsec > 0.6 Then | |
TextBox11.Text = CStr(totalsec) | |
End If | |
sw.Reset() | |
sw.Start() | |
Debug.Print("MOD 300:dataNo=" & CStr(dataNo)) | |
SerialPort1.DiscardInBuffer() | |
PictureBox1.Image = Nothing '1スクロール毎に画面クリア | |
'====================画面PLOT============================================== | |
Else | |
'Debug.Print("dataNo=" & CStr(dataNo) & "value=" & CStr(value) & "midvalue=" & CStr(midvalue(0)) & "px=" & CStr(px) & "py=" & CStr(py)) | |
'******************Plot Unit 1ch****************************** | |
If Ch_sel(0) = 1 Then | |
px = Int((dstep * dataNo Mod CInt(600 / Mag)) * Mag) | |
px_1 = Int((dstep * (dataNo - 1) Mod CInt(600 / Mag)) * Mag) | |
py = yh - (Int(rate(0) * (dataAry(dataNo, 0) - midvalue(0))) + TBposition) | |
'Debug.Print("------1ch_py:dataAry=" & CStr(dataAry(dataNo, 0)) & "midvalue=" & CStr(midvalue(0))) | |
py_1 = yh - (Int(rate(0) * (dataAry(dataNo - 1, 0) - midvalue(0))) + TBposition) | |
'Debug.Print("1ch_py_1:dataAry=" & CStr(dataAry(dataNo, 0)) & "midvalue=" & CStr(midvalue(0))) | |
g.DrawLine(p1, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
'Debug.Print("------1ch:px_1=" & CStr(px_1) & "px=" & CStr(px) & "py_1=" & CStr(py_1) & "py=" & CStr(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit2ch****************************** | |
If Ch_sel(1) = 1 Then | |
px = Int((dstep * dataNo Mod CInt(600 / Mag)) * Mag) | |
px_1 = Int((dstep * (dataNo - 1) Mod CInt(600 / Mag)) * Mag) | |
py = yh - (Int(rate(1) * (dataAry(dataNo, 1) - midvalue(1))) + TBposition) | |
'Debug.Print("=======2ch_py:dataAry=" & CStr(dataAry(dataNo, 0)) & "midvalue=" & CStr(midvalue(1))) | |
py_1 = yh - (Int(rate(1) * (dataAry(dataNo - 1, 1) - midvalue(1))) + TBposition) | |
'Debug.Print("2ch_py_1:dataAry=" & CStr(dataAry(dataNo, 0)) & "midvalue=" & CStr(midvalue(1))) | |
g.DrawLine(p2, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
'Debug.Print("=====2ch:px_1=" & CStr(px_1) & "px=" & CStr(px) & "py_1=" & CStr(py_1) & "py=" & CStr(py)) | |
End If | |
End If | |
'********************************************************** | |
'******************Plot Unit3ch****************************** | |
If Ch_sel(2) = 1 Then | |
px = Int((dstep * dataNo Mod CInt(600 / Mag)) * Mag) | |
px_1 = Int((dstep * (dataNo - 1) Mod CInt(600 / Mag)) * Mag) | |
py = yh - (Int(rate(2) * (dataAry(dataNo, 2) - midvalue(2))) + TBposition) | |
py_1 = yh - (Int(rate(2) * (dataAry(dataNo - 1, 2) - midvalue(2))) + TBposition) | |
g.DrawLine(p3, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit4ch****************************** | |
If Ch_sel(3) = 1 Then | |
px = Int((dstep * dataNo Mod CInt(600 / Mag)) * Mag) | |
px_1 = Int((dstep * (dataNo - 1) Mod CInt(600 / Mag)) * Mag) | |
py = yh - (Int(rate(3) * (dataAry(dataNo, 3) - midvalue(3))) + TBposition) | |
py_1 = yh - (Int(rate(3) * (dataAry(dataNo - 1, 3) - midvalue(3))) + TBposition) | |
g.DrawLine(p4, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit5ch****************************** | |
If Ch_sel(4) = 1 Then | |
px = Int((dstep * dataNo Mod CInt(600 / Mag)) * Mag) | |
px_1 = Int((dstep * (dataNo - 1) Mod CInt(600 / Mag)) * Mag) | |
py = yh - (Int(rate(4) * (dataAry(dataNo, 4) - midvalue(4))) + TBposition) | |
py_1 = yh - (Int(rate(4) * (dataAry(dataNo - 1, 4) - midvalue(4))) + TBposition) | |
g.DrawLine(p5, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit6ch****************************** | |
If Ch_sel(4) = 1 Then | |
px = Int((dstep * dataNo Mod CInt(600 / Mag)) * Mag) | |
px_1 = Int((dstep * (dataNo - 1) Mod CInt(600 / Mag)) * Mag) | |
py = yh - (Int(rate(5) * (dataAry(dataNo, 5) - midvalue(5))) + TBposition) | |
py_1 = yh - (Int(rate(5) * (dataAry(dataNo - 1, 5) - midvalue(5))) + TBposition) | |
g.DrawLine(p6, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'Debug.Print("px_1=" & CStr(px_1) & "px=" & CStr(px) & "py_1=" & CStr(py_1) & "py=1" & CStr(py)) | |
'g.FillEllipse(b, px, py, 3, 3) ' 点プロット | |
g.Dispose() | |
'b.Dispose() | |
PictureBox1.Invalidate() | |
End Sub | |
'===================================================================================================================== | |
'===================================================================================================================== | |
'===================================================================================================================== | |
'======================================================================================== | |
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load | |
'*********************Object Array set**************************************************************************** | |
Dim dataTextBox() As TextBox | |
dataTextBox = {Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10} | |
Dim adjustComboBox() As ComboBox | |
adjustComboBox = {Me.ComboBox1, Me.ComboBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox5, Me.ComboBox6, Me.ComboBox7} | |
Dim midTextBox() As TextBox | |
midTextBox = {Me.TextBox13, Me.TextBox14, Me.TextBox15, Me.TextBox16, Me.TextBox17, Me.TextBox18, Me.TextBox19} | |
'****************************************************************************************************************** | |
'Dim arry() As Integer = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100} | |
'================COMBOBOX Def============================= | |
ComboBox1.Items.Clear() | |
Dim n As Integer | |
For i = 0 To 6 | |
adjustComboBox(i).Items.Add("0.1") '0.1mv/yh_DOT | |
adjustComboBox(i).Items.Add("0.2") | |
adjustComboBox(i).Items.Add("0.5") | |
adjustComboBox(i).Items.Add("1") '1mv?yh?DOT | |
adjustComboBox(i).Items.Add("2") | |
adjustComboBox(i).Items.Add("5") | |
adjustComboBox(i).Items.Add("10") '10mV/yh_DOT | |
adjustComboBox(i).Items.Add("20") | |
adjustComboBox(i).Items.Add("50") '50mV?yh_DOT | |
'adjustComboBox(i).Items.Add("90") | |
'adjustComboBox(i).Items.Add("100") | |
Next | |
ComboBox1.SelectedIndex = 3 | |
ComboBox2.SelectedIndex = 3 | |
ComboBox3.SelectedIndex = 3 | |
ComboBox4.SelectedIndex = 3 | |
ComboBox5.SelectedIndex = 3 | |
ComboBox6.SelectedIndex = 3 | |
'ComboBox7.SelectedIndex = 1 | |
'==============Series Position TEXTBOX=========================== | |
TextBox13.Text = CStr(1550) | |
TextBox14.Text = CStr(1550) | |
TextBox15.Text = CStr(1550) | |
TextBox16.Text = CStr(1550) | |
TextBox17.Text = CStr(1550) | |
TextBox18.Text = CStr(1550) | |
TextBox19.Text = CStr(1550) | |
'============================CheckBox On================================- | |
CheckBox1.Checked = True | |
CheckBox2.Checked = True | |
CheckBox3.Checked = True | |
CheckBox4.Checked = True | |
CheckBox5.Checked = True | |
CheckBox6.Checked = True | |
'==================COMBOBOX8 X_Mag scale================================= | |
'===============1,2,3,4,5,6,10,12================================== | |
ComboBox8.Items.Add("0.01") | |
ComboBox8.Items.Add("0.1") | |
ComboBox8.Items.Add("0.2") | |
ComboBox8.Items.Add("0.5") | |
ComboBox8.Items.Add("1") | |
ComboBox8.Items.Add("2") | |
ComboBox8.Items.Add("3") | |
ComboBox8.Items.Add("4") | |
ComboBox8.Items.Add("5") | |
ComboBox8.Items.Add("6") | |
ComboBox8.Items.Add("10") | |
ComboBox8.Items.Add("12") | |
ComboBox8.SelectedIndex = 5 | |
'===================TrackBar read======================== | |
Dim TBvalue As Integer | |
TBvalue = TrackBar1.Value | |
TextBox20.Text = CStr(TBvalue) | |
'===========Receive check============== | |
CheckBox9.Checked = True | |
Button2.Enabled = False | |
End Sub | |
'======================================================================== | |
'================Average Graph mid Data================================== | |
'======================================================================== | |
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click | |
Dim endnum As Integer | |
Dim startnum As Integer | |
Dim midave(7) As Double | |
endnum = CInt(TextBox2.Text) | |
startnum = endnum - 100 | |
midave = dave(dataAry, startnum, endnum, 6) | |
Debug.Print("AveButtn:" & CStr(startnum) & "," & CStr(endnum) & "," & CStr(midave(0))) | |
TextBox13.Text = midave(0) | |
TextBox14.Text = midave(1) | |
TextBox15.Text = midave(2) | |
TextBox16.Text = midave(3) | |
TextBox17.Text = midave(4) | |
TextBox18.Text = midave(5) | |
End Sub | |
'==========================PLOTTING Parameter Check =============================================== | |
'===================dataAry(,)=mV rate()=dot/mv=1/adjutvalue()(=mV/dot)============================================ | |
'=================== plot: py=(dataAry(,)-midvalue())*rate()+midvalue()============================================== | |
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click | |
Dim m, n As Integer | |
Dim px, py As Integer | |
Dim dn, ds, de As Integer | |
ReDim rate(8) | |
ReDim midvalue(8) | |
'For m = 0 To 6 | |
' rate(m) = 1 / CInt(adjustComboBox(m).Text) | |
' midvalue(m) = CDbl(midTextBox(m).Text) | |
'Next | |
dn = CInt(TextBox2.Text) '現在データNo | |
ds = CInt(dn / 600) * 600 '左始点データスタートNO | |
de = dn Mod 600 '現在座標 | |
Debug.Print("dn=" & CStr(dn) & "ds=" & CStr(ds) & "de=" & CStr(de)) | |
For n = 0 To 5 | |
For m = 0 To de | |
px = m | |
py = CInt((CDbl(dataAry(ds + m, n)) - midvalue(n)) * rate(n) / 100 + yh / 2) | |
'Debug.Print("m=" & CStr(m) & "n=" & CStr(n) & "dataAry=" & CStr(dataAry(ds + m, n)) & "midvalue=" & CStr(midvalue(n)) & "sa=" & CStr((CDbl(dataAry(ds + m, n)) - midvalue(n))) & "rate=" & rate(n) & "Plotting:px=" & CStr(px) & "py=" & CStr(py)) | |
'Debug.Print("Plotting:px=" & CStr(px) & "py=" & CStr(py)) | |
Next | |
Next | |
End Sub | |
'******************************************************************************************************************** | |
'*********************************FORM Reading Functions************************************************************* | |
'******************************************************************************************************************* | |
Private Function AvTR() As Double() | |
Dim ave(7) As Double | |
ave(0) = CDbl(TextBox13.Text) | |
ave(1) = CDbl(TextBox14.Text) | |
ave(2) = CDbl(TextBox15.Text) | |
ave(3) = CDbl(TextBox16.Text) | |
ave(4) = CDbl(TextBox17.Text) | |
ave(5) = CDbl(TextBox18.Text) | |
ave(6) = CDbl(TextBox19.Text) | |
Return ave | |
End Function | |
Private Function RateCR() As Double() | |
Dim rate(7) As Double | |
rate(0) = CDbl(ComboBox1.SelectedItem) 'mv/dot | |
rate(1) = CDbl(ComboBox2.SelectedItem) | |
rate(2) = CDbl(ComboBox3.SelectedItem) | |
rate(3) = CDbl(ComboBox4.SelectedItem) | |
rate(4) = CDbl(ComboBox5.SelectedItem) | |
rate(5) = CDbl(ComboBox6.SelectedItem) | |
rate(6) = CDbl(ComboBox7.SelectedItem) | |
Return rate | |
End Function | |
Private Function CheckBR() As Integer() | |
Dim selCh() As Integer = {0, 0, 0, 0, 0, 0, 0} | |
If CheckBox1.Checked = True Then | |
selCh(0) = 1 | |
End If | |
If CheckBox2.Checked = True Then | |
selCh(1) = 1 | |
End If | |
If CheckBox3.Checked = True Then | |
selCh(2) = 1 | |
End If | |
If CheckBox4.Checked = True Then | |
selCh(3) = 1 | |
End If | |
If CheckBox5.Checked = True Then | |
selCh(4) = 1 | |
End If | |
If CheckBox6.Checked = True Then | |
selCh(5) = 1 | |
End If | |
If CheckBox7.Checked = True Then | |
selCh(6) = 1 | |
End If | |
Return selCh | |
End Function | |
'******************************************************************************************************************* | |
'******************************************************************************************************************* | |
'******************************************************************************************************************* | |
'================================================================================================================== | |
'==================================Static Calculation=========================================================== | |
'==========================Ave() MovingAve() ============================================================ | |
'================================================================================================================== | |
'================================================================================================================== | |
Function dave(ByRef dA(,) As Long, ByVal startN As Integer, ByVal endN As Integer, ByVal ch As Integer) As Double() | |
Dim chN As Integer | |
Dim dataN As Integer | |
Dim dsum As Double | |
Dim avech() As Double | |
ReDim avech(ch) | |
For chN = 0 To ch - 1 'chは1-6chで与えられるがデータindexは0-5 | |
For dataN = startN To endN 'startNからendNまでendN-startN+1 個の総和をとって平均 | |
dsum += dA(dataN, chN) | |
Next | |
avech(chN) = dsum / (endN - startN + 1) | |
dsum = 0 | |
Next | |
Return avech | |
End Function | |
Function MovAve(ByRef dA(,) As Long, ByVal colN As Integer, ByVal MA As Integer, ByVal rowN As Integer) As Double() | |
Dim i, j As Integer | |
Dim dataSum() As Long | |
Dim dSum As Long | |
Dim dataA() As Double '= {0, 0, 0, 0, 0, 0, 0} | |
'Debug.Print("====colN=" & CStr(colN) & "MA=" & CStr(MA) & "rowN=" & CStr(rowN)) | |
ReDim dataSum(colN + 1) | |
ReDim dataA(colN + 1) | |
For j = 0 To colN - 1 | |
dSum = 0 | |
For i = rowN - MA To rowN | |
dSum = dSum + dA(i, j) | |
'Debug.Print("dA(" & CStr(i) & "," & CStr(j) & ")=" & CStr(dA(i, j)) & CStr(dataSum(j))) | |
Next | |
dataA(j) = CDbl(dSum / MA) | |
Next | |
MovAve = dataA | |
End Function | |
Sub AutoFileLog() | |
End Sub | |
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.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 = fname | |
sfd.Filter = "TXTファイル|*.txt|CSVファイル|*.csv|すべてのファイル|*.*" | |
sfd.InitialDirectory = "C:\vb_LOG " | |
sfd.FilterIndex = 2 | |
sfd.Title = "保存先のファイルを選択してください" | |
If sfd.ShowDialog() = DialogResult.OK Then | |
'OKボタンがクリックされたとき、選択されたファイル名を表示する | |
Console.WriteLine(sfd.FileName) | |
TextBox21.Text = sfd.FileName | |
End If | |
''==================================================== | |
''SaveFileDialogクラスのインスタンスを作成 | |
'Dim sfd As New SaveFileDialog() | |
''はじめのファイル名を指定する | |
''はじめに「ファイル名」で表示される文字列を指定する | |
'sfd.FileName = "新しいファイル.html" | |
''はじめに表示されるフォルダを指定する | |
''指定しない(空の文字列)の時は、現在のディレクトリが表示される | |
'sfd.InitialDirectory = "C:\" | |
''[ファイルの種類]に表示される選択肢を指定する | |
'sfd.Filter = "HTMLファイル(*.html;*.htm)|*.html;*.htm|すべてのファイル(*.*)|*.*" | |
''[ファイルの種類]ではじめに選択されるものを指定する | |
''2番目の「すべてのファイル」が選択されているようにする | |
'sfd.FilterIndex = 2 | |
''タイトルを設定する | |
'sfd.Title = "保存先のファイルを選択してください" | |
''ダイアログボックスを閉じる前に現在のディレクトリを復元するようにする | |
'sfd.RestoreDirectory = True | |
''既に存在するファイル名を指定したとき警告する | |
''デフォルトでTrueなので指定する必要はない | |
'sfd.OverwritePrompt = True | |
''存在しないパスが指定されたとき警告を表示する | |
''デフォルトでTrueなので指定する必要はない | |
'sfd.CheckPathExists = True | |
''ダイアログを表示する | |
'If sfd.ShowDialog() = DialogResult.OK Then | |
' 'OKボタンがクリックされたとき、選択されたファイル名を表示する | |
' Console.WriteLine(sfd.FileName) | |
'End If | |
End Sub | |
Private Sub TrackBar1_MouseDown(sender As Object, e As MouseEventArgs) Handles TrackBar1.MouseDown | |
Debug.Print("Mouse Downed") | |
End Sub | |
'============ Auto File save CheckBox8==================================== | |
Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox8.CheckedChanged | |
If CheckBox8.Checked = False Then | |
fname = "" | |
TextBox21.Text = "" | |
'If System.IO.File.Exists(fname) Then | |
file.Close() | |
Label7.Text = "FileClosed" | |
' End If | |
End If | |
End Sub | |
'=========Receiving CheckBox=============================== | |
Private Sub CheckBox9_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox9.CheckedChanged | |
If CheckBox9.Checked = False Then | |
Button2.Enabled = True | |
Else | |
Button2.Enabled = False | |
End If | |
End Sub | |
Private Sub Label10_Click(sender As Object, e As EventArgs) Handles Label10.Click | |
End Sub | |
End Class | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment