diff --git a/schunk_egu_egk_gripper_dummy/src/dummy.py b/schunk_egu_egk_gripper_dummy/src/dummy.py index b9298bf..c84844b 100644 --- a/schunk_egu_egk_gripper_dummy/src/dummy.py +++ b/schunk_egu_egk_gripper_dummy/src/dummy.py @@ -31,7 +31,7 @@ def process_get(self, path: str, query: dict[str, list[str]]) -> dict | list | N print(f"query: {query}") if path == "info.json": - return {} + return {"dataformat": 0} # 0: Little endian, 1: Big endian if path == "enum.json": return [] if path == "data.json": diff --git a/schunk_egu_egk_gripper_dummy/tests/test_dummy.py b/schunk_egu_egk_gripper_dummy/tests/test_dummy.py index fd7808a..0523fb7 100644 --- a/schunk_egu_egk_gripper_dummy/tests/test_dummy.py +++ b/schunk_egu_egk_gripper_dummy/tests/test_dummy.py @@ -25,7 +25,7 @@ def test_dummy_responds_correctly_to_info_requests(): dummy = Dummy() path = "info.json" query = "" - expected = {} + expected = {"dataformat": 0} assert dummy.process_get(path, query) == expected diff --git a/schunk_egu_egk_gripper_library/include/schunk_egu_egk_gripper_library/communication.hpp b/schunk_egu_egk_gripper_library/include/schunk_egu_egk_gripper_library/communication.hpp index 0fc2040..469d725 100644 --- a/schunk_egu_egk_gripper_library/include/schunk_egu_egk_gripper_library/communication.hpp +++ b/schunk_egu_egk_gripper_library/include/schunk_egu_egk_gripper_library/communication.hpp @@ -171,6 +171,7 @@ class AnybusCom void initAddresses(); std::string ip; //IP to the connected gripper + int port = 80; //TCP/IP Port of the gripper uint8_t endian_format; //Flag for big/little Endian bool not_double_word; //Flag if double word is requested (double words are always big Endian) @@ -266,6 +267,7 @@ inline void AnybusCom::getWithInstance(const char inst[7], paramtype *param, con curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1L); + curl_easy_setopt(curl, CURLOPT_PORT, port); res = curl_easy_perform(curl); if (res != CURLE_OK) @@ -302,6 +304,7 @@ inline void AnybusCom::getWithOffset(const std::string &offset, const size_t & c curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, writeCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1); + curl_easy_setopt(curl, CURLOPT_PORT, port); res = curl_easy_perform(curl); diff --git a/schunk_egu_egk_gripper_library/src/communication.cpp b/schunk_egu_egk_gripper_library/src/communication.cpp index de50abc..026906f 100644 --- a/schunk_egu_egk_gripper_library/src/communication.cpp +++ b/schunk_egu_egk_gripper_library/src/communication.cpp @@ -37,7 +37,7 @@ size_t writeCallback(void* contents, size_t size, size_t nmemb, void* userp) } //Initialize the plcs and Addresses -AnybusCom::AnybusCom(const std::string &ip, int port) : ip(ip) +AnybusCom::AnybusCom(const std::string &ip, int port) : ip(ip), port(port) { initAddresses(); // for post and get curl = curl_easy_init(); @@ -172,20 +172,12 @@ void AnybusCom::postParameter(std::string inst, std::string value) //Inits used Addresses with the ip void AnybusCom::initAddresses() { - data_address = "http:///adi/data.json?"; - update_address = "http:///adi/update.json"; - enum_address = "http:///adi/enum.json?"; - info_address = "http:///adi/info.json"; - metadata_address = "http:///adi/metadata.json?"; - if(ip.size() >= 100) ip = "0.0.0.0"; - - data_address.insert(7, ip); - update_address.insert(7, ip); - enum_address.insert(7,ip); - info_address.insert(7,ip); - metadata_address.insert(7,ip); - + data_address = "http://" + ip + ":" + std::to_string(port) + "/adi/data.json?"; + update_address = "http://" + ip + ":" + std::to_string(port) + "/adi/update.json"; + enum_address = "http://" + ip + ":" + std::to_string(port) + "/adi/enum.json?"; + info_address = "http://" + ip + ":" + std::to_string(port) + "/adi/info.json"; + metadata_address = "http://" + ip + ":" + std::to_string(port) + "/adi/metadata.json?"; } //Translates the received string of double_word to an integer[4] an saves it in plc_sync_input @@ -271,6 +263,7 @@ void AnybusCom::getEnums(const char inst[7], const uint16_t &enumNum) curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 1L); + curl_easy_setopt(curl, CURLOPT_PORT, port); res = curl_easy_perform(curl);