Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Windows或Linux编译的Arduino草图执行不同的操作_Linux_Compiler Construction_Serial Port_Arduino - Fatal编程技术网

从Windows或Linux编译的Arduino草图执行不同的操作

从Windows或Linux编译的Arduino草图执行不同的操作,linux,compiler-construction,serial-port,arduino,Linux,Compiler Construction,Serial Port,Arduino,我有一个非常奇怪的问题,如果从WindowsXPHomeSP3或初级操作系统Luna(UbuntuLinux的发行版)编译并上传到Arduino,草图的性能会有所不同 这个草图,除其他外,从串行连接(蓝牙)读取一个字节,并将其写回串行监视器 这就是我从WinXP编译草图时得到的结果:我通过BT连接字符串从“1”发送到“7”,每次发送一次。这些字符串的ASCII码减少为48,以字节形式转换字符串。结果是正确的,指针数组中的函数也被正确调用。 这是我从Linux得到的。我将从“1”到“7”的每个字

我有一个非常奇怪的问题,如果从WindowsXPHomeSP3或初级操作系统Luna(UbuntuLinux的发行版)编译并上传到Arduino,草图的性能会有所不同

这个草图,除其他外,从串行连接(蓝牙)读取一个字节,并将其写回串行监视器

这就是我从WinXP编译草图时得到的结果:我通过BT连接字符串从“1”发送到“7”,每次发送一次。这些字符串的ASCII码减少为48,以字节形式转换字符串。结果是正确的,指针数组中的函数也被正确调用。

这是我从Linux得到的。我将从“1”到“7”的每个字符串发送了4次,以查看结果与我需要获取的内容无关,也与相同的输入数据不一致:例如,当我发送字符串“2”时,我得到104 106 104。。。。。同一字节106由来自BT的不同字符串写入。 此外,未调用这些函数,因此这意味着这不是串行打印问题

我确信这是一个编译问题,因为一旦草图上传到Arduino中,如果我在WinXP或Linux中使用串行监视器,它将以相同的方式执行(正确与否)

这是草图

#include "Arduino.h"
#include <SoftwareSerial.h>
#include <Streaming.h>
#define nrOfCommands 10

typedef void (* CmdFuncPtr) (); // this is a typedef to command functions

//the following declares an arry of 10 function pointers of type DigitFuncPtr 
CmdFuncPtr setOfCmds[nrOfCommands] = {
  noOp,
  leftWindowDown,
  leftWindowUp,
  bootOpen,
  cabinLightOn,
  cabinLightOff,
  lockOn,
  lockOff,
  canStart,
  canStop
};


#define cmdLeftWindowDown 1
#define cmdLeftWindowUp 2
#define cmdBootOpen 3
#define cmdCabinLightOn 4
#define cmdCabinLightOff 5
#define cmdLockOn 6
#define cmdLockOff 7
#define cmdCanStart 8
#define cmdCanStop 9

#define buttonPin  4     // the number of the pushbutton pin
#define bluetoothTx 2
#define bluetoothRx 3

int buttonState = 0;         // variable for reading the pushbutton status
int androidSwitch=0;

byte incomingByte;  // incoming data
byte msg[12];
byte msgLen=0;
byte msgIdMsb=0;
byte msgIdLsb=0;

//const byte cmdLeftWindowDown;

SoftwareSerial bluetooth(bluetoothTx,bluetoothRx);

void setup()
{
  //Setup usb serial connection to computer
  Serial.begin(115200);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(115200);
  //bluetooth.print("$$$");

  randomSeed(analogRead(10));
  delay(100);
  //bluetooth.println("U,9600,E");
  //bluetooth.begin(9600);
  //time=0;
}

void loop() {
  msgIdLsb=random(1,255);
  msgIdMsb=random(0,5);
  msg[0]=msgIdMsb;
  msg[1]=msgIdLsb;
  msgLen=random(9);
  msg[2]=msgLen;

  for (int x=3;x<msgLen+3;x++) {
    msg[x]=random(255);
  }

  for (int x=3+msgLen;x<11;x++) {
    msg[x]=0;
  }
  msg[11]='\n';
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  if ((buttonState == HIGH)||(androidSwitch==HIGH)) {  
    for (int x=0;x<12;x++) {
      Serial<<msg[x]<<" ";
      bluetooth.write(uint8_t(msg[x]));
    }
    Serial<<endl;

  }

  //Read from bluetooth and write to usb serial
  if(bluetooth.available())
  {
    incomingByte = bluetooth.read()-48;
    Serial<<incomingByte<<endl;
    if (incomingByte<nrOfCommands)
      setOfCmds[incomingByte]();

  }

  delay(10);
}

void noOp(void)
{
  Serial<<"noOp"<<endl;
};

void leftWindowDown(void)
{
  Serial<<"leftWindowDown"<<endl;
};

void leftWindowUp(void)
{
  Serial<<"leftWindowUp"<<endl;
};

void bootOpen(void)
{
  Serial<<"bootOpen"<<endl;
};

