完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我将 ESP-01 板作为 STA MODE(站)连接到路由器 WIFI(接入点)。
我在互联网上发现了有趣的库 (settimino.h) 允许我们连接 ESP 和 PLC。 我通过以太网电缆将 S7-1200 连接到此路由器,并在 PLC 端启用了可访问选项 PUT-GET 通信。 当 ESP 尝试调用 DB 读取函数时,ESP 复位。我不知道为什么。有人有同样的问题吗? 我在下面展示了所有代码和 ESP 调试器的一些屏幕。问题是什么?! 代码:全选/* ESP8266 Blink by Simon Peter Blink the blue LED on the ESP-01 module This example code is in the public domain The blue LED on the ESP-01 module is connected to GPIO1 (which is also the TXD pin; so we cannot use Serial.print() at the same time) Note that this sketch uses LED_BUILTIN to find the pin with the internal LED */ // Wifi -> #define S7WIFI // Cable -> #define S7WIRED #define S7WIFI #include #include "Settimino.h" // byte mac[] = { 0xE0, 0xDC, 0xA0, 0xE3, 0xF3, 0x3C }; char* ssid = "SteviaAutomation_2.4G"; char* password = "Stevia\"Automation\"!"; IPAddress ip(192,168,1,99); // Local Address IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0); IPAddress PLC(192,168,1,199); // PLC Address byte Buffer[512]; S7Client * Client = new S7Client(); unsigned long Elapsed; // To calc the execution time void setup() { Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } // Start the WiFi Library WiFi.mode(WIFI_STA); WiFi.config(ip, gateway, subnet); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println(WiFi.localIP()); } bool Connect() { int Result=Client->ConnectTo(PLC, 0, // Rack (see the doc.) 0); // Slot (see the doc.) Serial.print("Connecting to ");Serial.println(PLC); if (Result==0) { Serial.print("Connected ! PDU Length = "); Serial.println(Client->GetPDULength()); } else Serial.println("Connection error"); return Result==0; } void CheckError(int ErrNo) { Serial.print("Error No. 0x"); Serial.println(ErrNo, HEX); // Checks if it's a Server Error => we need to disconnect if (ErrNo & 0x00FF) { Serial.println("SERVER ERROR, disconnecting."); Client->Disconnect(); } } byte ReadDB(int StartAddress) // get specific bytes from SIMATIC DB block { int Result; byte Receive; // Connecting... while (!Client->Connected) { if (!Connect()) delay(500); } // call read area from SIMATIC Result=Client->ReadArea(S7AreaDB, // DB identifier 2, // DB Number = 53 StartAddress, // Start Address 1, // Number of bytes to read &Receive); // Pointer to Destination Area // data overwriting (for simulation purposes) //Result = 0; //Receive = 0x00; if (Result==0) { return Receive; } else CheckError(Result); } void loop() { Serial.print("Data from the PLC: "); Serial.println(ReadDB(2)); // Read one byte from the 2.0 start address Serial.println(""); delay(500); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
598 浏览 1 评论
552浏览 6评论
461浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
443浏览 5评论
445浏览 4评论
415浏览 4评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 02:52 , Processed in 0.709055 second(s), Total 75, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号