質問編集履歴

4

コード変更

2019/07/12 08:11

投稿

tsutaya_0624
tsutaya_0624

スコア12

test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,8 @@
26
26
 
27
27
  C#
28
28
 
29
+
30
+
29
31
  ```ここに言語を入力
30
32
 
31
33
  using System;
@@ -50,7 +52,7 @@
50
52
 
51
53
 
52
54
 
53
- ```ここに言語を入力
55
+
54
56
 
55
57
  namespace SerialTest
56
58
 
@@ -92,230 +94,232 @@
92
94
 
93
95
 
94
96
 
97
+
98
+
99
+ private void Form1_Load(object sender, EventArgs e)
100
+
101
+ {
102
+
103
+ string[] ports = SerialPort.GetPortNames();
104
+
105
+ foreach (string port in ports)
106
+
107
+ {
108
+
109
+ portComboBox.Items.Add(port);
110
+
111
+ }
112
+
113
+ if (portComboBox.Items.Count > 0)
114
+
115
+ portComboBox.SelectedIndex = 0;
116
+
117
+ }
118
+
119
+
120
+
121
+ private void button2_Click(object sender, EventArgs e)
122
+
123
+ {
124
+
125
+ if (serialPort1.IsOpen)
126
+
127
+ {
128
+
129
+ serialPort1.Write(textBox2.Text + "\n");
130
+
131
+ }
132
+
133
+ }
134
+
135
+
136
+
137
+ delegate void SetTextCallback(string text);
138
+
139
+ private void Response(string text)
140
+
141
+ {
142
+
143
+ if (textBox1.InvokeRequired)
144
+
145
+ {
146
+
147
+ SetTextCallback d = new SetTextCallback(Response);
148
+
149
+ BeginInvoke(d, new object[] { text });
150
+
151
+ }
152
+
153
+ else
154
+
155
+ {
156
+
157
+ textBox1.AppendText(text + "\n");
158
+
159
+ }
160
+
161
+ }
162
+
163
+
164
+
165
+ private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
166
+
167
+ {
168
+
169
+ string str = serialPort1.ReadLine();
170
+
171
+ Response(str);
172
+
173
+ }
174
+
175
+
176
+
177
+ private void button3_Click(object sender, EventArgs e)
178
+
179
+ {
180
+
181
+ serialPort1.Close();
182
+
183
+ }
184
+
185
+ }
186
+
187
+ }
188
+
189
+ namespace SerialTest
190
+
191
+ {
192
+
193
+ public partial class Form1 : Form
194
+
195
+ {
196
+
197
+ public Form1()
198
+
199
+ {
200
+
201
+ InitializeComponent();
202
+
203
+ }
204
+
205
+
206
+
207
+ private void button1_Click(object sender, EventArgs e)
208
+
209
+ {
210
+
211
+ serialPort1.BaudRate = 38400;
212
+
213
+ serialPort1.Parity = Parity.None;
214
+
215
+ serialPort1.DataBits = 8;
216
+
217
+ serialPort1.StopBits = StopBits.One;
218
+
219
+ serialPort1.Handshake = Handshake.None;
220
+
221
+ serialPort1.PortName = portComboBox.Text;
222
+
223
+ serialPort1.Open();
224
+
225
+ }
226
+
227
+
228
+
229
+ private void Form1_Load(object sender, EventArgs e)
230
+
231
+ {
232
+
233
+ string[] ports = SerialPort.GetPortNames();
234
+
235
+ foreach (string port in ports)
236
+
237
+ {
238
+
239
+ portComboBox.Items.Add(port);
240
+
241
+ }
242
+
243
+ if (portComboBox.Items.Count > 0)
244
+
245
+ portComboBox.SelectedIndex = 0;
246
+
247
+ }
248
+
249
+
250
+
251
+ private void button2_Click(object sender, EventArgs e)
252
+
253
+ {
254
+
255
+ if (serialPort1.IsOpen)
256
+
257
+ {
258
+
259
+ serialPort1.Write(textBox2.Text + "\n");
260
+
261
+ }
262
+
263
+ }
264
+
265
+
266
+
267
+ delegate void SetTextCallback(string text);
268
+
269
+ private void Response(string text)
270
+
271
+ {
272
+
273
+ if (textBox1.InvokeRequired)
274
+
275
+ {
276
+
277
+ SetTextCallback d = new SetTextCallback(Response);
278
+
279
+ BeginInvoke(d, new object[] { text });
280
+
281
+ }
282
+
283
+ else
284
+
285
+ {
286
+
287
+ textBox1.AppendText(text + "\n");
288
+
289
+ }
290
+
291
+ }
292
+
293
+
294
+
295
+ private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
296
+
297
+ {
298
+
299
+ string str = serialPort1.ReadLine();
300
+
301
+ Response(str);
302
+
303
+ }
304
+
305
+
306
+
307
+ private void button3_Click(object sender, EventArgs e)
308
+
309
+ {
310
+
311
+ serialPort1.Close();
312
+
313
+ }
314
+
315
+ }
316
+
317
+ }
318
+
319
+
320
+
95
321
  ```
96
322
 
97
- private void Form1_Load(object sender, EventArgs e)
98
-
99
- {
100
-
101
- string[] ports = SerialPort.GetPortNames();
102
-
103
- foreach (string port in ports)
104
-
105
- {
106
-
107
- portComboBox.Items.Add(port);
108
-
109
- }
110
-
111
- if (portComboBox.Items.Count > 0)
112
-
113
- portComboBox.SelectedIndex = 0;
114
-
115
- }
116
-
117
-
118
-
119
- private void button2_Click(object sender, EventArgs e)
120
-
121
- {
122
-
123
- if (serialPort1.IsOpen)
124
-
125
- {
126
-
127
- serialPort1.Write(textBox2.Text + "\n");
128
-
129
- }
130
-
131
- }
132
-
133
-
134
-
135
- delegate void SetTextCallback(string text);
136
-
137
- private void Response(string text)
138
-
139
- {
140
-
141
- if (textBox1.InvokeRequired)
142
-
143
- {
144
-
145
- SetTextCallback d = new SetTextCallback(Response);
146
-
147
- BeginInvoke(d, new object[] { text });
148
-
149
- }
150
-
151
- else
152
-
153
- {
154
-
155
- textBox1.AppendText(text + "\n");
156
-
157
- }
158
-
159
- }
160
-
161
-
162
-
163
- private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
164
-
165
- {
166
-
167
- string str = serialPort1.ReadLine();
168
-
169
- Response(str);
170
-
171
- }
172
-
173
-
174
-
175
- private void button3_Click(object sender, EventArgs e)
176
-
177
- {
178
-
179
- serialPort1.Close();
180
-
181
- }
182
-
183
- }
184
-
185
- }
186
-
187
- namespace SerialTest
188
-
189
- {
190
-
191
- public partial class Form1 : Form
192
-
193
- {
194
-
195
- public Form1()
196
-
197
- {
198
-
199
- InitializeComponent();
200
-
201
- }
202
-
203
-
204
-
205
- private void button1_Click(object sender, EventArgs e)
206
-
207
- {
208
-
209
- serialPort1.BaudRate = 38400;
210
-
211
- serialPort1.Parity = Parity.None;
212
-
213
- serialPort1.DataBits = 8;
214
-
215
- serialPort1.StopBits = StopBits.One;
216
-
217
- serialPort1.Handshake = Handshake.None;
218
-
219
- serialPort1.PortName = portComboBox.Text;
220
-
221
- serialPort1.Open();
222
-
223
- }
224
-
225
-
226
-
227
- private void Form1_Load(object sender, EventArgs e)
228
-
229
- {
230
-
231
- string[] ports = SerialPort.GetPortNames();
232
-
233
- foreach (string port in ports)
234
-
235
- {
236
-
237
- portComboBox.Items.Add(port);
238
-
239
- }
240
-
241
- if (portComboBox.Items.Count > 0)
242
-
243
- portComboBox.SelectedIndex = 0;
244
-
245
- }
246
-
247
-
248
-
249
- private void button2_Click(object sender, EventArgs e)
250
-
251
- {
252
-
253
- if (serialPort1.IsOpen)
254
-
255
- {
256
-
257
- serialPort1.Write(textBox2.Text + "\n");
258
-
259
- }
260
-
261
- }
262
-
263
-
264
-
265
- delegate void SetTextCallback(string text);
266
-
267
- private void Response(string text)
268
-
269
- {
270
-
271
- if (textBox1.InvokeRequired)
272
-
273
- {
274
-
275
- SetTextCallback d = new SetTextCallback(Response);
276
-
277
- BeginInvoke(d, new object[] { text });
278
-
279
- }
280
-
281
- else
282
-
283
- {
284
-
285
- textBox1.AppendText(text + "\n");
286
-
287
- }
288
-
289
- }
290
-
291
-
292
-
293
- private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
294
-
295
- {
296
-
297
- string str = serialPort1.ReadLine();
298
-
299
- Response(str);
300
-
301
- }
302
-
303
-
304
-
305
- private void button3_Click(object sender, EventArgs e)
306
-
307
- {
308
-
309
- serialPort1.Close();
310
-
311
- }
312
-
313
- }
314
-
315
- }
316
-
317
- ```
318
-
319
323
 
