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:
|
case NotSent:
|
||||||
writeLineEx(0, 3, "Error while analyzing %s! The device was not available! Ignoring...", gIpsSorted[ips[ADi]].IP);
|
writeLineEx(0, 3, "Error while analyzing %s! The device was not available! Ignoring...", gIpsSorted[ips[ADi]].IP);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
writeLinEx(0, 3, "OnModbusReadRegistersFailed: Unknown error: %d", error);
|
||||||
|
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
gQueueAck.Clear(); // Clear all queues
|
gQueueAck.Clear(); // Clear all queues
|
||||||
gQueuePending.Clear();
|
gQueuePending.Clear();
|
||||||
|
@ -406,7 +410,7 @@ void GenSysvars()
|
||||||
// Namespace Data
|
// Namespace Data
|
||||||
PutString(" <namespace name=\"Data\" comment=\"The actual process image\">\n");
|
PutString(" <namespace name=\"Data\" comment=\"The actual process image\">\n");
|
||||||
// InputRegisters
|
// 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(gIpsSorted[ipN].DeviceIOs.InputRegisters);
|
||||||
PutString("\" />\n");
|
PutString("\" />\n");
|
||||||
// InputBits
|
// InputBits
|
||||||
|
@ -414,7 +418,7 @@ void GenSysvars()
|
||||||
PutString(gIpsSorted[ipN].DeviceIOs.InputBits);
|
PutString(gIpsSorted[ipN].DeviceIOs.InputBits);
|
||||||
PutString("\" />\n");
|
PutString("\" />\n");
|
||||||
// OutputRegisters
|
// 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(gIpsSorted[ipN].DeviceIOs.OutputRegisters);
|
||||||
PutString("\" />\n");
|
PutString("\" />\n");
|
||||||
// OutputBits
|
// OutputBits
|
||||||
|
|
|
@ -68,8 +68,8 @@ void OnModbusReadBitsFailed(enum ModbusRequestError error, enum ModbusException
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
case Exception:
|
case Exception:
|
||||||
break;
|
|
||||||
case Timeout:
|
case Timeout:
|
||||||
|
case NotSent:
|
||||||
break;
|
break;
|
||||||
case FinalTimeout:
|
case FinalTimeout:
|
||||||
sysBeginVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputBits");
|
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;
|
@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::InputBits[i] = -1;
|
||||||
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputBits");
|
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputBits");
|
||||||
break;
|
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)
|
switch (error)
|
||||||
{
|
{
|
||||||
case Exception:
|
case Exception:
|
||||||
break;
|
|
||||||
case Timeout:
|
case Timeout:
|
||||||
|
case NotSent:
|
||||||
break;
|
break;
|
||||||
case FinalTimeout:
|
case FinalTimeout:
|
||||||
sysBeginVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputRegisters");
|
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;
|
@sysvar::%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data::InputRegisters[i] = -1;
|
||||||
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputRegisters");
|
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputRegisters");
|
||||||
break;
|
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");
|
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputBits");
|
||||||
break;
|
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");
|
sysEndVariableStructUpdate("%BUS_TYPE%%CHANNEL%::%NODE_NAME%::Data", "InputRegisters");
|
||||||
break;
|
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)
|
switch(reason)
|
||||||
{
|
{
|
||||||
case ParsingBuffer:
|
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);
|
runError(1001, reason);
|
||||||
break;
|
break;
|
||||||
case ModbusPackageWasSplit:
|
case ModbusPackageWasSplit:
|
||||||
|
@ -205,22 +223,27 @@ void OnModbusClientPanics(enum FatalErrors reason)
|
||||||
runError(1001, reason);
|
runError(1001, reason);
|
||||||
break;
|
break;
|
||||||
case VendorIdUnknown:
|
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);
|
runError(1001, reason);
|
||||||
break;
|
break;
|
||||||
case FuncCodeIncorrect:
|
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);
|
runError(1001, reason);
|
||||||
break;
|
break;
|
||||||
case AddressFailure:
|
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);
|
runError(1001, reason);
|
||||||
break;
|
break;
|
||||||
case ConnectionError:
|
case ConnectionError:
|
||||||
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Connection Error", reason);
|
writeLineEx(0, 4, "<%NODE_NAME%> Fatal Connection Error");
|
||||||
gtRead.Cancel();
|
gtRead.Cancel();
|
||||||
break;
|
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.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.OutputBits = 0x0000; // B&R writing outputs start at 0x000
|
||||||
thisDev.Addr.Write.OutputRegisters = 0x0000;
|
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.MaxRegisterCount = 0x0800; // B&R allows up to 2048 analog inputs
|
||||||
thisDev.ReceiveWindow = 1; // B&R can only handle 1 request at a time
|
thisDev.ReceiveWindow = 1; // B&R can only handle 1 request at a time
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -877,6 +877,10 @@ void _OnModbusReceive2Exceptions(byte exCode, struct ModbusApHeader mbap)
|
||||||
case 0x80+ReadWriteRegisters:
|
case 0x80+ReadWriteRegisters:
|
||||||
_OnModbusReceiveConfirmRegistersException(mbap, ex);
|
_OnModbusReceiveConfirmRegistersException(mbap, ex);
|
||||||
break;
|
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);
|
_OnModbusReceiveConfirmRegisters(mbuffer);
|
||||||
break;
|
break;
|
||||||
default:
|
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:
|
case ReadWriteRegisters:
|
||||||
OnModbusReadWriteRegistersFailed(reqError, None, mbap);
|
OnModbusReadWriteRegistersFailed(reqError, None, mbap);
|
||||||
break;
|
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:
|
case OK:
|
||||||
break;
|
break;
|
||||||
|
case NULL: // Delay
|
||||||
|
case CONNECTING:
|
||||||
|
return 1;
|
||||||
|
case ERROR:
|
||||||
|
writeDbg(ConnError, "_ModbusSnd: Socket status is not OK!");
|
||||||
|
OnModbusClientPanics(ConnectionError);
|
||||||
|
return 1;
|
||||||
default:
|
default:
|
||||||
writeDbg(ConnWarning, "_ModbusSnd: Socket status is not OK!);
|
writeDbg(ConnError, "_ModbusSnd: Unknown socket status: %d", gSocketState);
|
||||||
|
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,7 @@ variables
|
||||||
VendorIdUnknown,
|
VendorIdUnknown,
|
||||||
ConnectionError,
|
ConnectionError,
|
||||||
FuncCodeIncorrect,
|
FuncCodeIncorrect,
|
||||||
AddressFailure
|
AddressFailure,
|
||||||
|
SwitchArgumentInvalid
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -183,23 +183,28 @@ word _ModbusSnd(byte buffer[], word length)
|
||||||
{
|
{
|
||||||
case CLOSED: // If the connection is closed
|
case CLOSED: // If the connection is closed
|
||||||
_ModbusConnectTo(gRemoteIP, gRemotePort); // Try to (re)connect
|
_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!");
|
writeDbg(ConnError, "_ModbusSnd: Reconnecting failed!");
|
||||||
OnModbusClientPanics(ConnectionError);
|
OnModbusClientPanics(ConnectionError);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1; // Abort sending in all cases
|
||||||
}
|
}
|
||||||
case OK:
|
case OK:
|
||||||
break;
|
break;
|
||||||
case NULL:
|
case NULL: // Delay
|
||||||
|
case CONNECTING:
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
case ERROR:
|
||||||
writeDbg(ConnError, "_ModbusSnd: Socket status is not OK!");
|
writeDbg(ConnError, "_ModbusSnd: Socket status is not OK!");
|
||||||
OnModbusClientPanics(ConnectionError);
|
OnModbusClientPanics(ConnectionError);
|
||||||
return 1;
|
return 1;
|
||||||
|
default:
|
||||||
|
writeDbg(ConnError, "_ModbusSnd: Unknown socket status: %d", gSocketState);
|
||||||
|
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bin_to_strhex(buffer, str);
|
bin_to_strhex(buffer, str);
|
||||||
|
|
|
@ -143,10 +143,17 @@ byte _ModbusSnd(byte buffer[], word length)
|
||||||
}
|
}
|
||||||
case OK:
|
case OK:
|
||||||
break;
|
break;
|
||||||
default:
|
case NULL: // Delay
|
||||||
writeDbg(ConnError, "ModbusSnd: Socket status is not OK! Doing nothing.");
|
case CONNECTING:
|
||||||
|
return 1;
|
||||||
|
case ERROR:
|
||||||
|
writeDbg(ConnError, "_ModbusSnd: Socket status is not OK!");
|
||||||
OnModbusClientPanics(ConnectionError);
|
OnModbusClientPanics(ConnectionError);
|
||||||
return 1;
|
return 1;
|
||||||
|
default:
|
||||||
|
writeDbg(ConnError, "_ModbusSnd: Unknown socket status: %d", gSocketState);
|
||||||
|
OnModbusClientPanics(SwitchArgumentInvalid);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bin_to_strhex(buffer, str);
|
bin_to_strhex(buffer, str);
|
||||||
|
|
Loading…
Reference in a new issue