void cabinLightOn(void)
{
  Serial<<"cabinLightOn"<<endl;
};

void cabinLightOff(void)
{
  Serial<<"cabinLightOff"<<endl;
};

void lockOn(void) 
{
  Serial<<"lockOn"<<endl;
};

void lockOff(void)
{
  Serial<<"lockOff"<<endl;
};

void canStart(void)
{
  androidSwitch=HIGH;
};

void canStop(void)
{
  androidSwitch=LOW;
};
#包括“Arduino.h”
#包括
#包括
#定义nrOfCommands 10
typedef void(*CmdFuncPtr)(;//这是一个用于命令函数的typedef
//下面声明了一个包含10个DigitFuncPtr类型函数指针的数组
CmdFuncPtr setOfCmds[nRofCommand]={
努普,
左窗向下,
左窗向上,
打开靴子,
卡宾莱顿,
驾驶室照明,
洛克,
封锁,,
可以开始,
能阻止
};
#定义cmdLeftWindowDown 1
#定义cmdLeftWindowUp 2
#定义cmdBootOpen 3
#定义cmdCabinLightOn 4
#定义cmdCabinLightOff 5
#在6上定义cmdlock
#定义CMD锁定7
#定义cmdCanStart 8
#定义cmdCanStop 9
#定义按钮4//按钮销的编号
#定义bluetoothTx 2
#定义bluetoothRx 3
int buttonState=0;//用于读取按钮状态的变量
int androidSwitch=0;
字节输入字节;//传入数据
字节msg[12];
字节msgLen=0;
字节msgIdMsb=0;
字节msgIdLsb=0;
//常量字节cmdLeftWindowDown;
软件串行蓝牙(bluetoothTx、bluetoothRx);
无效设置()
{
//设置与计算机的usb串行连接
序列号开始(115200);
//设置与android的蓝牙串行连接
蓝牙。开始(115200);
//bluetooth.print(“$$”);
随机种子(模拟阅读(10));
延迟(100);
//bluetooth.println(“U,9600,E”);
//蓝牙开始(9600);
//时间=0;
}
void循环(){
msgIdLsb=随机(1255);
msgIdMsb=随机(0,5);
msg[0]=msgIdMsb;
msg[1]=msgIdLsb;
msgLen=随机(9);
msg[2]=msgLen;

对于(int x=3;x我想您正在使用arduino ide;如果不是,以下一些可能不适用

首先,找出ide编译和链接代码时使用的生成目录的位置。[一种方法是在编译期间临时打开详细输出。(单击文件,首选项,“在编译期间显示详细输出”。)单击“验证”按钮编译代码,并查看第一行输出中-o选项后面的路径。]例如,在Linux系统上,生成目录路径可能类似于
/tmp/build38771126492387157498.tmp
。在该目录中,查找编译期间创建的.cpp文件

在两个系统上找到草图的.cpp文件后,将它们复制到一个系统上,以便比较它们并检查差异。如果它们不同,则一个或另一个ide可能已损坏,或者可能出现不正确的包含

如果.cpp文件不同,请比较编译标志、头文件等。我认为两个系统上的标志和AVR头文件应该相同,但MSW文件可能在换行符之后有回车符。同时检查gcc版本。[我没有MSW系统可以尝试,但我假设两个系统都使用gcc进行AVR交叉编译。如果我错了,请纠正我。]

如果.cpp文件匹配,则测试生成的二进制文件以找出它们的不同之处。(例如,如果草图文件是
Blink21x.ino
,如果两个系统上都有.elf文件,则二进制文件可能是
Blink21x.cpp.elf
Blink21x.cpp.hex
)[我不知道MSW系统是否会生成.elf]在Linux系统上使用
avr objdump
生成反汇编版本的代码:

avr-objdump -d Blink21x.cpp.elf > Blink21x.cpp.lst
然后使用
diff
查找两个反汇编文件之间的差异。如果差异是由于源代码的编译方式造成的,而不是库中的差异,则.lst文件中有足够的信息来标识源代码行。(在后一种情况下,.lst文件中提供了足够的信息,以确定哪些库例程不同。)


如果MSW系统上没有.elf文件,您可以尝试比较.hex文件。从差异的位置可以找到Linux system.elf反汇编文件中的相关行,并从中可以识别代码行或库例程。

验证您在这两种情况下使用的是相同的BT发射机。您的输出f“SerialYou Tested Replacement”SerialI强烈建议取消输入的Boung。是的,我也尝试了打印(ln)方法,但没有成功。是的,我使用的是同一个发射机。也闻到UTF问题,但不知道如何澄清。目前,我通过安装最新的Arduino IDE版本(见下文)进行了修复。你能提供一个关于如何从串行传输中消除输入的示例吗?这对于其他目的来说可能很有趣。上面的评论有一个指向库的GITHUB的链接,带有示例。感谢对jwpat7的支持。我“发现”在Linux下,最新的Arduino IDE不是通过软件中心部署的(我有rel.1.0)所以我从Arduino网站(re.1.0.5)下载了最新版本