在发送完成后加入该函数 tcdrain(ctx->s);
使用该函数将会增加发送的时间,但是接收的时间会缩短,并未真正改善。
Modbusslave 工具基本上要等待40ms后才能返回,但是modbusascii返回的快一些,工具存在bug
使用真实从站效果好一些
if (msg_type ==1) p_tv.tv_usec is 1
|
[Sep 5 2024 02:18:23]-[ascii_modbus_master.c:75->Modbus_Ascii_init] ------------------------------------------------------------------------ if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 2202 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 2381 rc is 1 length_to_read is 2 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 2441 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 2467 the last value rc = 1 modbus.c timeuse is 30476 if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 6606 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 6838 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 6899 rc is 1 length_to_read is 4 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 6925 if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 153 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 272 rc is 1 length_to_read is 2 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 338 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 364 the last value rc = 1 modbus.c timeuse is 30324 if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 1136 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 1309 rc is 1 length_to_read is 2 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 1367 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 1393 the last value rc = 1 modbus.c timeuse is 28016 if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 4300 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 4443 rc is 1 length_to_read is 2 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 4501 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 4527 the last value rc = 1 modbus.c timeuse is 30075 if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 7251 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 7386 rc is 1 length_to_read is 2 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 7445 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 7471 the last value rc = 1 modbus.c timeuse is 29885 if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 98 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 216 rc is 1 length_to_read is 2 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 285 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 312 the last value rc = 1 modbus.c timeuse is 29778 if (msg_type ==1) p_tv.tv_usec is 1 while (length_to_read != 0) p_tv.tv_usec is 0 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 1487 rc is 1 length_to_read is 5 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 1935 rc is 1 length_to_read is 2 [Sep 5 2024 02:44:30]-[ascii_modbus.c:620->_ascii_modbus_receive_msg] tv.tv_sec =0,tv.tv_usec =500000 msg_type =1 while (length_to_read != 0) p_tv.tv_usec is 500000 [Sep 5 2024 02:44:30]-[ascii_modbus.c:497->_ascii_modbus_receive_msg] ===========timeuse is 2096 rc is 1 length_to_read is 8 [Sep 5 2024 02:44:30]-[ascii_modbus.c:649->_ascii_modbus_receive_msg] timeuse is 2126 the last value rc = 1 modbus.c timeuse is 28711 if (msg_type ==1) p_tv.tv_usec is 1 |