通过串行通信发送时,在调试和释放模式下接收的浮点数据的差异 [英] Difference in float data received in Debug and Release mode while sending it over serial communcation

查看:65
本文介绍了通过串行通信发送时,在调试和释放模式下接收的浮点数据的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在下面的代码中,我通过串行通信连续发送数据'50 .0'。但是,当值以'Debug'模式发送时,值将被接收为50.0,而在'Release'模式下,它将被接收为0.05。



How,我能解决它吗?我想使用'Release',以便我的代码执行速度更快,但却导致收到错误的数据。



 #include< fstream> 
#include< stdio.h>
#include< iostream>
#include< opencv2 / highgui / highgui.hpp>
#include< opencv2 / imgproc / imgproc.hpp>
#include" tserial.h"
#include" bot_control.h"

serial comm;

int main(int argc,char ** argv)
{
float move = 50.0;
char * cport =" COM3" ;;
comm.startDevice(cport,9600);
while(true)
{
char array [10];
sprintf(array,"%f",move);
char data [4] = {array [0],array [1],array [2],array [3]};
comm.send_array(data,strlen(data));
}
comm.stopDevice();
返回0;
}





解决方案

嗨Aditi Raj,


感谢您在这里发帖。


>>但是,当值在'Debug'模式下发送,值收到50.0,在'Release'模式下收到0.05.


如何修复。我想使用'Release',以便我的代码执行速度更快,但却导致收到错误的数据。


这听起来与我有关。


请提供有关如何传递和接收浮动数据的更多信息?您在
send_array中做了什么?


最好的问候,

Sera Yu







In the code below I am sending data '50.0' via serial communication continuously. However, when the value is send in 'Debug' mode the values are received as 50.0 and in 'Release' mode it is received as 0.05.

How, do I fix it. I want to use the 'Release' so that the execution of my code is faster but it is resulting in erroneous data being received.

#include<fstream>
#include<stdio.h>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "tserial.h"
#include "bot_control.h"

serial comm;

int main(int argc, char** argv)    
{
    float move = 50.0;
    char *cport = "COM3";
    comm.startDevice(cport, 9600);
    while (true)
    {
        char array[10];
        sprintf(array, "%f", move);
        char data[4] = { array[0], array[1], array[2], array[3] };
        comm.send_array(data, strlen(data));
    }
    comm.stopDevice();    
    return 0;
}


解决方案

Hi Aditi Raj,

thanks for posting here.

>>However, when the value is send in 'Debug' mode the values are received as 50.0 and in 'Release' mode it is received as 0.05.

How, do I fix it. I want to use the 'Release' so that the execution of my code is faster but it is resulting in erroneous data being received.

It sounds wired to me.

Please provide more information about how do you pass and receive float data? What have you done in your send_array?

Best Regards,
Sera Yu



这篇关于通过串行通信发送时,在调试和释放模式下接收的浮点数据的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