我能够读取一个数据从运动控制器与HTTP在MATLAB中。
MATLAB中的请求代码..。
api = 'http://192.168.0.105';
url = [api 'kas/plcvariables?variables=Velocity&format=text'];
options = weboptions('ContentType', text);
data = webread(url, options);但是,我不能用MATLAB给运动控制器写信,用数据格式"text“或"json",这不重要。我如何写到运动控制器?
json书写格式
PUT http://198.51.100.0/kas/plcvariables?format=json { "MachineSpeed"
: {"value" : "100.000000"}, " IntegerVar " : {"value" : "20"},
“UntitledST.LocalVariable” : {"value" : "’SampleString’”} }在文本中
PUT http://198.51.100.0/kas/plcvariables?format=text
MachineSpeed=100.000000,IntegerVar=20,UntitledST.LocalVariable=’SampleString’我在Matlab中尝试了一些代码,最后一个是下面的代码。
api = 'http://192.168.0.105';
url = [api 'kas/plcvariables?'];
ab = struct('value', '10000.00');
data.V = {ab};
options = webopitons('MediaType', 'application/json',
'RequestMethod', 'POST', 'ContentType', 'json');
response = webwrite(url, data, options);但他们都犯了以下同样的错误。
使用'http://192.168.0.105/kas/plcvariables?‘错误(第45行)服务器返回消息:“未找到”用于readContentFromWebService(使用HTTP代码404).
我想我不知道正确的URL地址,你能帮我如何为运动控制器写正确的URL地址吗?
发布于 2019-02-12 18:57:46
我发现在马丁的帮助下我哪里出了问题(kallmorgen.com/en-us/developer-network/…)。我为可能需要此链接的任何人共享代码,代码如下所示
int main() {
CURLcode ret;
CURL *curl_easy_handle;
curl_global_init(CURL_GLOBAL_ALL);
std::string jsonstr = "{\"Position\" : {\"value\" : \"4000\"}}";
struct curl_slist *headers;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "charset: utf-8");
curl_easy_handle = curl_easy_init();
if (curl_easy_handle == NULL) {
return 128;
}
curl_easy_setopt(curl_easy_handle, CURLOPT_URL, "http://192.168.0.105/kas/plcvariables?format=json");
curl_easy_setopt(curl_easy_handle, CURLOPT_CUSTOMREQUEST, "PUT");
curl_easy_setopt(curl_easy_handle, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl_easy_handle, CURLOPT_POSTFIELDS, jsonstr.c_str());
curl_easy_setopt(curl_easy_handle, CURLOPT_USERAGENT, "libcrp/0.1");
ret = curl_easy_perform(curl_easy_handle);
curl_easy_cleanup(curl_easy_handle);
curl_global_cleanup();
curl_easy_handle = NULL;
curl_slist_free_all(headers);
headers = NULL;
}https://stackoverflow.com/questions/47975522
复制相似问题