为什么在接收串口通信后更改int的值? [英] Why change the value of int after receiving serial communication?

查看:71
本文介绍了为什么在接收串口通信后更改int的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的VC ++代码中,



串口发送数据到另一台电脑。



发送结构化数据如下



struct data_format {



char stx; // 0x02

int type;

int seq;

int lenth;

char data [N];

char etx; // 0x03



一次,它将数据发送到另一个部分;



stx + type(= 0 )+ seq(= 100)+ lenth(= 220)+数据....



但是在接收数据方面



stx + stype(= 0)+ seq(= 100)+ lenth(= 92)+ data ....



我确认每次发送和接收部分之间的长度值不同。(220 - > 92)



有可能吗?



我尝试了什么:



此问题浪费了3天以上

In my VC++ code,

A serial sending data to another computer.

It send a structured data like as follows

struct data_format{

char stx; // 0x02
int type;
int seq;
int lenth;
char data[N];
char etx; // 0x03

Once, it send a data to another part;

stx+ type(=0) + seq(=100) + lenth (=220) + data ....

but in the side of receiving data

stx+ stype(=0) + seq(=100) + lenth (=92) + data....

I confirmed every time that the value of lenths are different between sending and receiving part.(220 -> 92)

Is it possible?

What I have tried:

3 more days wasted for this problem

推荐答案

是的。看看值:92 + 128 == 220.这意味着它是一个七位问题。

最可能的原因是:

1)之间的通信链接这两个器件设置为每个字符7位(7 bpc),这意味着第8位在传输时被丢弃。

2)您的软件使用的字符值仅保留7位重要数据 - 当您需要 char 时,可能需要 unsigned char

3)在软件的某个地方,你掩盖最高位以防止负值。



但是如果没有你的软件,我们甚至无法开始提供帮助你修好了。
Yes. Look at the values: 92 + 128 == 220. This implies it's a seven bit problem.
The most likely reasons for this are:
1) The communications link between the two devices is set to 7 bits per char (7 bpc), which means that the eighth bit is discarded when it's transmitted.
2) Your software is using a character based value which only holds 7 bits of significant data - it may be that you are using char when you need unsigned char
3) Somewhere in your software you are "masking out" the top bit to prevent negative values.

But without your software, we can't even begin to help you fix.


这篇关于为什么在接收串口通信后更改int的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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