(Новая страница: «<pre> Sub WriteValue() Cells(1, 9) = "Writing..." Dim Client As New WebClient Client.BaseUrl = "http://192.168.1.1/api" Dim Request As New We…»)
Application.Wait (Now + TimeValue("00:00:01")) ' Need to wait for PLC to be updated
+
Call GetRegisters
Else
Else
' Error, display error
' Error, display error
−
Cells(1, 9) = "ERROR"
+
Cells(2, 10) = "ERROR: " + Response.Content
−
+
End If
End If
+
End Sub
End Sub
</pre>
</pre>
Текущая версия на 08:27, 12 апреля 2018
Sub WriteValue()
Cells(1, 9) = "Writing..."
Dim Client As New WebClient
Client.BaseUrl = "http://192.168.1.1/api"
Dim Request As New WebRequest
Request.Resource = "register-values/{Id}"
Request.Method = WebMethod.HttpPut
Request.RequestFormat = WebFormat.JSON
Request.ResponseFormat = WebFormat.JSON
Request.AddBodyParameter "value", Cells(2, 7)
Request.AddUrlSegment "Id", Cells(1, 7)
Request.AddHeader "X-WH-APIKEY", "8DA00F5F9B42A8D070651C58F495DB1C3191AF19"
Dim Response As WebResponse
Set Response = Client.Execute(Request)
If Response.StatusCode = WebStatusCode.Ok Then
' Success
Cells(2, 10) = "OK"
Application.Wait (Now + TimeValue("00:00:01")) ' Need to wait for PLC to be updated
Call GetRegisters
Else
' Error, display error
Cells(2, 10) = "ERROR: " + Response.Content
End If
End Sub