320
324
 
321
325
  ### 試したこと

3

コード変更

2019/07/12 08:11

投稿

tsutaya_0624
tsutaya_0624

スコア12

test CHANGED
File without changes
test CHANGED
@@ -26,7 +26,7 @@
26
26
 
27
27
  C#
28
28
 
29
- C#
29
+ ```ここに言語を入力
30
30
 
31
31
  using System;
32
32
 
@@ -314,6 +314,8 @@
314
314
 
315
315
  }
316
316
 
317
+ ```
318
+
317
319
 
318
320
 
319
321
  ### 試したこと

2

タイトル

2019/07/12 08:10

投稿

tsutaya_0624
tsutaya_0624

スコア12

test CHANGED
@@ -1 +1 @@
1
- C#のwindowsのformからドライバー接続をしたいのですが...[プログラム初心者]
1
+ C#のwindowsのformからドライバー接続をしたいのですが...
test CHANGED
File without changes

1

タイトルとコード

2019/07/12 07:02

投稿

tsutaya_0624
tsutaya_0624

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ### C#のwindowsのformからドライバー接続をしたいのですが...[プログラム初心者]
1
+ ### C#のwindowsのformからドライバー接続をしたいのですが...
2
2
 
3
3
 
4
4
 
@@ -26,6 +26,8 @@
26
26
 
