MikelAyani
Member
Hi there!
I just downloaded CCW v13 and wanted to play a bit with the Micro850 Simulator and its API. I have been able to modify the input variables using the XML API, just making changes in the inputs.xml file and it works as expected.
In the other hand, when I try to use the HTTP API and follow the examples in the manual, I am able to do GET requests to obtain the actual input and outputs status, but the POST request does not seem to work. I get a 200 response (OK) but the inputs are not updated in the simulator. Does anyone managed to get it work?
I leave you some Python code that can be used to test this. Just install the requests library and modify the PORT value.
I just downloaded CCW v13 and wanted to play a bit with the Micro850 Simulator and its API. I have been able to modify the input variables using the XML API, just making changes in the inputs.xml file and it works as expected.
In the other hand, when I try to use the HTTP API and follow the examples in the manual, I am able to do GET requests to obtain the actual input and outputs status, but the POST request does not seem to work. I get a 200 response (OK) but the inputs are not updated in the simulator. Does anyone managed to get it work?
I leave you some Python code that can be used to test this. Just install the requests library and modify the PORT value.
Code:
import requests
import time
# api-endpoint
PORT = 65173
URL = f"http://localhost:{PORT}/"
MAX = 2**32-1
inputs = 0
while True:
# Write inputs
inputs += 1
input_data = []
for bit in range(20):
value = True if(inputs & 2**bit) > 0 else False
input_data.append({"Name":"_IO_EM_DI_"+str(bit).zfill(2),"Value":value})
print("SENT:", inputs)
print(input_data)
r = requests.post(url=URL+"inputs", data=input_data)
print(r)
print("RECEIVED:")
r = requests.get(url=URL+"inputs")
data = r.json()
print(data)
time.sleep(1)