void IPLC.Disconnect() { LastErrorCode = 0; LastErrorMessage = ""; try { S7 = null; if (S7 != null) { S7.Close(); S7 = null; } } catch (PlcException EPLC) { LastErrorMessage = EPLC.ToString(); LastErrorCode = (UInt32)EPLC.ErrorCode; throw EPLC; } catch (Exception E) { LastErrorMessage = E.ToString(); LastErrorCode = ErrorCodes.GENERICEXCEPTION; throw E; } }
void IPLC.Connect(UInt32 CPUType, String IP, UInt32 Rack, UInt32 Slot, UInt32 ReadTimeOut, UInt32 WriteTimeOut) { S7 = null; LastErrorCode = 0; LastErrorMessage = ""; try { S7 = new Plc((CpuType)CPUType, IP, (short)Rack, (short)Slot); S7.ReadTimeout = (int)ReadTimeOut; S7.WriteTimeout = (int)WriteTimeOut; S7.Open(); } catch (PlcException EPLC) { LastErrorMessage = EPLC.ToString(); LastErrorCode = (UInt32)EPLC.ErrorCode; throw EPLC; } catch (Exception E) { LastErrorMessage = E.ToString(); LastErrorCode = ErrorCodes.GENERICEXCEPTION; throw E; } }
String IPLC.GetIPAddress() { LastErrorCode = 0; LastErrorMessage = ""; try { if (S7 != null) { return(S7.IP); } throw new LibS7Exception(ErrorCodes.NOTCONNECTED); } catch (PlcException EPLC) { LastErrorMessage = EPLC.ToString(); LastErrorCode = (UInt32)EPLC.ErrorCode; throw EPLC; } catch (LibS7Exception ES7) { LastErrorMessage = ES7.ToString(); LastErrorCode = ES7.ErrorCode; throw ES7; } catch (Exception E) { LastErrorMessage = E.ToString(); LastErrorCode = ErrorCodes.GENERICEXCEPTION; throw E; } }
bool IPLC.IsAvailable() { LastErrorCode = 0; LastErrorMessage = ""; try { if (S7 != null) { return(S7.IsConnected); } return(false); } catch (PlcException EPLC) { LastErrorMessage = EPLC.ToString(); LastErrorCode = (UInt32)EPLC.ErrorCode; throw EPLC; } catch (LibS7Exception ES7) { LastErrorMessage = ES7.ToString(); LastErrorCode = ES7.ErrorCode; throw ES7; } catch (Exception E) { LastErrorMessage = E.ToString(); LastErrorCode = ErrorCodes.GENERICEXCEPTION; throw E; } }
void IPLC.WriteBytes(UInt32 DB, UInt32 Offset, [In, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_UI1)] byte[] bArray) { LastErrorCode = 0; LastErrorMessage = ""; try { if (S7 != null) { S7.WriteBytes(DataType.DataBlock, (int)DB, (int)Offset, bArray); } else { throw new LibS7Exception(ErrorCodes.NOTCONNECTED); } } catch (PlcException EPLC) { LastErrorMessage = EPLC.ToString(); LastErrorCode = (UInt32)EPLC.ErrorCode; throw EPLC; } catch (LibS7Exception ES7) { LastErrorMessage = ES7.ToString(); LastErrorCode = ES7.ErrorCode; throw ES7; } catch (Exception E) { LastErrorMessage = E.ToString(); LastErrorCode = ErrorCodes.GENERICEXCEPTION; throw E; } }
IPLCReadData IPLC.ReadBytes(UInt32 DB, UInt32 Offset, UInt32 Count) { LastErrorCode = 0; LastErrorMessage = ""; try { if (S7 != null) { byte[] Bytes = S7.ReadBytes(DataType.DataBlock, (int)DB, (int)Offset, (int)Count); return(new CPLCReadData(Bytes)); } else { throw new LibS7Exception(ErrorCodes.NOTCONNECTED); } } catch (PlcException EPLC) { LastErrorMessage = EPLC.ToString(); LastErrorCode = (UInt32)EPLC.ErrorCode; throw EPLC; } catch (LibS7Exception ES7) { LastErrorMessage = ES7.ToString(); LastErrorCode = ES7.ErrorCode; throw ES7; } catch (Exception E) { LastErrorMessage = E.ToString(); LastErrorCode = ErrorCodes.GENERICEXCEPTION; throw E; } }