27
27
  C#
28
28
 
29
+ C#
30
+
29
31
  using System;
30
32
 
31
33
  using System.Collections.Generic;
@@ -48,6 +50,8 @@
48
50
 
49
51
 
50
52
 
53
+ ```ここに言語を入力
54
+
51
55
  namespace SerialTest
52
56
 
53
57
  {
@@ -88,6 +92,8 @@
88
92
 
89
93
 
90
94
 
95
+ ```
96
+
91
97
  private void Form1_Load(object sender, EventArgs e)
92
98
 
93
99
  {
@@ -178,6 +184,136 @@
178
184
 
179
185
  }
180
186
 
187
+ namespace SerialTest
188
+
189
+ {
190
+
191
+ public partial class Form1 : Form
192
+
193
+ {
194
+
195
+ public Form1()
196
+
197
+ {
198
+
199
+ InitializeComponent();
200
+
201
+ }
202
+
203
+
204
+
205
+ private void button1_Click(object sender, EventArgs e)
206
+
207
+ {
208
+
209
+ serialPort1.BaudRate = 38400;
210
+
211
+ serialPort1.Parity = Parity.None;
212
+
213
+ serialPort1.DataBits = 8;
214
+
215
+ serialPort1.StopBits = StopBits.One;
216
+
217
+ serialPort1.Handshake = Handshake.None;
218
+
219
+ serialPort1.PortName = portComboBox.Text;
220
+
221
+ serialPort1.Open();
222
+
223
+ }
224
+
225
+
226
+
227
+ private void Form1_Load(object sender, EventArgs e)
228
+
229
+ {
230
+
231
+ string[] ports = SerialPort.GetPortNames();
232
+
233
+ foreach (string port in ports)
234
+
235
+ {
236
+
237
+ portComboBox.Items.Add(port);
238
+
239
+ }
240
+
241
+ if (portComboBox.Items.Count > 0)
242
+
243
+ portComboBox.SelectedIndex = 0;
244
+
245
+ }
246
+
247
+
248
+
249
+ private void button2_Click(object sender, EventArgs e)
250
+
251
+ {
252
+
253
+ if (serialPort1.IsOpen)
254
+
255
+ {
256
+
257
+ serialPort1.Write(textBox2.Text + "\n");
258
+
259
+ }
260
+
261
+ }
262
+
263
+
264
+
265
+ delegate void SetTextCallback(string text);
266
+
267
+ private void Response(string text)
268
+
269
+ {
270
+
271
+ if (textBox1.InvokeRequired)
272
+
273
+ {
274
+
275
+ SetTextCallback d = new SetTextCallback(Response);
276
+
277
+ BeginInvoke(d, new object[] { text });
278
+
279
+ }
280
+
281
+ else
282
+
283
+ {
284
+
285
+ textBox1.AppendText(text + "\n");
286
+
287
+ }
288
+
289
+ }
290
+
291
+
292
+
293
+ private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
294
+
295
+ {
296
+
297
+ string str = serialPort1.ReadLine();
298
+
299
+ Response(str);
300
+
301
+ }
302
+
303
+
304
+
305
+ private void button3_Click(object sender, EventArgs e)
306
+
307
+ {
308
+
309
+ serialPort1.Close();
310
+
311
+ }
312
+
313
+ }
314
+
315
+ }
316
+
181
317
 
182
318
 
183
319
  ### 試したこと