回答編集履歴

1

追記 こんなイメージ

2023/05/05 03:28

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -15,3 +15,92 @@
15
15
 
16
16
  `Log`の`Modifiers`を、`public`か`internal`にしてください。
17
17
  [方法: Modifiers プロパティおよび GenerateMember プロパティを使用する - Windows Forms .NET Framework | Microsoft Learn](https://learn.microsoft.com/ja-jp/dotnet/desktop/winforms/advanced/how-to-use-the-modifiers-and-generatemember-properties)
18
+
19
+ ---
20
+
21
+ # 追記
22
+ こんなイメージです(関係ないところはバッサリカット)
23
+ ```cs
24
+ using System.IO.Ports;
25
+
26
+ namespace Q1d8jlq64jymrpv;
27
+
28
+ public partial class MainForm : Form
29
+ {
30
+ SerialPort serialport = new SerialPort();
31
+ SerialDataEdit sde = new SerialDataEdit();
32
+
33
+ static public string CNT = "";
34
+ static public string FLW = "";
35
+ static public string CT = "";
36
+ static public string PI = "";
37
+
38
+ public MainForm()
39
+ {
40
+ InitializeComponent();
41
+ }
42
+
43
+ private void Serialport_DataReceived(object sender, SerialDataReceivedEventArgs e)
44
+ {
45
+ try
46
+ {
47
+ if (sde.stringEdit(serialport.ReadLine()))
48
+ {
49
+ //chart.addpoint();
50
+ log.logging();
51
+ }
52
+ }
53
+ catch (Exception ex)
54
+ {
55
+ MessageBox.Show(ex.Message);
56
+ }
57
+ }
58
+ }
59
+
60
+ public class SerialDataEdit
61
+ {
62
+ string? SerialDataOriginal;
63
+ string? countData;
64
+ string? flowrateData;
65
+ string? contactTimeData;
66
+ string? pulseIntervalData;
67
+
68
+ int wait = 0;
69
+
70
+ public bool stringEdit(string? Arduino)
71
+ {
72
+ switch (Arduino?[0])
73
+ {
74
+ case 'A':
75
+ MainForm.CNT = countData = Arduino[1..];
76
+ wait++;
77
+ break;
78
+ case 'B':
79
+ MainForm.FLW = flowrateData = Arduino[1..];
80
+ wait++;
81
+ break;
82
+ case 'C':
83
+ MainForm.CT = contactTimeData = Arduino[1..];
84
+ wait++;
85
+ break;
86
+ case 'D':
87
+ MainForm.PI = pulseIntervalData = Arduino[1..];
88
+ wait++;
89
+ break;
90
+ default:
91
+ countData = "0";
92
+ flowrateData = "0";
93
+ contactTimeData = "0";
94
+ pulseIntervalData = "0";
95
+ break;
96
+ }
97
+
98
+ if (wait == 4)
99
+ {
100
+ wait = 0;
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ }
106
+ ```