解决“被声明为不同种类的符号".错误 [英] Solving "redeclared as different kind of symbol" error

查看:402
本文介绍了解决“被声明为不同种类的符号".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Arduino.我正在使用Atmega1284为Lamp工作.我看到了一个示例代码,ModbusIP_ENC28J60-> Lamp.我首先编译它而未添加任何内容,但编译正确.现在,我要添加WebSocketServer,因为我希望它也可以在websocket上工作.我添加了一些必要的行,但最终出现此错误: error: 'EthernetClass Ethernet' redeclared as different kind of symbol

I'm currently working on Arduino. I'm working for Lamp using Atmega1284. I saw an example code, ModbusIP_ENC28J60 -> Lamp. I first compiled it without adding anything, it compiled properly. Now, I'm adding WebSocketServer, since I want this to work on websocket too. I added few necessary lines, but I ended up with this error: error: 'EthernetClass Ethernet' redeclared as different kind of symbol

我不了解代码有什么问题或应更改的内容.有人可以帮我吗?

I don't understand what's wrong with the code or what I should change. Can someone help me with this?

我在这里粘贴代码以供参考:

I'm pasting my code here for reference:

#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>

#include <WebSocketsServer.h>

WebSocketsServer webSocketServer = WebSocketsServer(8080);

//Modbus Registers Offsets (0-9999)
const int LAMP1_COIL = 100;
//Used Pins
const int ledPin = 9;

//ModbusIP object
ModbusIP mb;

void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) {
    switch(type) {
        case WStype_DISCONNECTED:
            Serial.println("[%u] Disconnected!\n");
            break;
        case WStype_CONNECTED:
            {
                //IPAddress ip = webSocket.remoteIP(num);
            Serial.println("[%u] Disconnected!\n");

        // send message to client
        //webSocket.sendTXT(num, "Connected");
            }
            break;
        case WStype_TEXT:
            Serial.println("[%u] got text!\n");

            // send message to client
            // webSocket.sendTXT(num, "message here");

            // send data to all connected clients
            // webSocket.broadcastTXT("message here");
            break;
        case WStype_BIN:
            Serial.println("[%u] get binary ");
            //hexdump(payload, lenght);

            // send message to client
            // webSocket.sendBIN(num, payload, lenght);
            break;
    }
}

void setup() {
    // The media access control (ethernet hardware) address for the shield
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    // The IP address for the shield
    byte ip[] = { 192, 168, 0, 120 };
    //Config Modbus IP
    mb.config(mac, ip);
    //Set ledPin mode
    pinMode(ledPin, OUTPUT);
    // Add LAMP1_COIL register - Use addCoil() for digital outputs
    mb.addCoil(LAMP1_COIL);

    webSocketServer.begin();
    webSocketServer.onEvent(webSocketEvent); 
}

void loop() {
   //Call once inside loop() - all magic here
   mb.task();

   //Attach ledPin to LAMP1_COIL register
   digitalWrite(ledPin, mb.Coil(LAMP1_COIL));

   webSocketServer.loop();
}

帮我使它工作.

推荐答案

您两次声明了以太网.而且它们是不同的.

You are declaring Ethernet twice. And they are different.

首先可能在包含文件Ethercard.h中 其次是Modbus.h

First is probably in the include file Ethercard.h Second is Modbus.h

在我通过Google在github中找到的ModbusIP_ENC28J60中,他们将以太网声明为数组.

In the ModbusIP_ENC28J60 I found in github via Google they declare Ethernet as an array.

要么重命名一个声明(例如以太vs以太网),要么取消使用一个声明.另外,考虑到源文件中的包含文件,如果只有两个冲突,我会感到惊讶.

Either rename one declaration (e.g. ether vs Ethernet) or eliminate the use of one. Also, considering the include files in your source I would be surprised if there are only two conflicts.

C课程:声明变量供函数使用,非常简单.添加其他模块时,任何名称冲突都将导致问题.如果您同意两个变量但仍在程序中,则将遭受大量的调试麻烦,因为一个函数将访问其变量,而另一个函数将拥有自己的变量,从而使任何东西都无法正常工作.

C lesson: Declaring a variable for use by a function, very straightforward. When adding additional modules any name conflicts will cause problems. If you get two variables to agree but are still in the program you will suffer massive debugging headaches because one function will access its variable while the other will have its own, resulting in nothing actually working.

返回并查看源文件(* .h).搜索以太网"变量.查看如何声明它们以及如何使用它们.最简单的解决方案是选择最新的扩展,然后将以太网更改为以太(如上所述).

Go back and look at the source files (*.h). Search for "Ethernet" variables. See how they are declared and how they are used. The simplest solution is to pick the latest addition and change Ethernet to ether (as I suggested above).

祝你好运.

这篇关于解决“被声明为不同种类的符号".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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