Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
Arduino buf[i]返回8位最大值,即255,而不是发送的字符_Arduino_Buffer_Wireless_Transmission - Fatal编程技术网

Arduino buf[i]返回8位最大值,即255,而不是发送的字符

Arduino buf[i]返回8位最大值,即255,而不是发送的字符,arduino,buffer,wireless,transmission,Arduino,Buffer,Wireless,Transmission,我很难理解我在Arduino装置中得到了什么 情况是: 我使用运行virtualwire的芯片组将字符A(可以是任何字符)从TX板发送到RX板。RX正在接收消息,缓冲区长度为1。当我在串行监视器上打印buf[I]时,我得到255(这是我假定的8位最大整数),而不是字符A。以下是相关代码: TX文件 [守则] 无效设置(){ c='A';//仅用于测试 //无线代码…TX上的数据引脚连接到端口7…vw代表“virtualwire” vw_设置(2000);//初始化发送传输速率 vw_set_tx

我很难理解我在Arduino装置中得到了什么

情况是: 我使用运行virtualwire的芯片组将字符A(可以是任何字符)从TX板发送到RX板。RX正在接收消息,缓冲区长度为1。当我在串行监视器上打印buf[I]时,我得到255(这是我假定的8位最大整数),而不是字符A。以下是相关代码:

TX文件 [守则] 无效设置(){

c='A';//仅用于测试

//无线代码…TX上的数据引脚连接到端口7…vw代表“virtualwire”

vw_设置(2000);//初始化发送传输速率 vw_set_tx_引脚(7);//声明用于变送器数据的arduino引脚

void循环(){

。。。 vw_send((uint8_t*)c,1);//打开蜂鸣器……发送字符

接收文件

//RX数据引脚为8

void循环(){

Serial.println(“循环”);
延迟(2000年);
uint8\u t buflen=VW\u MAX\u MESSAGE\u LEN;//定义消息的最大长度
uint8_t buf[buflen];//创建保存数据的数组;定义保存消息的缓冲区
if(vw_have_message()==1)//virtualwire library Recommension添加的语句,作为下面get_message语句之前要使用的三条语句之一//不在原始HumanHardDrive代码中
{
Serial.println(“已收到消息”);
}
如果(vw_get_message(buf,&buflen))/&buflen是接收到的消息的实际长度,则消息被放置在缓冲区“buf”中
{
Serial.print(“buflen from&buflen=”);
Serial.println(buflen);//打印出从上述&buflen导出的缓冲区长度
for(int i=0;iSerial.println(i);问题可能是:

vw_send((uint8_t*)c,1);

c
不是指针,您正在传递
'a'
的值作为指针位置,然后由
vw\u send
读取。您需要操作员的地址:

vw_发送((uint8_t*)&c,1);


如果出现以下情况,也会出现冗余:
if(vw_get_message(buf,&buflen))
未嵌套在
if(vw_have_message()==1)
中,因此无论事实如何运行
vw_have_message()
可能并不总是返回
1

Serial.println("Looping");
delay(2000);

uint8_t buflen = VW_MAX_MESSAGE_LEN;// Defines maximum length of message
uint8_t buf[buflen]; // Create array to hold the data; defines buffer that holds the message

if(vw_have_message() == 1) // Satement added by virtualwire library recommendation as one of three statements to use before the get_message statement below// not in original HumanHardDrive code
{
  Serial.println("Message has been received");
}

if(vw_get_message(buf, &buflen)) // &buflen is the actual length of the received message; the message is placed in the buffer 'buf'

{
  Serial.print("buflen from &buflen = ");
  Serial.println(buflen); // Print out the buffer length derived from the &buflen above

  for(int i = 0;i < buflen;i++)
  {
    Serial.print("i = ");
    Serial.println(i);             <--prints 0
    Serial.print(" buf[0] = ");    
    Serial.print(buf[0]);          <--prints 255  
    Serial.print("   buf[i] = ");
    Serial.println(buf[i]);        <--prints 255


    if(buf[i] == 'A')  <-- Does not recognize A since buf[i] comes out as 255