Simulink TCP/IP Client Receive模块无法接收C++发送的数据求助
问题:C++ TCP发送数据至Simulink TCP/IP Client Receive模块无法接收
我需要把C++程序的数据通过TCP发送到Simulink做后续处理,先在本机测试,之后计划跨设备传输。使用Simulink的TCP/IP Client Receive模块接收数据,但该模块始终无法接收到数据。
通过Wireshark验证,C++程序已成功发送数据。先后尝试发送包含3个逗号分隔坐标的字符串、单个double类型数据,均无法被Simulink接收,模块状态始终为False。怀疑是Simulink模块的datasize属性配置有误,但对该属性的含义理解模糊,官方文档说明不够清晰。
C++连接代码片段
// Initialize the endpoint to the loopback IP address and a specific port number remote_endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 9999); std::cout << "Socket opened successfully" << std::endl; std::cout << "Connecting to: " << remote_endpoint.address() << ":" << remote_endpoint.port() << std::endl; try { tcp_socket.connect(remote_endpoint); } catch (const boost::system::system_error& e) { std::cout << "Failed to connect: " << e.what() << std::endl; } //tcp_socket.connect(remote_endpoint); std::cout << "Connected successfully" << std::endl;
发送的逗号分隔字符串示例
975000,518.000000,287.000000 980000,518.000000,287.000000 985000,518.000000,287.000000 990000,518.000000,287.000000 995000,518.000000,287.000000
Simulink配置
Simulink配置截图包含两个页面:模块参数配置页、数据类型配置页
更新:发送double类型数据的代码
// Pack the timestamp into a double double data = static_cast<double>(ts); // Print the timestamp std::cout << "Timestamp: " << data << std::endl; // Send the data over TCP boost::system::error_code error; boost::endian::big_to_native_inplace(data); boost::asio::write(tcp_socket, boost::asio::buffer(&data, sizeof(data)), error); // Error handling if(!error) { std::cout << "Data sent successfully!" << std::endl; } else { std::cout << "Send failed: " << error.message() << std::endl; }
希望能得到排查该问题的思路和方法。
内容的提问来源于stack exchange,提问作者VEGETAO9000
相关产品推荐
相关产品推荐

