質問編集履歴
4
意図的に内容を抹消する行為にあたるため
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
PythonのコードをC#かVBに変換したい
|
test
CHANGED
@@ -1,13 +1,175 @@
|
|
1
|
+
PythonのコードをVBかC#に変換したいです。
|
2
|
+
|
3
|
+
目的は学習です。
|
4
|
+
|
5
|
+
Pythonコードは正常に動作している物で
|
6
|
+
|
1
|
-
|
7
|
+
VBコードは現在動作していない物です。
|
8
|
+
|
9
|
+
元のPythonコードと、私が書いたVBコードを載せます。
|
10
|
+
|
11
|
+
例外エラーなどは出ず処理は一応実行できますが、動作しない状況です。
|
12
|
+
|
13
|
+
私が書いたVBコードはどこが間違えているのかご教示願いたいです。
|
2
14
|
|
3
15
|
|
4
16
|
|
17
|
+
```Python
|
5
18
|
|
19
|
+
import requests
|
6
20
|
|
21
|
+
import json
|
7
22
|
|
23
|
+
# csvファイル取得
|
8
24
|
|
9
|
-
|
25
|
+
def get_csv(groupcodes, commandbytes):
|
10
26
|
|
11
|
-
|
27
|
+
url = 'http://192.168.14.100:7001/testapi/sendbroadcastcommand?groupcodes={}&commandbytes={}'. format(json.dumps(groupcodes), json.dumps(commandbytes))
|
12
28
|
|
29
|
+
print(url)
|
30
|
+
|
31
|
+
headers = {
|
32
|
+
|
33
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
try:
|
38
|
+
|
39
|
+
response = requests.post(url=url, headers=headers)
|
40
|
+
|
41
|
+
except Exception as e:
|
42
|
+
|
43
|
+
print("POST 例外発生!")
|
44
|
+
|
45
|
+
print(e)
|
46
|
+
|
47
|
+
return -1
|
48
|
+
|
49
|
+
if response.status_code != 200:
|
50
|
+
|
51
|
+
print("POST 応答エラー")
|
52
|
+
|
53
|
+
return -2
|
54
|
+
|
13
|
-
|
55
|
+
if __name__ == '__main__':
|
56
|
+
|
57
|
+
grcd1 = ['A','B']
|
58
|
+
|
59
|
+
cmdbyte1 = [4, 17, 0, 234]
|
60
|
+
|
61
|
+
try:
|
62
|
+
|
63
|
+
get_csv(grcd1, cmdbyte1)
|
64
|
+
|
65
|
+
except Exception as e01:
|
66
|
+
|
67
|
+
print("get_scv()の中に例外発生!")
|
68
|
+
|
69
|
+
print(e01)
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
```VB
|
74
|
+
|
75
|
+
Imports Newtonsoft.Json
|
76
|
+
|
77
|
+
Public Class Form1
|
78
|
+
|
79
|
+
Public Class testjson
|
80
|
+
|
81
|
+
Public Property groupcodes As String
|
82
|
+
|
83
|
+
Public Property commandbytes As String
|
84
|
+
|
85
|
+
'Public Property sikaku As String()
|
86
|
+
|
87
|
+
End Class
|
88
|
+
|
89
|
+
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
90
|
+
|
91
|
+
Dim ret As Int32
|
92
|
+
|
93
|
+
'Dim postData As String
|
94
|
+
|
95
|
+
Dim postDataBytes As Byte()
|
96
|
+
|
97
|
+
Dim req As System.Net.WebRequest
|
98
|
+
|
99
|
+
Dim reqStream As System.IO.Stream = Nothing
|
100
|
+
|
101
|
+
Dim res As System.Net.WebResponse = Nothing
|
102
|
+
|
103
|
+
Dim resStream As System.IO.Stream = Nothing
|
104
|
+
|
105
|
+
Dim sr As System.IO.StreamReader = Nothing
|
106
|
+
|
107
|
+
Try
|
108
|
+
|
109
|
+
Dim syain1 As testjson = New testjson()
|
110
|
+
|
111
|
+
syain1.groupcodes = "['A','B']"
|
112
|
+
|
113
|
+
syain1.commandbytes = "[4, 17, 0, 234]"
|
114
|
+
|
115
|
+
Dim Json As String = JsonConvert.SerializeObject(syain1)
|
116
|
+
|
117
|
+
'バイト型配列に変換
|
118
|
+
|
119
|
+
postDataBytes = System.Text.Encoding.UTF8.GetBytes(Json)
|
120
|
+
|
121
|
+
'WebRequestの作成
|
122
|
+
|
123
|
+
req = System.Net.WebRequest.Create("http://192.168.14.100:7001/testapi/sendbroadcastcommand")
|
124
|
+
|
125
|
+
'メソッドにPOSTを指定
|
126
|
+
|
127
|
+
req.Method = "POST"
|
128
|
+
|
129
|
+
'ContentTypeを"application/json"にする
|
130
|
+
|
131
|
+
req.ContentType = "application/json"
|
132
|
+
|
133
|
+
''POST送信するデータの長さを指定
|
134
|
+
|
135
|
+
req.ContentLength = postDataBytes.Length
|
136
|
+
|
137
|
+
req.Proxy = Nothing
|
138
|
+
|
139
|
+
'データをPOST送信するためのStreamを取得
|
140
|
+
|
141
|
+
reqStream = req.GetRequestStream()
|
142
|
+
|
143
|
+
'送信するデータを書き込む
|
144
|
+
|
145
|
+
reqStream.Write(postDataBytes, 0, postDataBytes.Length)
|
146
|
+
|
147
|
+
ret = 0
|
148
|
+
|
149
|
+
Catch ex As Exception
|
150
|
+
|
151
|
+
'エラーコードの設定
|
152
|
+
|
153
|
+
ret = 100
|
154
|
+
|
155
|
+
Finally
|
156
|
+
|
157
|
+
If IsNothing(reqStream) = False Then
|
158
|
+
|
159
|
+
reqStream.Close()
|
160
|
+
|
161
|
+
End If
|
162
|
+
|
163
|
+
If IsNothing(sr) = False Then
|
164
|
+
|
165
|
+
sr.Close()
|
166
|
+
|
167
|
+
End If
|
168
|
+
|
169
|
+
End Try
|
170
|
+
|
171
|
+
End Sub
|
172
|
+
|
173
|
+
End Class
|
174
|
+
|
175
|
+
```
|
3
削除希望
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
※※質問削除願います※※
|
test
CHANGED
@@ -1,19 +1,13 @@
|
|
1
|
-
PythonのコードをVBかC#に変換したいです。
|
2
|
-
|
3
|
-
目的は学習です。
|
4
|
-
|
5
|
-
Pythonコードは正常に動作している物で
|
6
|
-
|
7
|
-
|
1
|
+
回答得られない為、本質問は取りやめます。
|
8
|
-
|
9
|
-
元のPythonコードと、私が書いたVBコードを載せます。
|
10
|
-
|
11
|
-
例外エラーなどは出ず処理は一応実行できますが、動作しない状況です。
|
12
|
-
|
13
|
-
私が書いたVBコードはどこが間違えているのかご教示願いたいです。
|
14
2
|
|
15
3
|
|
16
4
|
|
17
5
|
|
18
6
|
|
7
|
+
|
8
|
+
|
9
|
+
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
|
10
|
+
|
19
|
-
|
11
|
+
コード削除
|
12
|
+
|
13
|
+
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
|
2
回答得られない為、コード削除します。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,212 +16,4 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
```Python
|
20
|
-
|
21
|
-
import requests
|
22
|
-
|
23
|
-
import json
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# csvファイル取得
|
28
|
-
|
29
|
-
def get_csv(groupcodes, commandbytes):
|
30
|
-
|
31
|
-
url = 'http://192.168.14.100:7001/testapi/sendbroadcastcommand?groupcodes={}&commandbytes={}'. format(json.dumps(groupcodes), json.dumps(commandbytes))
|
32
|
-
|
33
|
-
print(url)
|
34
|
-
|
35
|
-
headers = {
|
36
|
-
|
37
|
-
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
try:
|
42
|
-
|
43
|
-
response = requests.post(url=url, headers=headers)
|
44
|
-
|
45
|
-
except Exception as e:
|
46
|
-
|
47
|
-
print("POST 例外発生!")
|
48
|
-
|
49
|
-
print(e)
|
50
|
-
|
51
|
-
return -1
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
if response.status_code != 200:
|
56
|
-
|
57
|
-
print("POST 応答エラー")
|
58
|
-
|
59
|
-
return -2
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
if __name__ == '__main__':
|
66
|
-
|
67
|
-
grcd1 = ['A','B']
|
68
|
-
|
69
|
-
cmdbyte1 = [4, 17, 0, 234]
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
try:
|
76
|
-
|
77
|
-
get_csv(grcd1, cmdbyte1)
|
78
|
-
|
79
|
-
except Exception as e01:
|
80
|
-
|
81
|
-
print("get_scv()の中に例外発生!")
|
82
|
-
|
83
|
-
print(e01)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
```
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
```VB
|
92
|
-
|
93
|
-
Imports Newtonsoft.Json
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
Public Class Form1
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
Public Class testjson
|
102
|
-
|
103
|
-
Public Property groupcodes As String
|
104
|
-
|
105
|
-
Public Property commandbytes As String
|
106
|
-
|
107
|
-
'Public Property sikaku As String()
|
108
|
-
|
109
|
-
End Class
|
110
|
-
|
111
|
-
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
112
|
-
|
113
|
-
Dim ret As Int32
|
114
|
-
|
115
|
-
'Dim postData As String
|
116
|
-
|
117
|
-
Dim postDataBytes As Byte()
|
118
|
-
|
119
|
-
Dim req As System.Net.WebRequest
|
120
|
-
|
121
|
-
Dim reqStream As System.IO.Stream = Nothing
|
122
|
-
|
123
|
-
Dim res As System.Net.WebResponse = Nothing
|
124
|
-
|
125
|
-
Dim resStream As System.IO.Stream = Nothing
|
126
|
-
|
127
|
-
Dim sr As System.IO.StreamReader = Nothing
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
Try
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
Dim syain1 As testjson = New testjson()
|
136
|
-
|
137
|
-
syain1.groupcodes = "['A','B']"
|
138
|
-
|
139
|
-
syain1.commandbytes = "[4, 17, 0, 234]"
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
Dim Json As String = JsonConvert.SerializeObject(syain1)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
'バイト型配列に変換
|
148
|
-
|
149
|
-
postDataBytes = System.Text.Encoding.UTF8.GetBytes(Json)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
'WebRequestの作成
|
154
|
-
|
155
|
-
req = System.Net.WebRequest.Create("http://192.168.14.100:7001/testapi/sendbroadcastcommand")
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
'メソッドにPOSTを指定
|
160
|
-
|
161
|
-
req.Method = "POST"
|
162
|
-
|
163
|
-
'ContentTypeを"application/json"にする
|
164
|
-
|
165
|
-
req.ContentType = "application/json"
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
''POST送信するデータの長さを指定
|
170
|
-
|
171
|
-
req.ContentLength = postDataBytes.Length
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
req.Proxy = Nothing
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
'データをPOST送信するためのStreamを取得
|
180
|
-
|
181
|
-
reqStream = req.GetRequestStream()
|
182
|
-
|
183
|
-
'送信するデータを書き込む
|
184
|
-
|
185
|
-
reqStream.Write(postDataBytes, 0, postDataBytes.Length)
|
186
|
-
|
187
|
-
ret = 0
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
Catch ex As Exception
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
'エラーコードの設定
|
196
|
-
|
197
|
-
ret = 100
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
Finally
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
If IsNothing(reqStream) = False Then
|
206
|
-
|
207
|
-
reqStream.Close()
|
208
|
-
|
209
|
-
|
19
|
+
※コード削除
|
210
|
-
|
211
|
-
If IsNothing(sr) = False Then
|
212
|
-
|
213
|
-
sr.Close()
|
214
|
-
|
215
|
-
End If
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
End Try
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
End Sub
|
224
|
-
|
225
|
-
End Class
|
226
|
-
|
227
|
-
```
|
1
自分が行った事を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
|
1
|
+
PythonのコードをVBかC#に変換したいです。
|
2
|
+
|
2
|
-
|
3
|
+
目的は学習です。
|
4
|
+
|
3
|
-
|
5
|
+
Pythonコードは正常に動作している物で
|
6
|
+
|
7
|
+
VBコードは現在動作していない物です。
|
8
|
+
|
9
|
+
元のPythonコードと、私が書いたVBコードを載せます。
|
10
|
+
|
11
|
+
例外エラーなどは出ず処理は一応実行できますが、動作しない状況です。
|
12
|
+
|
13
|
+
私が書いたVBコードはどこが間違えているのかご教示願いたいです。
|
14
|
+
|
15
|
+
|
4
16
|
|
5
17
|
|
6
18
|
|
@@ -54,9 +66,7 @@
|
|
54
66
|
|
55
67
|
grcd1 = ['A','B']
|
56
68
|
|
57
|
-
cmdbyte1 = [4, 17, 1, 233]
|
58
|
-
|
59
|
-
cmdbyte
|
69
|
+
cmdbyte1 = [4, 17, 0, 234]
|
60
70
|
|
61
71
|
|
62
72
|
|
@@ -75,3 +85,143 @@
|
|
75
85
|
|
76
86
|
|
77
87
|
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
```VB
|
92
|
+
|
93
|
+
Imports Newtonsoft.Json
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
Public Class Form1
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
Public Class testjson
|
102
|
+
|
103
|
+
Public Property groupcodes As String
|
104
|
+
|
105
|
+
Public Property commandbytes As String
|
106
|
+
|
107
|
+
'Public Property sikaku As String()
|
108
|
+
|
109
|
+
End Class
|
110
|
+
|
111
|
+
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
112
|
+
|
113
|
+
Dim ret As Int32
|
114
|
+
|
115
|
+
'Dim postData As String
|
116
|
+
|
117
|
+
Dim postDataBytes As Byte()
|
118
|
+
|
119
|
+
Dim req As System.Net.WebRequest
|
120
|
+
|
121
|
+
Dim reqStream As System.IO.Stream = Nothing
|
122
|
+
|
123
|
+
Dim res As System.Net.WebResponse = Nothing
|
124
|
+
|
125
|
+
Dim resStream As System.IO.Stream = Nothing
|
126
|
+
|
127
|
+
Dim sr As System.IO.StreamReader = Nothing
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
Try
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
Dim syain1 As testjson = New testjson()
|
136
|
+
|
137
|
+
syain1.groupcodes = "['A','B']"
|
138
|
+
|
139
|
+
syain1.commandbytes = "[4, 17, 0, 234]"
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
Dim Json As String = JsonConvert.SerializeObject(syain1)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
'バイト型配列に変換
|
148
|
+
|
149
|
+
postDataBytes = System.Text.Encoding.UTF8.GetBytes(Json)
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
'WebRequestの作成
|
154
|
+
|
155
|
+
req = System.Net.WebRequest.Create("http://192.168.14.100:7001/testapi/sendbroadcastcommand")
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
'メソッドにPOSTを指定
|
160
|
+
|
161
|
+
req.Method = "POST"
|
162
|
+
|
163
|
+
'ContentTypeを"application/json"にする
|
164
|
+
|
165
|
+
req.ContentType = "application/json"
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
''POST送信するデータの長さを指定
|
170
|
+
|
171
|
+
req.ContentLength = postDataBytes.Length
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
req.Proxy = Nothing
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
'データをPOST送信するためのStreamを取得
|
180
|
+
|
181
|
+
reqStream = req.GetRequestStream()
|
182
|
+
|
183
|
+
'送信するデータを書き込む
|
184
|
+
|
185
|
+
reqStream.Write(postDataBytes, 0, postDataBytes.Length)
|
186
|
+
|
187
|
+
ret = 0
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
Catch ex As Exception
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
'エラーコードの設定
|
196
|
+
|
197
|
+
ret = 100
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
Finally
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
If IsNothing(reqStream) = False Then
|
206
|
+
|
207
|
+
reqStream.Close()
|
208
|
+
|
209
|
+
End If
|
210
|
+
|
211
|
+
If IsNothing(sr) = False Then
|
212
|
+
|
213
|
+
sr.Close()
|
214
|
+
|
215
|
+
End If
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
End Try
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
End Sub
|
224
|
+
|
225
|
+
End Class
|
226
|
+
|
227
|
+
```
|