首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部分输出打印libmodbus函数输出

部分输出打印libmodbus函数输出
EN

Stack Overflow用户
提问于 2019-02-04 15:39:55
回答 1查看 62关注 0票数 0

我正在使用libmodbus 3.1.2编写应用程序。我无法打印modbus函数的完整输出。另外,我在输出中得到了一些无用的值。请提个建议。

代码语言:javascript
复制
 printf("================Sending  Sample delay command==============\n");
  i32_read_ret = modbus_read_registers(ctx, 164, 1, sample_delay);
  printf("\nSample delay result:%d\n", i32_read_ret);
  printf("\n Sample delay : \n");
  for (i = 0; i < 40; i++) //printing only the received characters
  {
    printf(" : %.2x \t", (int)( * (unsigned char * )( & sample_delay[i])));

  }
  printf("\n\n\n");

  tcflush(fd, TCIOFLUSH);
  printf("================Sending  measurement command==============\n");

  i32_read_ret = modbus_write_registers(ctx, 1, 5, measurement);
  printf("\nMeasurement result : %d \n", i32_read_ret);
  for (i = 0; i < 40; i++) {
    printf(": %.2x \t", (int)( * (unsigned char * )( & measurement[i])));

  }
  printf("\n");
  tcflush(fd, TCIOFLUSH);
  printf("================Sending  actual measurement command==============\n");
  i32_read_ret = modbus_read_registers(ctx, 83, 10, actual_measurement);
  printf("\nRead Return actual_measurement 3:%d\n\n\n", i32_read_ret);

  for (i = 0; i < 40; i++) //printing only the received characters
  {
    printf(" : %.2x \t", (int)( * (unsigned char * )( & actual_measurement[i])));

  }
  printf("\n");
  printf("%s\n", actual_measurement);
  tcflush(fd, TCIOFLUSH);

o/p

代码语言:javascript
复制
================Sending  Sample delay command==============
[28][03][00][A4][00][01][C2][10]
Waiting for a confirmation...
<28><03><02><01><2C><E5><CF>

Sample delay result:1

 Sample delay : 
 : 2c    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 08    : 08    : 80    : 00    : 38    : 00    : 29    : 00    : 00    : 00    : c8    : 7d    : 01    : 00    : 00    : 00    : 30    : 00    : 00    : 00   


================Sending  measurement command==============
[28][10][00][01][00][05][0A][B1][D8][77][1E][B1][D8][77][1E][0D][F8][9F][E7]
Waiting for a confirmation...
<28><10><00><01><00><05><56><33>

Measurement result : 5 
: d8    : 1e    : d8    : 1e    : f8    : 00    : 65    : 57    : 70    : 00    : 10    : 02    : 65    : 57    : 7c    : 00    : 00 : 04   : 01    : 00    : 49    : 01    : 31    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00 : 00   : 00    : 00    : 00    : 00    : 00    
================Sending  actual measurement command==============
[28][03][00][53][00][0A][32][25]
Waiting for a confirmation...
<28><03><14><41><DD><8E><59><00><00><00><00><00><00><00><00><46><1C><34><00><46><1C><34><00><48><84>

Read Return actual_measurement 3:10


 : dd    : 59    : 00    : 00    : 00    : 00    : 1c    : 00    : 1c    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 00    : 08    : 1b    : 31    : 00    : 28    : 00    : 08    : 00    : 01    : 00    : 00    : 00    : 00    : 00    : 20    : 07    : 00    : 00    : 20    : 07   
�AY�
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-04 19:11:01

更正printf行后,问题得到解决。

代码语言:javascript
复制
for(i=0;i<i32_read_ret;i++)
{
   printf("%X",sample_delay[i]);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54511859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档