English 中文(简体)
如何在序列上发送浮标
原标题:How to send float over serial
最佳回答
问题回答

页: 1 如何做到这一点:

void send_float (float arg)
{
  // get access to the float as a byte-array:
  byte * data = (byte *) &arg; 

  // write the data to the serial
  Serial.write (data, sizeof (arg));
}

使用Firmata 礼宾。 投票:

Firmata is a generic protocol for communicating with microcontrollers from software on a host computer. It is intended to work with any host computer software package. Right now there is a matching object in a number of languages. It is easy to add objects for other software to use this protocol. Basically, this firmware establishes a protocol for talking to the Arduino from the host software. The aim is to allow people to completely control the Arduino from software on the host computer.

你们需要研究的词汇是“航空化”。

这在序列连接上是一个令人感兴趣的问题,可能会限制能够终止的特性,并且可能无法通过8个轨道。

对某些性质代码的限制相当普遍。 这里有几处 off子:

  • 如果软件流动控制正在使用,那么,通常情况下,DC1和DC3(Ctrl-Q和Ctrl-S,有时也称作XON和XOFF)的控制特性不能作为数据传输,因为它们被送往电缆另一端开始并停止发送。

  • 在某些装置上,国家不动产和/或衍生物特性(0x00和0x7F)可能只是从国际不动产业的接收者那里消失。

  • 如果接收人是“不满意”的,而且术语的使用方式没有正确确定,那么Ctrl-D(EOT或0x04)的特性就可导致“真实”的动因向,向程序发出“最后”的信号。

序列连接通常可以预示,可能包括平价比。 某些联系要求采用7轨制的对等制,而不是8轨制。 甚至有可能连接(非常老的)遗留的硬件,以没收5比特和6比特的许多序列港口。 如果每批提供不到8个轨道,则需要一个更为复杂的程序来处理双轨数据。

ASCII85是围绕7-bit数据和管制特性限制开展工作的一种常用技术。 它是一种只使用85种经过仔细选择的ASCII特性代码重写双倍数据的公约。

此外,你当然必须担心发交人和收受人之间的定购。 你们可能还必须担心浮动点格式,因为并不是每个系统都使用EPC-754浮动点。

底线是,选择纯的ASCII议定书常常是更好的答案。 它具有人类能够理解的优势,并且更能抵制与序列连接有关的问题。 除非你寄送浮点数据,否则,通过易于执行,代表的低效率可能会超过。

在你们接受的东西方面,也就你们所说的话保守。

规模是否重要? 如果是的话,请将每32个比照小组编码为5个ASCII特性,使用ASCII85,见

或许这是将Float改为拜特和拜特改为Float、Hamid Reza的最佳办法。

int breakDown(int index, unsigned char outbox[], float member)
{
  unsigned long d = *(unsigned long *)&member;

  outbox[index] = d & 0x00FF;
  index++;

  outbox[index] = (d & 0xFF00) >> 8;
  index++;

  outbox[index] = (d & 0xFF0000) >> 16;
  index++;

  outbox[index] = (d & 0xFF000000) >> 24;
  index++;
  return index;
}


float buildUp(int index, unsigned char outbox[])
{
  unsigned long d;

  d =  (outbox[index+3] << 24) | (outbox[index+2] << 16)
    | (outbox[index+1] << 8) | (outbox[index]);
  float member = *(float *)&d;
  return member;
}

regards. `

结构和工会解决这一问题。 采用一种包裹结构,并配对结构。 超越了结构和工会(或增加结构中的工会)。 利用Serial.write发送溪流。 在收尾时有配对结构。 只要按批发令不配问题,你就能够利用“C” hto(s.l)的功能进行包装。 添加“标题”信息,以编码不同的结构/单位。

Arduino IDE:

float buildUp(int index, unsigned char outbox[])
{
  unsigned long d;
 d = (long(outbox[index +3]) << 24)  |   
     (long(outbox[index +2]) << 16) |   
     (long(outbox[index +1]) << 8)  |   
     (long(outbox[index]));
 float member = *(float *)&d;
 return member;
}

否则不工作。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?