我正在尝试在 PLC(WAGO 750-8101)和 Arduino(UNO)之间交换数据,PLC 作为主机,Arduino 作为从机,但似乎无法连接。
对于 Arduino,我有一个 MINI ENC28J60 作为网络模块,并像这样连接到 arduino:
SCK - 引脚 13,SO - 引脚 12,SI - 引脚 11,CS - 引脚 10
VCC:3.3V
对于 arduino,我正在使用这些库:
主设置
SendRequest : WagoAppPlcModbus.FbMbMasterTcp := ( xConnect := TRUE,
sHost:= '192.168.1.88',
wPort:=502,
utKeepAlive:= ( xEnable :=TRUE,
tMaxIdleTime := T#5S,
tInterval:= T#2S,
udiProbes:=5),
eFrameType := eMbFrameType.ETHERNET,
tTimeOut:= T#30S);
utQuery: typMbQuery := ( bUnitId := 88, // slave ID,
bFunctionCode:=16#4, // analog input registers
uiReadAddress:= 0,
uiReadQuantity:=2,
uiWriteAddress:=0,
uiWriteQuantity:=0,
awWriteData:= [124(0)]);
xTxTrigger : BOOL;
utResponse : typMbResponse;
TimerForRequest : TON := (PT := T#5S);
HeartRate: WORD;
AirQuality : WORD;
HentSensorData : BOOL;
和主要代码:
//TimerForRequest(IN:=HentSensorData);
//xTxTrigger S= TimerForRequest.Q;
SendRequest( utQuery := utQuery,
xTrigger := HentSensorData, //a toggle switch on HMI
utResponse := utResponse);
HeartRate := utResponse.awData[0];
AirQuality := utResponse.awData[1];
从站设置(arduino):
#include <EtherCard.h>
#include <ModbusIP_ENC28J60.h>
#include <Modbus.h>
const int HeartBeat = 0;
const int Oxygen = 1;
ModbusIP mb;
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, 1, 88 };
byte dns[] = { 192, 168, 1, 1 };
byte gw[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
Serial.begin(9600);
Serial.println("DEBUG");
Serial.println();
//Config Modbus IP
mb.config(mac, ip, dns, gw, subnet);
Serial.println("Modbus com. setup done");
Serial.println();
Serial.println("SLAVE SETTINGS");
ether.printIp("IP: ",ether.myip);
ether.printIp("DNS: ", ether.dnsip);
//ether.printIp("GW: ",ether.gwip); ether.printIp("Mask: ",
ether.mymask);
Serial.println();
// Add SENSOR_IREG register - Use addIreg() for analog Inputs
mb.addIreg(HeartBeat);
Serial.print("HeartBeatSensor added at address: ");
Serial.println(HeartBeat);
mb.addIreg(Oxygen);
Serial.print("OxygenSensor added at address: ");
Serial.println(Oxygen);
}
void loop() {
//Call once inside loop() - all magic here
mb.task();
//Testcode
for(int i=0;i<400; i++)
{
mb.Ireg(HeartBeat, i);
mb.Ireg(Oxygen,i+2000);
Serial.println(i);
delay(2000);
}
}
输出(调试)从站:
我能够在 PLC 和 Modbus Slave 模拟器之间建立连接(并交换数据),但是当我尝试连接 arduino 时,我似乎无法建立连接。
这是我在 PLC 中遇到的错误:
有什么建议么?问题是否可能是我正在使用交叉电缆(即使 WAGO 在以太网设置中设置为切换模式?)