Created
October 18, 2020 14:22
-
-
Save dj1711572002/86c009a75c775ce159a7d3b067ae6d05 to your computer and use it in GitHub Desktop.
VB.NET Serial_Graphic_Monitor 2ports 16CH RealtimeGraph
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 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 ReceivedData1 As String = " " '受信データ用変数を宣言します | |
Dim ReceivedData2 As String = " " '受信データ用変数を宣言します | |
Dim ReceivedData3 As String = " " | |
Dim header As String | |
Dim rdata1 As String = "" | |
Dim rdata2 As String = "" | |
Dim rdata3 As String = "" | |
Dim Aflag As Integer = 0 | |
Dim Bflag As Integer = 0 | |
Dim sdnum As Integer | |
Dim dcount As Integer = 0 | |
Dim dummy As String | |
Private com1_None As Integer | |
Private com2_None As Integer | |
'=========Moving Average ====================== | |
Private MA As Integer | |
Private sCH(16) As Integer | |
Private dataSum(16) As Double | |
Private dataA(16) As Double | |
Private dSum As Double | |
Private iniFlag As Integer = 1 '初回のみ指定 | |
'==========LinearMode Parameteres============== | |
Public fStr1, fStr2 As String | |
Public rate(16) As Double | |
Public midvalue(16) As Double | |
Public x1ch, y1ch, x2ch, y2ch, x3ch, y3ch As Integer | |
Public pushMode As Integer = 0 | |
Public pushMode_1 As Integer = 0 | |
Public averaging As Integer = 0 | |
Public pushN As Integer = 0 | |
Public pushN_1 As Integer = 0 | |
Public aveStat As Integer = 0 | |
Public aveNcount As Integer = 0 | |
Public avecount As Integer = 0 | |
Public aveData1X(10000) As Double 'pushModeで得た平均値プロットデータ | |
Public aveData1Y(10000) As Double 'pushModeで得た平均値プロットデータ | |
Public aveData2X(10000) As Double 'pushModeで得た平均値プロットデータ | |
Public aveData2Y(10000) As Double 'pushModeで得た平均値プロットデータ | |
Public aveData3X(10000) As Double 'pushModeで得た平均値プロットデータ | |
Public aveData3Y(10000) As Double 'pushModeで得た平均値プロットデータ | |
Public aveN As Integer | |
Public sum1X As Double = 0 | |
Public sum1Y As Double = 0 | |
Public sum2X As Double = 0 | |
Public sum2Y As Double = 0 | |
Public sum3X As Double = 0 | |
Public sum3Y As Double = 0 | |
Public cp1X As Integer(,) | |
Public cp1Y As Integer(,) | |
Public cp2X As Integer(,) | |
Public cp2Y As Integer(,) | |
Public cp3X As Integer(,) | |
Public cp3Y As Integer(,) | |
'===========Controls ============== | |
Dim Ch_sel(16) As Integer | |
Dim shokaiN As Integer | |
Dim Chsuu As Integer | |
'=========Receive Stop=========== | |
Public rFlag As Integer = 1 | |
Public rcFlag As Integer = 0 | |
'=======file=============== | |
Public f1open As Integer = 0 | |
Public fname As String = "" | |
Public fname1 As String = "" | |
Public file As System.IO.StreamWriter | |
Public file1 As System.IO.StreamWriter | |
Public fsdata As String | |
Public fsdata1 As String | |
Public pushStr, pushStr1, pushStr2, pushStr3 As String | |
'======PictureBoxSize======== | |
Const yh = 240 | |
Const xw = 600 | |
Private onetime As Integer = 1 | |
Delegate Sub DataDelegate(ByVal sdata As String) | |
'=========Available Parameters in thie Class================= | |
Private dStr(100) As String | |
Private dataAry(60000, 16) As Double | |
Private dataNo As Long | |
Dim stm As Integer = 0 | |
'---------Plotting parameters-------------- | |
'Private rate As Double() | |
Private Mag 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 sw1 As New System.Diagnostics.Stopwatch() | |
Private tp As TimeSpan | |
Private tr 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座標 | |
'=============================================================== | |
'Least Square Method Function Parameters | |
'=============================================================== | |
Private num(3) As Integer | |
Private sumX(3) As Double | |
Private sumY(3) As Double | |
Private sumX2(3) As Double | |
Private sumY2(3) As Double | |
Private sumXY(3) As Double | |
Private aveX As Double = 0 | |
Private aveY As Double = 0 | |
Private devX As Double = 0 | |
Private devY As Double = 0 | |
Private devXY As Double = 0 | |
Private stdevX As Double = 0 | |
Private stdevY As Double = 0 | |
Private n, n_1 As Integer | |
Private result(4, 3) As Double ' 0:correl 1:slope 2:intercept 3:setN ,setN=1,2,3waku | |
'===================================================================== | |
' Setting Save & Read parameters | |
'===================================================================== | |
Public fname2 As String = "" | |
Public file2 As System.IO.StreamWriter | |
Public fname3 As String = "" | |
Public file3 As System.IO.StreamWriter | |
Private cIndex As Integer | |
Private textboxdata As String | |
Private checkboxdata As String | |
Private comboboxdata As String | |
Private readata(1000) As String | |
'=============================================================================== | |
'=========================LSM Function========================================== | |
'================================================================================ | |
Private Function LSM(ByVal x As Double, ByVal y As Double, ByVal setN As Integer) As Double() | |
Dim a(8) As Double 'correl,slope,intercept,n,aveX,aveY,stdevX,stcevY | |
Dim slope As Double | |
Dim correl As Double | |
Dim intercept As Double | |
num(setN) = num(setN) + 1 | |
sumX(setN) += x | |
sumY(setN) += y | |
aveX = sumX(setN) / num(setN) | |
aveY = sumY(setN) / num(setN) | |
sumX2(setN) += (x - aveX) ^ 2 | |
sumY2(setN) += (y - aveY) ^ 2 | |
sumXY(setN) += (x - aveX) * (y - aveY) | |
devX = sumX2(setN) / num(setN) | |
devY = sumY2(setN) / num(setN) | |
devXY = sumXY(setN) / num(setN) | |
stdevX = Math.Sqrt(devX) | |
stdevY = Math.Sqrt(devY) | |
slope = devXY / devX | |
correl = devXY / (stdevX * stdevY) | |
intercept = aveY - slope * aveX | |
a(0) = correl | |
a(1) = slope | |
a(2) = intercept | |
a(3) = num(setN) | |
a(4) = aveX | |
a(5) = aveY | |
a(6) = stdevX | |
a(7) = stdevY | |
Return a | |
End Function | |
Private Sub LSMinit() | |
Array.Clear(sumX, 0, sumX.Length) | |
Array.Clear(sumY, 0, sumY.Length) | |
Array.Clear(sumXY, 0, sumXY.Length) | |
Array.Clear(sumX2, 0, sumX2.Length) | |
Array.Clear(sumY2, 0, sumY2.Length) | |
Array.Clear(num, 0, num.Length) | |
n = 0 | |
avecount = 0 | |
End Sub | |
'===============================MAIN=========================================================================================================================== | |
'=============================PRINT DATA======================================================================================================================= | |
'============================================================================================================================================================== | |
Private Sub PrintData(ByVal sdata As String) | |
''*********************Object Array set**************************************************************************** | |
Dim CH_checkbox() As CheckBox | |
CH_checkbox = {Me.CheckBox1, Me.CheckBox2, Me.CheckBox3, Me.CheckBox4, Me.CheckBox5, Me.CheckBox6, Me.CheckBox7, Me.CheckBox13, Me.CheckBox14, Me.CheckBox15, Me.CheckBox16, Me.CheckBox17, Me.CheckBox18, Me.CheckBox19, Me.CheckBox20, Me.CheckBox21} | |
Dim dataTextBox() As TextBox | |
dataTextBox = {Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10, Me.TextBox29, Me.TextBox31, Me.TextBox33, Me.TextBox35, Me.TextBox37, Me.TextBox39, Me.TextBox41, Me.TextBox43, Me.TextBox45} | |
Dim adjustComboBox() As ComboBox | |
adjustComboBox = {Me.ComboBox1, Me.ComboBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox5, Me.ComboBox6, Me.ComboBox7, Me.ComboBox12, Me.ComboBox13, Me.ComboBox14, Me.ComboBox15, Me.ComboBox16, Me.ComboBox17, Me.ComboBox18, Me.ComboBox19, Me.ComboBox20} | |
Dim midTextBox() As TextBox | |
midTextBox = {Me.TextBox13, Me.TextBox14, Me.TextBox15, Me.TextBox16, Me.TextBox17, Me.TextBox18, Me.TextBox19, Me.TextBox28, Me.TextBox30, Me.TextBox32, Me.TextBox34, Me.TextBox36, Me.TextBox38, Me.TextBox40, Me.TextBox42, Me.TextBox44} | |
'****************************************************************************************************************** | |
'===Start StopWatch=============== | |
If dcount = 0 Then | |
sw1.Start() | |
End If | |
dcount += 1 | |
'Debug.Print(dcount) | |
If dcount Mod 50 = 0 Then | |
'========Recived data Period Measurement=========== | |
sw1.Stop() | |
stm = sw1.ElapsedMilliseconds | |
sw1.Start() | |
TextBox46.Text = dcount | |
TextBox47.Text = stm | |
'CheckBox11.Checked = False | |
ListBox1.Items.Add("time=" + CStr(stm)) | |
End If | |
'========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 | |
' Debug.Print("sdata=" & sdata) | |
'=======sdata File writing==================== | |
If System.IO.File.Exists(fname) And CheckBox8.Checked = True Then | |
fsdata = sdata.Substring(0, sdata.Length - 2) + Chr(13) + Chr(10) | |
'fsdata = sdata.Substring(0, sdata.Length - 2) + ",80data_time=" + CStr(stm) + Chr(13) + Chr(10) | |
file.Write(fsdata) | |
Label7.Text = "Logging" | |
End If | |
''=====Port1 A, +Port2 B,合体============================== | |
If CheckBox22.Checked = True Then | |
header = sdata.Substring(0, 3) | |
pushMode_1 = pushMode | |
If header = "B,2" Then | |
pushMode = 1 | |
If pushMode = 1 Then | |
Label28.Visible = True | |
Else | |
Label28.Visible = False | |
End If | |
' Debug.Print("B2:pushMode=" + CStr(pushMode)) | |
End If | |
If header = "B,1" Then | |
pushMode = 0 | |
If pushMode = 0 Then | |
Label28.Visible = False | |
End If | |
' Debug.Print("B1:pushMode=" + CStr(pushMode)) | |
End If | |
'Debug.Print(header) | |
sdnum = sdata.Length | |
'Debug.Print(sdnum) | |
If header = "A,1" And sdnum > 5 Then | |
rdata1 = sdata.Substring(2, sdnum - 2) | |
Aflag = 1 | |
'Debug.Print("rdata1=") | |
'Debug.Print(rdata1) | |
End If | |
If (header = "B,1" Or header = "B,2") And sdnum > 5 Then | |
rdata2 = sdata.Substring(2, sdnum - 2) | |
Bflag = 1 | |
'Debug.Print("rdata2=") | |
'Debug.Print(rdata2) | |
'Debug.Print("--------------") | |
End If | |
If Aflag = 1 And Bflag = 1 Then | |
rdata3 = rdata1 + "," + rdata2 | |
'Debug.Print("rdata3=") | |
'Debug.Print(rdata3) | |
'TextBox48.Text = rdata3 | |
End If | |
If Aflag = 1 And Bflag = 0 Then | |
rdata3 = rdata1 | |
'Debug.Print("rdata3=") | |
'Debug.Print(rdata3) | |
'TextBox48.Text = rdata3 | |
End If | |
If Aflag = 0 And Bflag = 0 Then | |
rdata3 = rdata2 | |
'Debug.Print("rdata3=") | |
'Debug.Print(rdata3) | |
'TextBox48.Text = rdata3 | |
End If | |
End If | |
'================================================================= | |
'=============ListBox===================== | |
If CheckBox11.Checked = True And CheckBox22.Checked = False Then | |
ListBox1.Visible = True | |
ListBox1.Items.Add(sdata) | |
End If | |
If CheckBox11.Checked = True And CheckBox22.Checked = True Then | |
ListBox1.Visible = True | |
ListBox1.Items.Add(rdata3) | |
End If | |
If CheckBox11.Checked = False Then | |
ListBox1.Visible = False | |
End If | |
'======================================= | |
Dim delimiter As String = "," | |
Dim i, j, k As Integer | |
'Dim stdata As String | |
Dim dStrAry(100) As String | |
'============================SPLITTING============================ | |
'================================================================== | |
If rdata3.Length > 6 And CheckBox12.Checked = True Then | |
dStr = Split(rdata3, delimiter, -1, CompareMethod.Text) | |
Chsuu = dStr.Length | |
TextBox3.Text = Chsuu | |
End If | |
'---------------------------------dStr to dataAry-------------------------------------------------------------------------- | |
'Debug.Print("dStr.length=" & CStr(dStr.Length) & "sdata.Length=" & CStr(sdata.Length)) | |
If sdata.Length < 90 And sdata.Length > 6 And dStr.Length > 1 And CheckBox12.Checked Then 'dStr.Length = 7 And sdata.Length < 37 | |
Try | |
dataNo = (dataNo + 1) Mod 3000 | |
TextBox2.Text = dataNo | |
'Debug.Print("SPLITed TextBox Printing") | |
For i = 0 To dStr.Length - 1 | |
If dStr(i) <> "" Then | |
TextBox1.Text = dStr(i) | |
dataAry(dataNo, i) = CDbl(dStr(i)) | |
End If | |
Next | |
If startFlag = 1 Then | |
'=================PLOT SUBへ================= | |
plotC(dataNo, 0, 0, 0) 'plotC(x,y,colorN) | |
'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 | |
'Debug.Print("dataAry(" & CStr(dataNo) & "," & CStr(i) & ")=" & CStr(dataAry(dataNo, i))) | |
Catch ex As Exception | |
Console.WriteLine(ex.Message) | |
Console.WriteLine("Error in dstr=>dataAry") | |
End Try | |
End If | |
'End If | |
End Sub | |
'==========================================MAIN BOTTOM======================================================================================================== | |
'============================================================================================================================================================= | |
'============================================================================================================================================================= | |
'*************************SerialPort Open Close REceive*************************************************************** | |
'=================================================================================================================== | |
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click | |
SerialPort1.PortName = ComboBox10.SelectedItem 'TextBox1.Text 'オープンするポート名を格納 | |
SerialPort2.PortName = ComboBox11.SelectedItem | |
If SerialPort1.PortName <> "None" Then | |
SerialPort1.Open() 'ポートオープン | |
Label2.Text = "Port1_OPENED" | |
com1_None = 0 | |
SerialPort1.DiscardInBuffer() | |
End If | |
If SerialPort1.PortName = "None" Then | |
com1_None = 1 | |
End If | |
If SerialPort2.PortName <> "None" Then | |
SerialPort2.Open() 'ポートオープン | |
Label22.Text = "Port2_OPENED" | |
com2_None = 0 | |
SerialPort2.DiscardInBuffer() | |
End If | |
If SerialPort2.PortName = "None" Then | |
com2_None = 1 | |
End If | |
'Received CheckBox ON | |
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 = "Port1_CLOSED" | |
End If | |
If SerialPort2.IsOpen = True Then 'ポートオープン済み | |
SerialPort2.Close() 'ポートクローズ | |
Label22.Text = "Port2_CLOSED" | |
End If | |
End Sub | |
Private Sub PrintData1(ByVal sdata As String) | |
ListBox1.Items.Add(sdata) | |
End Sub | |
'*************************************************************************************************************************** | |
'******************************DataReceiving******************************************************************************** | |
'*************************************************************************************************************************** | |
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived | |
If CheckBox9.Checked = True And com1_None = 0 Then | |
Try | |
ReceivedData1 = "A," + SerialPort1.ReadLine 'データを受信します | |
'If SerialPort2.IsOpen = True Then | |
' 'SerialPort2.DiscardInBuffer() | |
' ReceivedData2 = SerialPort2.ReadLine | |
' ReceivedData3 = ReceivedData1 & "," & ReceivedData2 | |
'Else | |
'ReceivedData3 = ReceivedData1 | |
'End If | |
'Invokeメソッドにより実行されるメソッドへのデリゲートの宣言を行い、受信データを表示します | |
Dim adre As New DataDelegate(AddressOf PrintData) | |
Me.Invoke(adre, ReceivedData1) | |
Catch ex As Exception | |
ReceivedData1 = ex.Message '例外処理を行います | |
'Console.WriteLine("Error in DataReceived1") | |
End Try | |
SerialPort1.DiscardInBuffer() | |
End If | |
End Sub | |
Private Sub SerialPort2_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived | |
If CheckBox9.Checked = True And com2_None = 0 Then | |
Try | |
'SerialPort2.DiscardInBuffer() | |
ReceivedData2 = "B," + SerialPort2.ReadLine 'データを受信します | |
Dim adre As New DataDelegate(AddressOf PrintData) | |
Me.Invoke(adre, ReceivedData2) | |
Catch ex As Exception | |
ReceivedData2 = ex.Message '例外処理を行います | |
'Console.WriteLine("Error in DataReceived2") | |
End Try | |
'Invokeメソッドにより実行されるメソッドへのデリゲートの宣言を行い、受信データを表示します | |
SerialPort2.DiscardInBuffer() | |
End If | |
End Sub | |
'***************************************************************************************************************************** | |
'***************************************************************************************************************************** | |
'***************************************************************************************************************************** | |
'================================================================================================================= | |
'===================================SerialPort Setting End================================================================== | |
'================================================================================================================ | |
'===============Plotting Start Button======================= | |
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click | |
If startFlag = 0 Then | |
startFlag = 1 | |
Label20.Text = "--Plotting--" | |
End If | |
End Sub | |
'===============Plotting Stop=================================== | |
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click | |
If startFlag = 1 Then | |
startFlag = 0 | |
Label20.Text = "--PlotStopped--" | |
If f1open = 1 Then | |
file1.Close() | |
RichTextBox1.AppendText("FileClosed") | |
f1open = 0 | |
LSMinit() | |
End If | |
End If | |
End Sub | |
'LSM 計算初期化 | |
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click | |
LSMinit() 'LSM計算初期化 | |
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(720, 240) | |
End If | |
Dim g As Graphics = Graphics.FromImage(PictureBox1.Image) | |
Ch_sel = CheckBR() 'CheckBox Checked array 1=ON 0=OFF | |
'==============Text Box Value Reading=================================== | |
rate = RateCR() ' rate(0-16)はdot/mV | |
midvalue = AvTR() 'midvalue(0-16)はゼロレベル値 | |
'==============TrackBar value Read============== | |
Dim TBvalue As Integer | |
Dim TBposition As Integer | |
TBvalue = TrackBar1.Value | |
TBposition = CInt(TBvalue / 100 * yh) | |
TextBox20.Text = CStr(TBvalue) | |
'********************************************************************************************************** | |
'************************************Moving Average Function CALL****************************************** | |
MA = CInt(ComboBox21.SelectedItem) | |
'Debug.Print("Before MovAve_sCH.Length=" + CStr(sCH.Length)) | |
If dataNo > MA Then | |
If iniFlag = 1 Then '初回に総和を出しておく | |
For j = 0 To Chsuu - 1 | |
For i = 0 To MA - 1 | |
dataSum(j) += dataAry(dataNo - MA + i, j) | |
Next i | |
dataA(j) = dataSum(j) / MA | |
Next j | |
iniFlag = 0 | |
End If 'iniFlag=1 | |
For j = 0 To Chsuu - 1 '総和から古いデータをを引いて、最新データを足す | |
'dataNo=100は1~100までの和、101番目移動平均計算は、1番データを引いて101番目を足す | |
dataSum(j) = dataSum(j) + dataAry(dataNo, j) - dataAry(dataNo - MA, j) | |
dataA(j) = dataSum(j) / MA | |
'Debug.Print("iniFlag0:" + CStr(dataAry(dataNo, sCH(j)) + "," + CStr(dataA(j)))) | |
dataAry(dataNo, j) = dataA(j) '元データへ移動平均値を代入変更 | |
Next j | |
End If 'dataNo>MA | |
'********************************************************************************************************** | |
'********************************************************************************************************** | |
'********************************************************************************************************** | |
'========================================================================= | |
'=================Plot Oresen Graph========================================= | |
'========================================================================= | |
'------------Pen COLORS------------ | |
Dim p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16 As New Pen(Color.Black) | |
Dim p As New Pen(Color.Black) | |
'Dim p(16) As Pen | |
Dim b As Brush | |
Dim bp As Brush | |
b = Brushes.Black | |
p1.Width = 0.1 | |
p2.Width = 0.1 | |
p3.Width = 0.1 | |
p4.Width = 0.1 | |
p5.Width = 0.1 | |
p7.Width = 0.1 | |
p8.Width = 0.1 | |
p9.Width = 0.1 | |
p10.Width = 0.1 | |
p11.Width = 0.1 | |
p12.Width = 0.1 | |
p13.Width = 0.1 | |
p14.Width = 0.1 | |
p15.Width = 0.1 | |
p16.Width = 0.1 | |
p1 = Pens.Red | |
p2 = Pens.Blue | |
p3 = Pens.Green | |
p4 = Pens.Magenta | |
p5 = Pens.Orange | |
p6 = Pens.LemonChiffon | |
p7 = Pens.Lime | |
p8 = Pens.MediumSpringGreen | |
p9 = Pens.DeepPink | |
p10 = Pens.Crimson | |
p11 = Pens.SeaGreen | |
p12 = Pens.GreenYellow | |
p13 = Pens.Orchid | |
p14 = Pens.Maroon | |
p15 = Pens.DarkSlateBlue | |
p16 = Pens.DarkViolet | |
'=============PLOT パラメータ準備============== | |
Dim xscale As Integer = 2 | |
'--Y軸 | |
'-------------ドット変換値設定------- | |
dstep = 1 'X軸基本 | |
Mag = CDbl(ComboBox8.SelectedItem) 'X軸倍率 0.01-0.5 1-10 dot/dataNo | |
'===========================時系列プロットDrawing================================================================= | |
If CheckBox10.Checked = False Then '*********False=Oresen View Mode /True=LenearViewMode | |
'===================スクロール クリア&時間測定======================================== | |
' 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スクロール毎に画面クリア | |
Else | |
'====================折れ線PLOT============================================== | |
'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)) | |
'g.FillEllipse(b, px, py, 5, 5) ' 点プロット この位置で動作OK | |
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 | |
'********************************************************** | |
'******************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(5) = 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 | |
'********************************************************** | |
'******************Plot Unit7ch****************************** | |
If Ch_sel(6) = 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(6) * (dataAry(dataNo, 6) - midvalue(6))) + TBposition) | |
py_1 = yh - (Int(rate(6) * (dataAry(dataNo - 1, 6) - midvalue(6))) + TBposition) | |
g.DrawLine(p7, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit8ch****************************** | |
If Ch_sel(7) = 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(7) * (dataAry(dataNo, 7) - midvalue(7))) + TBposition) | |
py_1 = yh - (Int(rate(7) * (dataAry(dataNo - 1, 7) - midvalue(7))) + TBposition) | |
g.DrawLine(p8, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit9ch****************************** | |
If Ch_sel(8) = 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(8) * (dataAry(dataNo, 8) - midvalue(8))) + TBposition) | |
py_1 = yh - (Int(rate(8) * (dataAry(dataNo - 1, 8) - midvalue(8))) + TBposition) | |
g.DrawLine(p9, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit10ch****************************** | |
If Ch_sel(9) = 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(9) * (dataAry(dataNo, 9) - midvalue(9))) + TBposition) | |
py_1 = yh - (Int(rate(9) * (dataAry(dataNo - 1, 9) - midvalue(9))) + TBposition) | |
g.DrawLine(p10, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit11ch****************************** | |
If Ch_sel(10) = 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(10) * (dataAry(dataNo, 10) - midvalue(10))) + TBposition) | |
py_1 = yh - (Int(rate(10) * (dataAry(dataNo - 1, 10) - midvalue(10))) + TBposition) | |
g.DrawLine(p11, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit12ch****************************** | |
If Ch_sel(11) = 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(11) * (dataAry(dataNo, 11) - midvalue(11))) + TBposition) | |
py_1 = yh - (Int(rate(11) * (dataAry(dataNo - 1, 11) - midvalue(11))) + TBposition) | |
g.DrawLine(p12, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit13ch****************************** | |
If Ch_sel(12) = 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(12) * (dataAry(dataNo, 12) - midvalue(12))) + TBposition) | |
py_1 = yh - (Int(rate(12) * (dataAry(dataNo - 1, 12) - midvalue(12))) + TBposition) | |
g.DrawLine(p13, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit14ch****************************** | |
If Ch_sel(13) = 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(13) * (dataAry(dataNo, 13) - midvalue(13))) + TBposition) | |
py_1 = yh - (Int(rate(13) * (dataAry(dataNo - 1, 13) - midvalue(13))) + TBposition) | |
g.DrawLine(p14, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit15ch****************************** | |
If Ch_sel(14) = 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(14) * (dataAry(dataNo, 14) - midvalue(14))) + TBposition) | |
py_1 = yh - (Int(rate(14) * (dataAry(dataNo - 1, 14) - midvalue(14))) + TBposition) | |
g.DrawLine(p15, CSng(px_1), CSng(py_1), CSng(px), CSng(py)) | |
End If | |
'********************************************************** | |
'******************Plot Unit16ch****************************** | |
If Ch_sel(15) = 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(15) * (dataAry(dataNo, 15) - midvalue(15))) + TBposition) | |
py_1 = yh - (Int(rate(15) * (dataAry(dataNo - 1, 15) - midvalue(15))) + TBposition) | |
g.DrawLine(p16, 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)) | |
End If | |
g.Dispose() | |
'b.Dispose() | |
PictureBox1.Invalidate() | |
End If 'Oresen Graph End | |
'************************************************************************************************************* | |
'*************************Linear View Mode******************************************************************** | |
'***************************720x240*************************************************************************** | |
Dim result1(10) As Double | |
Dim result2(10) As Double | |
Dim result3(10) As Double | |
ReDim cp1X(600000, 16) | |
ReDim cp1Y(600000, 16) | |
ReDim cp2X(600000, 16) | |
ReDim cp2Y(600000, 16) | |
ReDim cp3X(600000, 16) | |
ReDim cp3Y(600000, 16) | |
Dim acp1X, acp1Y, acp2X, acp2Y, acp3X, acp3Y As Integer 'for push Mode plotting | |
b = Brushes.Black | |
If CheckBox10.Checked = True Then 'Linear Mode CheckBox | |
'Debug.Print("Linear Mode In") | |
'----=WAKU--------------------- | |
g.DrawRectangle(Pens.Black, 0, 0, 239, 239) | |
g.DrawRectangle(Pens.Black, 241, 0, 479, 239) | |
g.DrawRectangle(Pens.Black, 480, 0, 719, 239) | |
'-------Ellipse Color---------------- | |
Select Case ComboBox9.SelectedIndex | |
Case 0 | |
b = Brushes.Red | |
Case 1 | |
b = Brushes.Blue | |
Case 2 | |
b = Brushes.Green | |
Case 3 | |
b = Brushes.Magenta | |
Case 4 | |
b = Brushes.Orange | |
Case 5 | |
b = Brushes.Black | |
End Select | |
'If pushMode = 1 Then | |
' b = Brushes.Black | |
'End If | |
'========First CSV File Declaration====================== | |
If f1open = 0 Then | |
fname1 = Format(Now, "yyyyMMdd_HHmmss") | |
fStr1 = ComboBox9.SelectedItem.ToString() | |
fname1 = "C:\vb_LOG\" & fStr1 & fname1 & ".csv" | |
fStr2 = "FileOpen:" + fname1 | |
RichTextBox1.AppendText(fStr2) | |
'---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”) | |
file1 = My.Computer.FileSystem.OpenTextFileWriter(fname1, False, enc) | |
f1open = 1 | |
End If | |
'===============Linear Mode pushMode Averaging===================== | |
If (CheckBox23.Checked = True And pushMode = 1) Then 'pushMode CheckBox ON | |
'Debug.Print("pushMode IN averaging=" + CStr(aveNcount)) | |
x1ch = CInt(TextBox22.Text) - 1 'array indexNo | |
y1ch = CInt(TextBox23.Text) - 1 | |
x2ch = CInt(TextBox24.Text) - 1 'array indexNo | |
y2ch = CInt(TextBox25.Text) - 1 | |
x3ch = CInt(TextBox26.Text) - 1 'array indexNo | |
y3ch = CInt(TextBox27.Text) - 1 | |
sum1X += dataAry(dataNo, x1ch) | |
sum1Y += dataAry(dataNo, y1ch) | |
sum2X += dataAry(dataNo, x2ch) | |
sum2Y += dataAry(dataNo, y2ch) | |
sum3X += dataAry(dataNo, x3ch) | |
sum3Y += dataAry(dataNo, y3ch) | |
averaging = 1 | |
aveNcount += 1 | |
End If | |
'Debug.Print("Push end pushMode_1,pushMode,averaging:" + CStr(pushMode_1) + "," + CStr(pushMode) + "," + CStr(averaging)) | |
If (CheckBox23.Checked = True And (pushMode_1 = 1 And pushMode = 0) And averaging = 1) Then 'pushMode CheckBox ON=>OFF and averaging GO | |
avecount += 1 | |
aveData1X(avecount) = sum1X / aveNcount | |
aveData1Y(avecount) = sum1Y / aveNcount | |
aveData2X(avecount) = sum2X / aveNcount | |
aveData2Y(avecount) = sum2Y / aveNcount | |
aveData3X(avecount) = sum3X / aveNcount | |
aveData3Y(avecount) = sum3Y / aveNcount | |
If CheckBox24.Checked = True Then 'Input Weight Mode | |
aveData1Y(avecount) = CInt(TextBox58.Text) | |
aveData2Y(avecount) = aveData1Y(avecount) | |
aveData3Y(avecount) = aveData1Y(avecount) | |
End If | |
If TextBox22.Text <> "" And TextBox23.Text <> "" Then 'waku1 | |
acp1X = yh - (Int(rate(x1ch) * (aveData1X(avecount) - midvalue(x1ch))) + TBposition) | |
acp1Y = yh - (Int(rate(y1ch) * (aveData1Y(avecount) - midvalue(y1ch))) + TBposition) | |
g.FillEllipse(b, acp1X, acp1Y, 9, 9) ' 点プロット | |
Debug.Print("pushMode_aveData1X,Y=" + CStr(avecount) + "," + CStr(aveData1X(avecount)) + "," + CStr(aveData1Y(avecount))) | |
result1 = LSM(aveData1X(avecount), aveData1Y(avecount), 0) | |
Debug.Print("2Ch-7CH:" + CStr(avecount) + "," + CStr(result1(0)) + "," + CStr(result1(1)) + "," + CStr(result1(2)) + "," + CStr(result1(3)) + "," + CStr(result1(4)) + "," + CStr(result1(5)) + "," + CStr(result1(6)) + "," + CStr(result1(7))) | |
TextBox49.Text = CStr(result1(0)) 'correl | |
TextBox50.Text = CStr(result1(1)) ' slope | |
TextBox55.Text = CStr(result1(2)) ' intercept | |
pushStr1 = "waku1:," + CStr(avecount) + "," + CStr(result1(0)) + "," + CStr(result1(1)) + "," + CStr(result1(2)) + "," + CStr(aveData1X(avecount)) + "," + CStr(aveData1Y(avecount)) + vbCrLf | |
RichTextBox1.AppendText(pushStr1) | |
file1.Write(pushStr1) | |
pushStr1 = "" | |
End If 'waku2 | |
If TextBox24.Text <> "" And TextBox25.Text <> "" Then 'waku2 | |
Dim xoff As Integer = 240 | |
acp2X = yh - (Int(rate(x2ch) * (aveData2X(avecount) - midvalue(x2ch))) + TBposition) + xoff | |
acp2Y = yh - (Int(rate(y2ch) * (aveData2Y(avecount) - midvalue(y2ch))) + TBposition) | |
g.FillEllipse(b, acp2X, acp2Y, 9, 9) ' 点プロット | |
Debug.Print("pushMode_aveData2X,Y=" + CStr(avecount) + "," + CStr(aveData2X(avecount)) + "," + CStr(aveData2Y(avecount))) | |
result2 = LSM(aveData2X(avecount), aveData2Y(avecount), 1) | |
Debug.Print("3Ch-7CH:" + CStr(avecount) + "," + CStr(result2(0)) + "," + CStr(result2(1)) + "," + CStr(result2(2)) + "," + CStr(result2(3)) + "," + CStr(result2(4)) + "," + CStr(result2(5)) + "," + CStr(result2(6)) + "," + CStr(result2(7))) | |
TextBox51.Text = CStr(result2(0)) 'correl | |
TextBox52.Text = CStr(result2(1)) ' slope | |
TextBox56.Text = CStr(result1(2)) ' intercept | |
pushStr2 = "waku2:," + CStr(avecount) + "," + CStr(result2(0)) + "," + CStr(result2(1)) + "," + CStr(result2(2)) + "," + CStr(aveData2X(avecount)) + "," + CStr(aveData2Y(avecount)) + vbCrLf | |
RichTextBox1.AppendText(pushStr2) | |
file1.Write(pushStr2) | |
pushStr2 = "" | |
End If 'waku2 | |
If TextBox26.Text <> "" And TextBox27.Text <> "" Then 'waku3 | |
Dim xoff As Integer = 480 | |
acp3X = yh - (Int(rate(x3ch) * (aveData3X(avecount) - midvalue(x3ch))) + TBposition) + xoff | |
acp3Y = yh - (Int(rate(y3ch) * (aveData3Y(avecount) - midvalue(y3ch))) + TBposition) | |
g.FillEllipse(b, acp3X, acp3Y, 9, 9) ' 点プロット | |
Debug.Print("pushMode_aveData3X,Y=" + CStr(avecount) + "," + CStr(aveData3X(avecount)) + "," + CStr(aveData3Y(avecount))) | |
result3 = LSM(aveData3X(avecount), aveData3Y(avecount), 2) | |
Debug.Print("4Ch-7CH:" + CStr(avecount) + "," + CStr(result3(0)) + "," + CStr(result3(1)) + "," + CStr(result3(2)) + "," + CStr(result3(3)) + "," + CStr(result3(4)) + "," + CStr(result3(5)) + "," + CStr(result3(6)) + "," + CStr(result3(7))) | |
TextBox53.Text = CStr(result3(0)) 'correl | |
TextBox54.Text = CStr(result3(1)) ' slope | |
TextBox57.Text = CStr(result1(2)) ' intercept | |
pushStr3 = "waku3:," + CStr(avecount) + "," + CStr(result3(0)) + "," + CStr(result3(1)) + "," + CStr(result3(2)) + "," + CStr(aveData3X(avecount)) + "," + CStr(aveData3Y(avecount)) + vbCrLf | |
RichTextBox1.AppendText(pushStr3) | |
file1.Write(pushStr3) | |
pushStr3 = "" | |
End If 'waku3 | |
file1.Write(pushStr1 + pushStr2 + pushStr3) | |
sum1X = 0 | |
sum1Y = 0 | |
sum2X = 0 | |
sum2Y = 0 | |
sum3X = 0 | |
sum3Y = 0 | |
aveNcount = 0 | |
averaging = 0 | |
g.Dispose() | |
PictureBox1.Invalidate() | |
'PictureBox1.Refresh() | |
End If | |
g.Dispose() | |
PictureBox1.Invalidate() | |
'=================Linear Mode Continuous Plot=============== | |
'If CheckBox23.Checked = False Then ' Or (CheckBox23.Checked = True And pushMode = 1) Then 'pushMode CheckBox off | |
' '--Waku1------------------------- | |
' If TextBox22.Text <> "" And TextBox23.Text <> "" Then | |
' x1ch = CInt(TextBox22.Text) - 1 'array indexNo | |
' y1ch = CInt(TextBox23.Text) - 1 | |
' cp1X(dataNo, x1ch) = yh - (Int(rate(x1ch) * (dataAry(dataNo, x1ch) - midvalue(x1ch))) + TBposition) | |
' cp1Y(dataNo, y1ch) = yh - (Int(rate(y1ch) * (dataAry(dataNo, y1ch) - midvalue(y1ch))) + TBposition) | |
' px = cp1X(dataNo, x1ch) | |
' py = cp1Y(dataNo, y1ch) | |
' 'Debug.Print("y1ch,rate(y1ch),midvalue,dataAry(y1ch)=" + CStr(y1ch) + "," + CStr(rate(y1ch)) + "," + CStr(midvalue(y1ch)) + "," + CStr(dataAry(dataNo, y1ch))) | |
' g.FillEllipse(b, px, py, 3, 3) ' 点プロット | |
' result1 = LSM(dataAry(dataNo, x1ch), dataAry(dataNo, y1ch), 0) | |
' TextBox49.Text = CStr(result1(0)) 'correl | |
' TextBox50.Text = CStr(result1(1)) ' slope | |
' End If | |
' '---Waku2---------------------------- | |
' If TextBox24.Text <> "" And TextBox25.Text <> "" Then | |
' Dim xoff As Integer = 240 | |
' x2ch = CInt(TextBox24.Text) - 1 'array indexNo | |
' y2ch = CInt(TextBox25.Text) - 1 | |
' cp2X(dataNo, x2ch) = yh - (Int(rate(x2ch) * (dataAry(dataNo, x2ch) - midvalue(x2ch))) + TBposition) | |
' cp2Y(dataNo, y2ch) = yh - (Int(rate(y2ch) * (dataAry(dataNo, y2ch) - midvalue(y2ch))) + TBposition) | |
' px = cp2X(dataNo, x2ch) + xoff | |
' py = cp2Y(dataNo, y2ch) | |
' g.FillEllipse(b, px, py, 3, 3) ' 点プロット | |
' result2 = LSM(dataAry(dataNo, x2ch), dataAry(dataNo, y2ch), 1) | |
' TextBox51.Text = CStr(result2(0)) 'correl | |
' TextBox52.Text = CStr(result2(1)) 'slope | |
' End If | |
' '---Waku3---------------------------- | |
' If TextBox26.Text <> "" And TextBox27.Text <> "" Then | |
' Dim xoff As Integer = 480 | |
' x3ch = CInt(TextBox26.Text) - 1 'array indexNo | |
' y3ch = CInt(TextBox27.Text) - 1 | |
' cp3X(dataNo, x3ch) = yh - (Int(rate(x3ch) * (dataAry(dataNo, x3ch) - midvalue(x3ch))) + TBposition) | |
' cp3Y(dataNo, y3ch) = yh - (Int(rate(y3ch) * (dataAry(dataNo, y3ch) - midvalue(y3ch))) + TBposition) | |
' px = cp3X(dataNo, x3ch) + xoff | |
' py = cp3Y(dataNo, y3ch) | |
' g.FillEllipse(b, px, py, 3, 3) ' 点プロット | |
' result3 = LSM(dataAry(dataNo, x3ch), dataAry(dataNo, y3ch), 2) | |
' TextBox53.Text = CStr(result3(0)) 'correl | |
' TextBox54.Text = CStr(result3(1)) ' slope | |
' End If | |
' g.Dispose() | |
' PictureBox1.Invalidate() | |
' 'PictureBox1.Refresh() | |
'End If 'Continuous Plot end | |
End If 'Linear mode end | |
'End If | |
End Sub | |
'******************************************************************************************************************************************************** | |
'===================================================================================================================== | |
'===============================================Form Load Init================================================== | |
'===================================================================================================================== | |
'======================================================================================== | |
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load | |
''*********************Object Array set**************************************************************************** | |
Dim CH_checkbox() As CheckBox | |
CH_checkbox = {Me.CheckBox1, Me.CheckBox2, Me.CheckBox3, Me.CheckBox4, Me.CheckBox5, Me.CheckBox6, Me.CheckBox7, Me.CheckBox13, Me.CheckBox14, Me.CheckBox15, Me.CheckBox16, Me.CheckBox17, Me.CheckBox18, Me.CheckBox19, Me.CheckBox20, Me.CheckBox21} | |
Dim dataTextBox() As TextBox | |
dataTextBox = {Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10, Me.TextBox29, Me.TextBox31, Me.TextBox33, Me.TextBox35, Me.TextBox37, Me.TextBox39, Me.TextBox41, Me.TextBox43, Me.TextBox45} | |
Dim adjustComboBox() As ComboBox | |
adjustComboBox = {Me.ComboBox1, Me.ComboBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox5, Me.ComboBox6, Me.ComboBox7, Me.ComboBox12, Me.ComboBox13, Me.ComboBox14, Me.ComboBox15, Me.ComboBox16, Me.ComboBox17, Me.ComboBox18, Me.ComboBox19, Me.ComboBox20} | |
Dim midTextBox() As TextBox | |
midTextBox = {Me.TextBox13, Me.TextBox14, Me.TextBox15, Me.TextBox16, Me.TextBox17, Me.TextBox18, Me.TextBox19, Me.TextBox28, Me.TextBox30, Me.TextBox32, Me.TextBox34, Me.TextBox36, Me.TextBox38, Me.TextBox40, Me.TextBox42, Me.TextBox44} | |
'****************************************************************************************************************** | |
'Dim arry() As Integer = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100} | |
'================COMBOBOX Def============================= | |
ComboBox21.SelectedIndex = 0 ' MA 初期値 1 | |
ComboBox1.Items.Clear() | |
Dim n As Integer | |
shokaiN = 1 | |
For i = 0 To 15 | |
adjustComboBox(i).Items.Add("0.01") '0.01mv/yh_DOT | |
adjustComboBox(i).Items.Add("0.02") '0.02mv/yh_DOT | |
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 | |
For i = 0 To 15 | |
'adjustComboBox(i).SelectedIndex = 3 | |
midTextBox(i).Text = CStr(1550) | |
'CH_checkbox(i).Checked = True | |
Next i | |
'==================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 | |
'======Color Combobox ============================ | |
ComboBox9.Items.Add(Color.Red) | |
ComboBox9.Items.Add(Color.Blue) | |
ComboBox9.Items.Add(Color.Green) | |
ComboBox9.Items.Add(Color.Magenta) | |
ComboBox9.Items.Add(Color.Orange) | |
ComboBox9.Items.Add(Color.Black) | |
ComboBox9.SelectedIndex = 0 | |
'============USB Serial Ports Search============= | |
For Each sp As String In My.Computer.Ports.SerialPortNames | |
ComboBox10.Items.Add(sp) | |
ComboBox11.Items.Add(sp) | |
Next | |
ComboBox10.Items.Add("None") | |
ComboBox11.Items.Add("None") | |
ComboBox11.SelectedIndex = ComboBox11.Items.Count - 1 | |
'==============================COLORS ==================================== | |
TextBox13.BackColor = Color.Red | |
TextBox14.BackColor = Color.Blue | |
TextBox15.BackColor = Color.Green | |
TextBox16.BackColor = Color.Magenta | |
TextBox17.BackColor = Color.Orange | |
TextBox18.BackColor = Color.LemonChiffon | |
TextBox19.BackColor = Color.Maroon | |
TextBox28.BackColor = Color.MediumSpringGreen | |
TextBox30.BackColor = Color.DeepPink | |
TextBox32.BackColor = Color.Crimson | |
TextBox34.BackColor = Color.SeaGreen | |
TextBox36.BackColor = Color.GreenYellow | |
TextBox38.BackColor = Color.Orchid | |
TextBox40.BackColor = Color.Lime | |
TextBox42.BackColor = Color.DarkSlateBlue | |
TextBox44.BackColor = Color.DarkViolet | |
End Sub | |
'======================================================================== | |
'================Average Graph mid Data================================== | |
'======================================================================== | |
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click | |
Try | |
Dim endnum As Integer | |
Dim startnum As Integer | |
Dim midave(16) As Double | |
If dataNo > 200 Then | |
endnum = dataNo ' CInt(TextBox2.Text) | |
startnum = endnum - 100 | |
midave = dave(startnum, endnum, CInt(TextBox3.Text)) | |
'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) | |
TextBox19.Text = midave(6) | |
TextBox28.Text = midave(7) | |
TextBox30.Text = midave(8) | |
TextBox32.Text = midave(9) | |
TextBox34.Text = midave(10) | |
TextBox36.Text = midave(11) | |
TextBox38.Text = midave(12) | |
TextBox40.Text = midave(13) | |
TextBox42.Text = midave(14) | |
TextBox44.Text = midave(15) | |
End If | |
Catch ex As Exception | |
Console.WriteLine(ex.Message) '例外処理を行います | |
Console.WriteLine("Error in Average") | |
End Try | |
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(16) | |
' '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) | |
' Next | |
' Next | |
'End Sub | |
'******************************************************************************************************************** | |
'*********************************FORM Reading Functions************************************************************* | |
'******************************************************************************************************************* | |
Private Function AvTR() As Double() | |
Dim ave(16) 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) | |
ave(7) = CDbl(TextBox28.Text) | |
ave(8) = CDbl(TextBox30.Text) | |
ave(9) = CDbl(TextBox32.Text) | |
ave(10) = CDbl(TextBox34.Text) | |
ave(11) = CDbl(TextBox36.Text) | |
ave(12) = CDbl(TextBox38.Text) | |
ave(13) = CDbl(TextBox40.Text) | |
ave(14) = CDbl(TextBox42.Text) | |
ave(15) = CDbl(TextBox44.Text) | |
Return ave | |
End Function | |
Private Function RateCR() As Double() | |
Dim rate(16) 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) | |
rate(7) = CDbl(ComboBox12.SelectedItem) 'mv/dot | |
rate(8) = CDbl(ComboBox13.SelectedItem) | |
rate(9) = CDbl(ComboBox14.SelectedItem) | |
rate(10) = CDbl(ComboBox15.SelectedItem) | |
rate(11) = CDbl(ComboBox16.SelectedItem) | |
rate(12) = CDbl(ComboBox17.SelectedItem) | |
rate(13) = CDbl(ComboBox18.SelectedItem) | |
rate(14) = CDbl(ComboBox19.SelectedItem) | |
rate(15) = CDbl(ComboBox20.SelectedItem) | |
Return rate | |
End Function | |
Private Function CheckBR() As Integer() | |
Dim selCh(16) As Integer '= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} | |
Dim CH_checkbox() As CheckBox | |
CH_checkbox = {Me.CheckBox1, Me.CheckBox2, Me.CheckBox3, Me.CheckBox4, Me.CheckBox5, Me.CheckBox6, Me.CheckBox7, Me.CheckBox13, Me.CheckBox14, Me.CheckBox15, Me.CheckBox16, Me.CheckBox17, Me.CheckBox18, Me.CheckBox19, Me.CheckBox20, Me.CheckBox21} | |
For i = 0 To 15 | |
If CH_checkbox(i).Checked = True Then | |
selCh(i) = 1 | |
Else | |
selCh(i) = 0 | |
End If | |
Next i | |
Return selCh | |
End Function | |
Private Function CheckCH() | |
Dim CH_checkbox() As CheckBox | |
CH_checkbox = {Me.CheckBox1, Me.CheckBox2, Me.CheckBox3, Me.CheckBox4, Me.CheckBox5, Me.CheckBox6, Me.CheckBox7, Me.CheckBox13, Me.CheckBox14, Me.CheckBox15, Me.CheckBox16, Me.CheckBox17, Me.CheckBox18, Me.CheckBox19, Me.CheckBox20, Me.CheckBox21} | |
Dim dataTextBox() As TextBox | |
dataTextBox = {Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10, Me.TextBox29, Me.TextBox31, Me.TextBox33, Me.TextBox35, Me.TextBox37, Me.TextBox39, Me.TextBox41, Me.TextBox43, Me.TextBox45} | |
'Debug.Print("CheckCH Integer Chsuu") | |
'Debug.Print(Chsuu) | |
For i = 0 To 15 | |
If i < Chsuu Then | |
CH_checkbox(i).Checked = True | |
Else | |
CH_checkbox(i).Checked = False | |
End If | |
Next | |
Label3.Text = "CH selected" | |
End Function | |
'******************************************************************************************************************* | |
'******************************************************************************************************************* | |
'******************************************************************************************************************* | |
'================================================================================================================== | |
'==================================Static Calculation=========================================================== | |
'==========================Ave() MovingAve() ============================================================ | |
'================================================================================================================== | |
'================================================================================================================== | |
Function dave(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(16) | |
Dim dstring As String | |
dstring = "dave:" + CStr(startN) + "," + CStr(endN) + "," + CStr(ch) | |
' Debug.Print(dstring) | |
'Try | |
For chN = 0 To ch - 1 'chは1-6chで与えられるがデータindexは0-5 | |
For dataN = startN To endN 'startNからendNまでendN-startN+1 個の総和をとって平均 | |
dsum += dataAry(dataN, chN) | |
Next | |
avech(chN) = dsum / (endN - startN + 1) | |
dsum = 0 | |
Next | |
Return avech | |
'Catch ex As Exception | |
' Console.WriteLine(ex.Message) | |
' Console.WriteLine("Error In dave()") | |
'End Try | |
End Function | |
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 | |
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 | |
'====Linearuty MODE Controls Visible=============== | |
Private Sub CheckBox10_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox10.CheckedChanged | |
If CheckBox10.Checked = True Then | |
TextBox22.Visible = True | |
TextBox23.Visible = True | |
TextBox24.Visible = True | |
TextBox25.Visible = True | |
TextBox26.Visible = True | |
TextBox27.Visible = True | |
Label11.Visible = True | |
Label12.Visible = True | |
Label13.Visible = True | |
Label14.Visible = True | |
Label15.Visible = True | |
Label16.Visible = True | |
Label17.Visible = True | |
Label18.Visible = True | |
Label19.Visible = True | |
End If | |
If CheckBox10.Checked = False Then | |
TextBox22.Visible = False | |
TextBox23.Visible = False | |
TextBox24.Visible = False | |
TextBox25.Visible = False | |
TextBox26.Visible = False | |
TextBox27.Visible = False | |
Label11.Visible = False | |
Label12.Visible = False | |
Label13.Visible = False | |
Label14.Visible = False | |
Label15.Visible = False | |
Label16.Visible = False | |
Label17.Visible = False | |
Label18.Visible = False | |
Label19.Visible = False | |
End If | |
End Sub | |
Private Sub Button8_Click_1(sender As Object, e As EventArgs) Handles Button8.Click | |
PictureBox1.Image = Nothing '1スクロール毎に画面クリア | |
'LSMinit() 'LSM計算初期化 | |
End Sub | |
Private Sub ComboBox9_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox9.SelectedIndexChanged | |
Select Case ComboBox9.SelectedIndex | |
Case 0 | |
ComboBox9.BackColor = Color.Red | |
ComboBox9.ForeColor = Color.Red | |
Case 1 | |
ComboBox9.BackColor = Color.Blue | |
ComboBox9.ForeColor = Color.Blue | |
Case 2 | |
ComboBox9.BackColor = Color.Green | |
ComboBox9.ForeColor = Color.Green | |
Case 3 | |
ComboBox9.BackColor = Color.Magenta | |
ComboBox9.ForeColor = Color.Magenta | |
Case 4 | |
ComboBox9.BackColor = Color.Orange | |
ComboBox9.ForeColor = Color.Orange | |
Case 5 | |
ComboBox9.BackColor = Color.Black | |
ComboBox9.ForeColor = Color.Black | |
End Select | |
End Sub | |
Private Sub Label24_Click(sender As Object, e As EventArgs) Handles Label24.Click | |
End Sub | |
Private Sub ComboBox9_Click(sender As Object, e As EventArgs) Handles ComboBox9.Click | |
ComboBox9.ForeColor = Color.Gray | |
End Sub | |
'==========Comment MEMO===================================== | |
Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles RichTextBox1.TextChanged | |
'-------Ellipse Color---------------- | |
Select Case ComboBox9.SelectedIndex | |
Case 0 | |
RichTextBox1.SelectionColor = Color.Red | |
Case 1 | |
RichTextBox1.SelectionColor = Color.Blue | |
Case 2 | |
RichTextBox1.SelectionColor = Color.Green | |
Case 3 | |
RichTextBox1.SelectionColor = Color.Magenta | |
Case 4 | |
RichTextBox1.SelectionColor = Color.Orange | |
Case 5 | |
RichTextBox1.SelectionColor = Color.Black | |
End Select | |
End Sub | |
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged | |
'shokaiN = 1 | |
End Sub | |
Private Sub ListBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseDown | |
Dim sindex As Integer | |
sindex = ListBox1.SelectedIndex | |
TextBox12.Text = ListBox1.SelectedItem | |
End Sub | |
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click | |
shokaiN = 1 | |
End Sub | |
Private Sub formRecord() | |
''*********************Object Array set**************************************************************************** | |
Dim CH_checkbox() As CheckBox | |
CH_checkbox = {Me.CheckBox1, Me.CheckBox2, Me.CheckBox3, Me.CheckBox4, Me.CheckBox5, Me.CheckBox6, Me.CheckBox7, Me.CheckBox13, Me.CheckBox14, Me.CheckBox15, Me.CheckBox16, Me.CheckBox17, Me.CheckBox18, Me.CheckBox19, Me.CheckBox20, Me.CheckBox21} | |
Dim dataTextBox() As TextBox | |
dataTextBox = {Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10, Me.TextBox29, Me.TextBox31, Me.TextBox33, Me.TextBox35, Me.TextBox37, Me.TextBox39, Me.TextBox41, Me.TextBox43, Me.TextBox45} | |
Dim adjustComboBox() As ComboBox | |
adjustComboBox = {Me.ComboBox1, Me.ComboBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox5, Me.ComboBox6, Me.ComboBox7, Me.ComboBox12, Me.ComboBox13, Me.ComboBox14, Me.ComboBox15, Me.ComboBox16, Me.ComboBox17, Me.ComboBox18, Me.ComboBox19, Me.ComboBox20} | |
Dim midTextBox() As TextBox | |
midTextBox = {Me.TextBox13, Me.TextBox14, Me.TextBox15, Me.TextBox16, Me.TextBox17, Me.TextBox18, Me.TextBox19, Me.TextBox28, Me.TextBox30, Me.TextBox32, Me.TextBox34, Me.TextBox36, Me.TextBox38, Me.TextBox40, Me.TextBox42, Me.TextBox44} | |
'****************************************************************************************************************** | |
'Dim arry() As Integer = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100} | |
'================COMBOBOX Def============================= | |
ComboBox21.SelectedIndex = 0 ' MA 初期値 1 | |
ComboBox1.Items.Clear() | |
Dim n As Integer | |
shokaiN = 1 | |
For i = 0 To 15 | |
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 | |
For i = 0 To 15 | |
'adjustComboBox(i).SelectedIndex = 3 | |
midTextBox(i).Text = CStr(1550) | |
'CH_checkbox(i).Checked = True | |
Next i | |
'==================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 | |
'======Color Combobox ============================ | |
ComboBox9.Items.Add(Color.Red) | |
ComboBox9.Items.Add(Color.Blue) | |
ComboBox9.Items.Add(Color.Green) | |
ComboBox9.Items.Add(Color.Magenta) | |
ComboBox9.Items.Add(Color.Orange) | |
ComboBox9.Items.Add(Color.Black) | |
ComboBox9.SelectedIndex = 0 | |
'============USB Serial Ports Search============= | |
For Each sp As String In My.Computer.Ports.SerialPortNames | |
ComboBox10.Items.Add(sp) | |
ComboBox11.Items.Add(sp) | |
Next | |
ComboBox10.Items.Add("None") | |
ComboBox11.Items.Add("None") | |
ComboBox11.SelectedIndex = ComboBox11.Items.Count - 1 | |
End Sub | |
'======================================================================================================================== | |
'================================================Setting Save Mode======================================================== | |
'======================================================================================================================== | |
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click | |
'''*********************Control Object Array set**************************************************************************** | |
Dim allTextBox() As TextBox | |
allTextBox = {Me.TextBox1, Me.TextBox2, Me.TextBox3, Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10 _ | |
, Me.TextBox11, Me.TextBox12, Me.TextBox13, Me.TextBox14, Me.TextBox15, Me.TextBox16, Me.TextBox17, Me.TextBox18, Me.TextBox19, Me.TextBox20 _ | |
, Me.TextBox21, Me.TextBox22, Me.TextBox23, Me.TextBox24, Me.TextBox25, Me.TextBox26, Me.TextBox27, Me.TextBox28, Me.TextBox29, Me.TextBox30 _ | |
, Me.TextBox31, Me.TextBox32, Me.TextBox33, Me.TextBox34, Me.TextBox35, Me.TextBox36, Me.TextBox37, Me.TextBox38, Me.TextBox39, Me.TextBox40 _ | |
, Me.TextBox41, Me.TextBox42, Me.TextBox43, Me.TextBox44, Me.TextBox45, Me.TextBox46, Me.TextBox47, Me.TextBox48, Me.TextBox49, Me.TextBox50 _ | |
, Me.TextBox51, Me.TextBox52, Me.TextBox53, Me.TextBox54, Me.TextBox55, Me.TextBox56, Me.TextBox57, Me.TextBox58, Me.TextBox59} | |
Dim allcheckbox() As CheckBox | |
allcheckbox = {Me.CheckBox1, Me.CheckBox2, Me.CheckBox3, Me.CheckBox4, Me.CheckBox5, Me.CheckBox6, Me.CheckBox7, Me.CheckBox8, Me.CheckBox9, Me.CheckBox10 _ | |
, Me.CheckBox11, Me.CheckBox12, Me.CheckBox13, Me.CheckBox14, Me.CheckBox15, Me.CheckBox16, Me.CheckBox17, Me.CheckBox18, Me.CheckBox19, Me.CheckBox20 _ | |
, Me.CheckBox21, Me.CheckBox22, Me.CheckBox23, Me.CheckBox24} | |
Dim allComboBox() As ComboBox | |
allComboBox = {Me.ComboBox1, Me.ComboBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox5, Me.ComboBox6, Me.ComboBox7, Me.ComboBox8, Me.ComboBox9, Me.ComboBox10 _ | |
, Me.ComboBox11, Me.ComboBox12, Me.ComboBox13, Me.ComboBox14, Me.ComboBox15, Me.ComboBox16, Me.ComboBox17, Me.ComboBox18, Me.ComboBox19, Me.ComboBox20 _ | |
, Me.ComboBox21} | |
''***************************************File Name ****************************************************************** | |
' If CheckBox8.Checked = True And fname = "" Then | |
fname2 = Format(Now, "yyyyMMdd_HHmmss") | |
fname2 = "C:\vb_LOG\Set_" & fname2 & ".csv" | |
TextBox59.Text = fname2 | |
'---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”) | |
file2 = My.Computer.FileSystem.OpenTextFileWriter(fname2, False, enc) | |
' End If | |
'=====TextBox Save======== | |
For cIndex = 0 To 58 | |
textboxdata = allTextBox(cIndex).Text & "," | |
file2.Write(textboxdata) | |
Next | |
file2.Write(vbCrLf) | |
For cIndex = 0 To 23 | |
checkboxdata = allcheckbox(cIndex).Checked & "," | |
file2.Write(checkboxdata) | |
Next | |
file2.Write(vbCrLf) | |
For cIndex = 0 To 20 | |
comboboxdata = allComboBox(cIndex).SelectedIndex & "," | |
file2.Write(comboboxdata) | |
Next | |
file2.Write(vbCrLf) | |
file2.Close() | |
End Sub | |
'======================================================================================================================== | |
'================================================Setting Read Mode======================================================== | |
'======================================================================================================================== | |
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click | |
'''*********************Control Object Array set**************************************************************************** | |
Dim allTextBox() As TextBox | |
allTextBox = {Me.TextBox1, Me.TextBox2, Me.TextBox3, Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10 _ | |
, Me.TextBox11, Me.TextBox12, Me.TextBox13, Me.TextBox14, Me.TextBox15, Me.TextBox16, Me.TextBox17, Me.TextBox18, Me.TextBox19, Me.TextBox20 _ | |
, Me.TextBox21, Me.TextBox22, Me.TextBox23, Me.TextBox24, Me.TextBox25, Me.TextBox26, Me.TextBox27, Me.TextBox28, Me.TextBox29, Me.TextBox30 _ | |
, Me.TextBox31, Me.TextBox32, Me.TextBox33, Me.TextBox34, Me.TextBox35, Me.TextBox36, Me.TextBox37, Me.TextBox38, Me.TextBox39, Me.TextBox40 _ | |
, Me.TextBox41, Me.TextBox42, Me.TextBox43, Me.TextBox44, Me.TextBox45, Me.TextBox46, Me.TextBox47, Me.TextBox48, Me.TextBox49, Me.TextBox50 _ | |
, Me.TextBox51, Me.TextBox52, Me.TextBox53, Me.TextBox54, Me.TextBox55, Me.TextBox56, Me.TextBox57, Me.TextBox58, Me.TextBox59} | |
Dim allcheckbox() As CheckBox | |
allcheckbox = {Me.CheckBox1, Me.CheckBox2, Me.CheckBox3, Me.CheckBox4, Me.CheckBox5, Me.CheckBox6, Me.CheckBox7, Me.CheckBox8, Me.CheckBox9, Me.CheckBox10 _ | |
, Me.CheckBox11, Me.CheckBox12, Me.CheckBox13, Me.CheckBox14, Me.CheckBox15, Me.CheckBox16, Me.CheckBox17, Me.CheckBox18, Me.CheckBox19, Me.CheckBox20 _ | |
, Me.CheckBox21, Me.CheckBox22, Me.CheckBox23, Me.CheckBox24} | |
Dim allComboBox() As ComboBox | |
allComboBox = {Me.ComboBox1, Me.ComboBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox5, Me.ComboBox6, Me.ComboBox7, Me.ComboBox8, Me.ComboBox9, Me.ComboBox10 _ | |
, Me.ComboBox11, Me.ComboBox12, Me.ComboBox13, Me.ComboBox14, Me.ComboBox15, Me.ComboBox16, Me.ComboBox17, Me.ComboBox18, Me.ComboBox19, Me.ComboBox20 _ | |
, Me.ComboBox21} | |
''****************************************************************************************************************** | |
Dim ofd As New OpenFileDialog() | |
'はじめのファイル名を指定する | |
'はじめに「ファイル名」で表示される文字列を指定する | |
ofd.FileName = "yyyyMMdd_HHmmss" '"default.html" | |
'はじめに表示されるフォルダを指定する | |
'指定しない(空の文字列)の時は、現在のディレクトリが表示される | |
ofd.InitialDirectory = "C:\vb_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ボタンがクリックされたとき、選択されたファイル名を表示する | |
Console.WriteLine(ofd.FileName) | |
End If | |
'ダイアログを表示する | |
'================================MS sample========================= | |
'https://docs.microsoft.com/ja-jp/dotnet/visual-basic/developing-apps/programming/drives-directories-files/how-to-read-from-comma-delimited-text-files | |
'=================================================================== | |
Using MyReader As New Microsoft.VisualBasic. | |
FileIO.TextFieldParser(ofd.FileName) | |
MyReader.TextFieldType = FileIO.FieldType.Delimited | |
MyReader.SetDelimiters(",") | |
Dim currentRow As String() | |
cIndex = 0 | |
While Not MyReader.EndOfData | |
Try | |
currentRow = MyReader.ReadFields() | |
Dim currentField As String | |
For Each currentField In currentRow | |
'MsgBox(currentField) | |
readata(cIndex) = currentField | |
Debug.Print(cIndex & ":" & readata(cIndex)) | |
'=====TextBox input===== | |
If cIndex < 59 Then | |
allTextBox(cIndex).Text = currentField | |
End If | |
If cIndex > 59 And cIndex < 84 Then | |
allcheckbox(cIndex - 60).Checked = CType(currentField, Boolean) | |
End If | |
If cIndex > 84 And cIndex < 106 Then | |
allComboBox(cIndex - 85).SelectedIndex = currentField | |
End If | |
cIndex = cIndex + 1 | |
Next | |
Catch ex As Microsoft.VisualBasic. | |
FileIO.MalformedLineException | |
MsgBox("Line " & ex.Message & | |
"is not valid and will be skipped.") | |
End Try | |
End While | |
End Using | |
'Using parser As New TextFieldParser(ofd.FileName, System.Text.Encoding.GetEncoding("Shift_JIS")) | |
' parser.TextFieldType = FieldType.Delimited | |
' parser.SetDelimiters(",") ' 区切り文字はコンマ | |
' ' parser.HasFieldsEnclosedInQuotes = False | |
' ' parser.TrimWhiteSpace = False | |
' While Not parser.EndOfData | |
' Dim row As String() = parser.ReadFields() ' 1行読み込み | |
' For i = 0 To row.Length | |
' readata = Split(row(i), ",", -1, CompareMethod.Text) | |
' ' For j = 0 To readata.Length | |
' Debug.Print(readata(0) & ",") | |
' 'Next j | |
' Next i | |
'For Each field As String In row | |
' field = field.Replace(vbCrLf, "n") ' 改行をnで表示 | |
' field = field.Replace(" ", "_") ' 空白を_で表示 | |
' Debug.Writeline(field + vbTab) ' TAB区切りで出力 | |
' 'Debug.Print(field + ",") | |
'Next | |
'Console.WriteLine() | |
'End While | |
'End Using | |
''==============================File Open Read====================================================== | |
'Dim textFile As FileIO.TextFieldParser ' -- 入力するファイル | |
'' --- 入力ファイルを開く | |
'textFile = New FileIO.TextFieldParser(ofd.FileName) ' -- デフォルト encoding は UTF8 | |
'' --- デリミターをタブと定義する | |
'textFile.TextFieldType = FileIO.FieldType.Delimited | |
'textFile.SetDelimiters(",") ' -- カンマ区切りの場合はカッコ内を "," にします | |
'' --- 行を文字型配列(currentRow)に読み込み、各列を DataGridView に格納する | |
'Dim currentRow As String() ' -- 文字型配列 | |
'Dim myRow As Integer = 0 | |
'Dim myCol As Integer = 0 | |
'' ---▼▼ 行ループ | |
'While Not textFile.EndOfData | |
' Me.DataGridView1.Rows.Add() ' -- DataGridView に新規行を追加 | |
' currentRow = textFile.ReadFields() ' -- 1行を文字型配列に格納 | |
' Dim currentColumn As String | |
' ' ---▼ 列ループ:1行分の列を埋める | |
' For Each currentColumn In currentRow | |
' Me.DataGridView1(myCol, myRow).Value = currentColumn | |
' myCol += 1 | |
' Next ' --▲ 列ループ | |
' myCol = 0 | |
' myRow += 1 | |
'End While ' --▲▲ 行ループ | |
'' --- 入力ファイルを閉じる | |
'textFile.Close() | |
''===================FILE Name================= | |
''------FILE SAVE---------------------- | |
'Dim sfd As New SaveFileDialog() | |
'Dim fname4 As String | |
'fname4 = Format(Now, "yyyyMMdd_HHmmss") | |
'' Debug.Print("fname4=" & fname4) | |
'sfd.FileName = fname4 | |
'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 | |
End Sub | |
End Class | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment