Added defaults to switch statements
This commit is contained in:
parent
723a6bacc7
commit
752f282c3a
8 changed files with 78 additions and 20 deletions
|
@ -247,6 +247,10 @@ void OnModbusReadRegistersFailed(enum ModbusRequestError error, enum ModbusExcep
|
|||
case NotSent:
|
||||
writeLineEx(0, 3, "Error while analyzing %s! The device was not available! Ignoring...", gIpsSorted[ips[ADi]].IP);
|
||||
break;
|
||||
default:
|
||||
writeLinEx(0, 3, "OnModbusReadRegistersFailed: Unknown error: %d", error);
|
||||
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||
return;
|
||||
}
|
||||
gQueueAck.Clear(); // Clear all queues
|
||||
gQueuePending.Clear();
|
||||
|
@ -406,7 +410,7 @@ void GenSysvars()
|
|||
// Namespace Data
|
||||
PutString(" <namespace name=\"Data\" comment=\"The actual process image\">\n");
|
||||
// InputRegisters
|
||||
PutString(" <variable anlyzLocal=\"2\" readOnly=\"false\" valueSequence=\"false\" unit=\"\" name=\"InputRegisters\" comment=\"The values of the input registers\" bitcount=\"9\" isSigned=\"true\" encoding=\"65001\" type=\"intarray\" arrayLength=\"");
|
||||
PutString(" <variable anlyzLocal=\"2\" readOnly=\"false\" valueSequence=\"false\" unit=\"\" name=\"InputRegisters\" comment=\"The values of the input registers\" bitcount=\"17\" isSigned=\"true\" encoding=\"65001\" type=\"intarray\" arrayLength=\"");
|
||||
PutString(gIpsSorted[ipN].DeviceIOs.InputRegisters);
|
||||
PutString("\" />\n");
|
||||
// InputBits
|
||||
|
@ -414,7 +418,7 @@ void GenSysvars()
|
|||
PutString(gIpsSorted[ipN].DeviceIOs.InputBits);
|
||||
PutString("\" />\n");
|
||||
// OutputRegisters
|
||||
PutString(" <variable anlyzLocal=\"2\" readOnly=\"false\" valueSequence=\"false\" unit=\"\" name=\"OutputRegisters\" comment=\"The values of the output registers. Write here and the values will be sent to the device\" bitcount=\"9\" isSigned=\"true\" encoding=\"65001\" type=\"intarray\" arrayLength=\"");
|
||||
PutString(" <variable anlyzLocal=\"2\" readOnly=\"false\" valueSequence=\"false\" unit=\"\" name=\"OutputRegisters\" comment=\"The values of the output registers. Write here and the values will be sent to the device\" bitcount=\"17\" isSigned=\"true\" encoding=\"65001\" type=\"intarray\" arrayLength=\"");
|
||||
PutString(gIpsSorted[ipN].DeviceIOs.OutputRegisters);
|
||||
PutString("\" />\n");
|
||||
// OutputBits
|
||||
|
|
|
@ -68,8 +68,8 @@ void OnModbusReadBitsFailed(enum ModbusRequestError error, enum ModbusException
|
|||
switch (error)
|
||||
{
|
||||
case Exception:
|
||||
break;
|
||||
case Timeout:
|
||||
case NotSent:
|
||||
break;
|
||||
case FinalTimeout:
|
||||
sysBeginVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputBits");
|
||||
|
@ -77,6 +77,10 @@ void OnModbusReadBitsFailed(enum ModbusRequestError error, enum ModbusException
|
|||
@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::InputBits[i] = -1;
|
||||
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputBits");
|
||||
break;
|
||||
default:
|
||||
writeDbg(MbError, "OnModbusReadBitsFailed: Unkown error: %d", error);
|
||||
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,8 +92,8 @@ void OnModbusReadRegistersFailed(enum ModbusRequestError error, enum ModbusExcep
|
|||
switch (error)
|
||||
{
|
||||
case Exception:
|
||||
break;
|
||||
case Timeout:
|
||||
case NotSent:
|
||||
break;
|
||||
case FinalTimeout:
|
||||
sysBeginVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputRegisters");
|
||||
|
@ -97,6 +101,10 @@ void OnModbusReadRegistersFailed(enum ModbusRequestError error, enum ModbusExcep
|
|||
@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::InputRegisters[i] = -1;
|
||||
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputRegisters");
|
||||
break;
|
||||
default:
|
||||
writeDbg(MbError, "OnModbusReadBitsFailed: Unkown error: %d", error);
|
||||
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,6 +153,11 @@ void OnModbusReadBitsSuccess(struct ModbusResReceiveBits mbres, byte bitStatus[]
|
|||
|
||||
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputBits");
|
||||
break;
|
||||
|
||||
default:
|
||||
writeDbg(MbError, "OnModbusReadBitsSuccess: Unexpected function code: 0x%02X", mbreq.Header.FuncCode);
|
||||
OnModbusClientPanics(FuncCodeIncorrect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,6 +188,11 @@ void OnModbusReadRegistersSuccess(struct ModbusResReceiveRegisters mbres, struct
|
|||
|
||||
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputRegisters");
|
||||
break;
|
||||
|
||||
default:
|
||||
writeDbg(MbError, "OnModbusReadBitsSuccess: Unexpected function code: 0x%02X", mbreq.Header.FuncCode);
|
||||
OnModbusClientPanics(FuncCodeIncorrect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +215,7 @@ void OnModbusClientPanics(enum FatalErrors reason)
|
|||
switch(reason)
|
||||
{
|
||||
case ParsingBuffer:
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error while parsing the received buffer", reason);
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error while parsing the received buffer");
|
||||
runError(1001, reason);
|
||||
break;
|
||||
case ModbusPackageWasSplit:
|
||||
|
@ -205,22 +223,27 @@ void OnModbusClientPanics(enum FatalErrors reason)
|
|||
runError(1001, reason);
|
||||
break;
|
||||
case VendorIdUnknown:
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error: Vendor ID unknown", reason);
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error: Vendor ID unknown");
|
||||
runError(1001, reason);
|
||||
break;
|
||||
case FuncCodeIncorrect:
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error: Function code is incorrect", reason);
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error: Function code is incorrect");
|
||||
runError(1001, reason);
|
||||
break;
|
||||
case AddressFailure:
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error: Start address is incorrect", reason);
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error: Start address is incorrect");
|
||||
runError(1001, reason);
|
||||
break;
|
||||
case ConnectionError:
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Connection Error", reason);
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Connection Error");
|
||||
gtRead.Cancel();
|
||||
break;
|
||||
case SwitchArgumentInvalid:
|
||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Error: A argument of a switch statement is incorrect");
|
||||
runError(1001, reason);
|
||||
break;
|
||||
}
|
||||
stop();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
|
@ -92,7 +92,7 @@ void DeviceInit(byte vendor)
|
|||
thisDev.Addr.Read.OutputRegisters = 0x0800; // B&R reading analog outputs start at 0x800
|
||||
thisDev.Addr.Write.OutputBits = 0x0000; // B&R writing outputs start at 0x000
|
||||
thisDev.Addr.Write.OutputRegisters = 0x0000;
|
||||
thisDev.MaxBitCount = 0x4000; // B&R allows up to 16348 digital inputs
|
||||
thisDev.MaxBitCount = 0x4000; // B&R allows up to 16384 digital inputs
|
||||
thisDev.MaxRegisterCount = 0x0800; // B&R allows up to 2048 analog inputs
|
||||
thisDev.ReceiveWindow = 1; // B&R can only handle 1 request at a time
|
||||
break;
|
||||
|
|
|
@ -877,6 +877,10 @@ void _OnModbusReceive2Exceptions(byte exCode, struct ModbusApHeader mbap)
|
|||
case 0x80+ReadWriteRegisters:
|
||||
_OnModbusReceiveConfirmRegistersException(mbap, ex);
|
||||
break;
|
||||
default:
|
||||
writeDbg(MbError, "_OnModbusReceive2Exceptions: Got incorrect exception function code 0x%02X!", mbap.FuncCode);
|
||||
OnModbusClientPanics(FuncCodeIncorrect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -919,7 +923,9 @@ void _OnModbusReceive2Success(byte buffer[], struct ModbusApHeader mbap, int off
|
|||
_OnModbusReceiveConfirmRegisters(mbuffer);
|
||||
break;
|
||||
default:
|
||||
writeDbg(MbError, "OnModbusReceive2Success: We received funcCode 0x%X!?", mbap.FuncCode);
|
||||
writeDbg(MbError, "_OnModbusReceive2Success: Received unexpected function code 0x%02X!", mbap.FuncCode);
|
||||
OnModbusClientPanics(FuncCodeIncorrect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1052,5 +1058,9 @@ void _ModbusSendTimerError(byte buffer[], enum ModbusRequestError reqError)
|
|||
case ReadWriteRegisters:
|
||||
OnModbusReadWriteRegistersFailed(reqError, None, mbap);
|
||||
break;
|
||||
default:
|
||||
writeDbg(MbError, "_ModbusSendTimerError: Unexpected function code 0x%02X!", mbap.FuncCode);
|
||||
OnModbusClientPanics(FuncCodeIncorrect);
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -155,8 +155,16 @@ byte _ModbusSnd(byte buffer[], word length)
|
|||
}
|
||||
case OK:
|
||||
break;
|
||||
case NULL: // Delay
|
||||
case CONNECTING:
|
||||
return 1;
|
||||
case ERROR:
|
||||
writeDbg(ConnError, "_ModbusSnd: Socket status is not OK!");
|
||||
OnModbusClientPanics(ConnectionError);
|
||||
return 1;
|
||||
default:
|
||||
writeDbg(ConnWarning, "_ModbusSnd: Socket status is not OK!);
|
||||
writeDbg(ConnError, "_ModbusSnd: Unknown socket status: %d", gSocketState);
|
||||
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ variables
|
|||
VendorIdUnknown,
|
||||
ConnectionError,
|
||||
FuncCodeIncorrect,
|
||||
AddressFailure
|
||||
AddressFailure,
|
||||
SwitchArgumentInvalid
|
||||
};
|
||||
}
|
|
@ -183,23 +183,28 @@ word _ModbusSnd(byte buffer[], word length)
|
|||
{
|
||||
case CLOSED: // If the connection is closed
|
||||
_ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect
|
||||
if (gSocketState != OK) // If this didn't work
|
||||
if (gSocketState < OK) // If this didn't work (state != OK)
|
||||
{
|
||||
if (gSocketState != NULL) // not WSAE WOULD BLOCK
|
||||
if (gSocketState < CONNECTING)
|
||||
{
|
||||
writeDbg(ConnError, "_ModbusSnd: Reconnecting failed!");
|
||||
OnModbusClientPanics(ConnectionError);
|
||||
}
|
||||
return 1;
|
||||
return 1; // Abort sending in all cases
|
||||
}
|
||||
case OK:
|
||||
break;
|
||||
case NULL:
|
||||
case NULL: // Delay
|
||||
case CONNECTING:
|
||||
return 1;
|
||||
default:
|
||||
case ERROR:
|
||||
writeDbg(ConnError, "_ModbusSnd: Socket status is not OK!");
|
||||
OnModbusClientPanics(ConnectionError);
|
||||
return 1;
|
||||
default:
|
||||
writeDbg(ConnError, "_ModbusSnd: Unknown socket status: %d", gSocketState);
|
||||
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bin_to_strhex(buffer, str);
|
||||
|
|
|
@ -143,10 +143,17 @@ byte _ModbusSnd(byte buffer[], word length)
|
|||
}
|
||||
case OK:
|
||||
break;
|
||||
default:
|
||||
writeDbg(ConnError, "ModbusSnd: Socket status is not OK! Doing nothing.");
|
||||
case NULL: // Delay
|
||||
case CONNECTING:
|
||||
return 1;
|
||||
case ERROR:
|
||||
writeDbg(ConnError, "_ModbusSnd: Socket status is not OK!");
|
||||
OnModbusClientPanics(ConnectionError);
|
||||
return 1;
|
||||
default:
|
||||
writeDbg(ConnError, "_ModbusSnd: Unknown socket status: %d", gSocketState);
|
||||
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bin_to_strhex(buffer, str);
|
||||
|
|
Loading…
Reference in a new issue