// ISO COTP export const COTP_CR = 0xE0; export const COTP_CC = 0xD0; export const COTP_DR = 0x80; export const COTP_DC = 0xC0; export const COTP_DT = 0xF0; export const COTP_DT_EOT = 0x08; // COTP Parameter Codes export const COTP_SRC_TSAP = 0xC1; export const COTP_DST_TSAP = 0xC2; export const COTP_TPDU_SIZE = 0xC0; // TPKT export const TPKT_VERSION = 0x03; export const TPKT_HEADER_LEN = 4; // S7 Protocol export const S7_PROTOCOL_ID = 0x32; // S7 Message Types export const S7_MSG_TYPE_REQUEST = 0x01; export const S7_MSG_TYPE_RESPONSE = 0x02; export const S7_MSG_TYPE_RESPONSE_DATA = 0x03; export const S7_MSG_TYPE_USERDATA = 0x07; // S7 Function Codes export const S7_FN_SETUP_COMM = 0xF0; export const S7_FN_READ_AREA = 0x04; export const S7_FN_WRITE_AREA = 0x05; export const S7_FN_READ_VAR = 0x04; export const S7_FN_WRITE_VAR = 0x05; export const S7_FN_REQUEST_DOWNLOAD = 0x1A; export const S7_FN_DOWNLOAD_BLOCK = 0x1B; export const S7_FN_DOWNLOAD_ENDED = 0x1C; export const S7_FN_START_UPLOAD = 0x1D; export const S7_FN_UPLOAD = 0x1E; export const S7_FN_END_UPLOAD = 0x1F; export const S7_FN_DELETE_BLOCK = 0x28; export const S7_FN_PLC_CONTROL = 0x28; export const S7_FN_PLC_SECURITY = 0x2C; // S7 Item Specification export const S7_ITEM_SPEC = 0x12; export const S7_ITEM_LEN = 0x0A; export const S7_SYNTAX_ID_ANY = 0x10; // Area IDs export const S7AreaPE = 0x81; export const S7AreaPA = 0x82; export const S7AreaMK = 0x83; export const S7AreaDB = 0x84; export const S7AreaCT = 0x1C; export const S7AreaTM = 0x1D; // Word Length export const S7WLBit = 0x01; export const S7WLByte = 0x02; export const S7WLWord = 0x04; export const S7WLDWord = 0x06; export const S7WLReal = 0x08; export const S7WLCounter = 0x1C; export const S7WLTimer = 0x1D; // Transport Size (for item encoding) export const TS_BIT = 0x01; export const TS_BYTE = 0x02; export const TS_WORD = 0x04; export const TS_DWORD = 0x06; export const TS_REAL = 0x08; export const TS_COUNTER = 0x1C; export const TS_TIMER = 0x1D; // Connection Type export const CONNTYPE_PG = 0x01; export const CONNTYPE_OP = 0x02; export const CONNTYPE_BASIC = 0x03; // Block Type export const Block_OB = 0x38; export const Block_DB = 0x41; export const Block_SDB = 0x42; export const Block_FC = 0x43; export const Block_SFC = 0x44; export const Block_FB = 0x45; export const Block_SFB = 0x46; // Sub Block Type export const SubBlk_OB = 0x08; export const SubBlk_DB = 0x0A; export const SubBlk_SDB = 0x0B; export const SubBlk_FC = 0x0C; export const SubBlk_SFC = 0x0D; export const SubBlk_FB = 0x0E; export const SubBlk_SFB = 0x0F; // Block Languages export const BlockLangAWL = 0x01; export const BlockLangKOP = 0x02; export const BlockLangFUP = 0x03; export const BlockLangSCL = 0x04; export const BlockLangDB = 0x05; export const BlockLangGRAPH = 0x06; // CPU Status export const S7CpuStatusUnknown = 0x00; export const S7CpuStatusRun = 0x08; export const S7CpuStatusStop = 0x04; // Max vars for MultiRead/MultiWrite export const MAX_VARS = 20; // Default PDU export const DEFAULT_PDU_REQUESTED = 960; export const DEFAULT_PDU_MIN = 240; // Param Numbers (Client) export const p_u16_LocalPort = 1; export const p_u16_RemotePort = 2; export const p_i32_PingTimeout = 3; export const p_i32_SendTimeout = 4; export const p_i32_RecvTimeout = 5; export const p_i32_WorkInterval = 6; export const p_u16_SrcRef = 7; export const p_u16_DstRef = 8; export const p_u16_SrcTSap = 9; export const p_i32_PDURequest = 10; export const p_i32_MaxClients = 11; export const p_i32_BSendTimeout = 12; export const p_i32_BRecvTimeout = 13; export const p_u32_RecoveryTime = 14; export const p_u32_KeepAliveTime = 15; // ISO Errors export const errIsoConnect = 0x00010000; export const errIsoDisconnect = 0x00020000; export const errIsoInvalidPDU = 0x00030000; export const errIsoInvalidDataSize = 0x00040000; export const errIsoNullPointer = 0x00050000; export const errIsoShortPacket = 0x00060000; export const errIsoTooManyFragments = 0x00070000; export const errIsoPduOverflow = 0x00080000; export const errIsoSendPacket = 0x00090000; export const errIsoRecvPacket = 0x000A0000; export const errIsoInvalidParams = 0x000B0000; // Client Errors export const errNegotiatingPDU = 0x00100000; export const errCliInvalidParams = 0x00200000; export const errCliJobPending = 0x00300000; export const errCliTooManyItems = 0x00400000; export const errCliInvalidWordLen = 0x00500000; export const errCliPartialDataWritten = 0x00600000; export const errCliSizeOverPDU = 0x00700000; export const errCliInvalidPlcAnswer = 0x00800000; export const errCliAddressOutOfRange = 0x00900000; export const errCliInvalidTransportSize = 0x00A00000; export const errCliWriteDataSizeMismatch = 0x00B00000; export const errCliItemNotAvailable = 0x00C00000; export const errCliInvalidValue = 0x00D00000; export const errCliCannotStartPLC = 0x00E00000; export const errCliAlreadyRun = 0x00F00000; export const errCliCannotStopPLC = 0x01000000; export const errCliCannotCopyRamToRom = 0x01100000; export const errCliCannotCompress = 0x01200000; export const errCliAlreadyStop = 0x01300000; export const errCliFunNotAvailable = 0x01400000; export const errCliUploadSequenceFailed = 0x01500000; export const errCliInvalidDataSizeRecvd = 0x01600000; export const errCliInvalidBlockType = 0x01700000; export const errCliInvalidBlockNumber = 0x01800000; export const errCliInvalidBlockSize = 0x01900000; export const errCliDownloadSequenceFailed = 0x01A00000; export const errCliInsertRefused = 0x01B00000; export const errCliDeleteRefused = 0x01C00000; export const errCliNeedPassword = 0x01D00000; export const errCliInvalidPassword = 0x01E00000; export const errCliNoPasswordToSetOrClear = 0x01F00000; export const errCliJobTimeout = 0x02000000; export const errCliPartialDataRead = 0x02100000; export const errCliBufferTooSmall = 0x02200000; export const errCliFunctionRefused = 0x02300000; export const errCliDestroying = 0x02400000; export const errCliInvalidParamNumber = 0x02500000; export const errCliCannotChangeParam = 0x02600000; // Server Errors export const errSrvCannotStart = 0x00100000; export const errSrvDBNullPointer = 0x00200000; export const errSrvAreaAlreadyExists = 0x00300000; export const errSrvUnknownArea = 0x00400000; export const errSrvInvalidParams = 0x00500000; export const errSrvTooManyDB = 0x00600000; export const errSrvInvalidParamNumber = 0x00700000; export const errSrvCannotChangeParam = 0x00800000; // Server Area IDs export const srvAreaPE = 0; export const srvAreaPA = 1; export const srvAreaMK = 2; export const srvAreaCT = 3; export const srvAreaTM = 4; export const srvAreaDB = 5; // Server Operation Types export const OperationRead = 0; export const OperationWrite = 1; // Server Event Codes export const evcServerStarted = 0x00000001; export const evcServerStopped = 0x00000002; export const evcListenerCannotStart = 0x00000004; export const evcClientAdded = 0x00000008; export const evcClientRejected = 0x00000010; export const evcClientNoRoom = 0x00000020; export const evcClientException = 0x00000040; export const evcClientDisconnected = 0x00000080; export const evcClientTerminated = 0x00000100; export const evcClientsDropped = 0x00000200; export const evcPDUincoming = 0x00010000; export const evcDataRead = 0x00020000; export const evcDataWrite = 0x00040000; export const evcNegotiatePDU = 0x00080000; export const evcReadSZL = 0x00100000; export const evcClock = 0x00200000; export const evcUpload = 0x00400000; export const evcDownload = 0x00800000; export const evcDirectory = 0x01000000; export const evcSecurity = 0x02000000; export const evcControl = 0x04000000; export const evcAll = 0xFFFFFFFF; export const evcNone = 0x00000000; // Event SubCodes export const evsUnknown = 0x0000; export const evsStartUpload = 0x0001; export const evsStartDownload = 0x0001; export const evsGetBlockList = 0x0001; export const evsStartListBoT = 0x0002; export const evsListBoT = 0x0003; export const evsGetBlockInfo = 0x0004; export const evsGetClock = 0x0001; export const evsSetClock = 0x0002; export const evsSetPassword = 0x0001; export const evsClrPassword = 0x0002; // Event Params - Function Groups export const grProgrammer = 0x0041; export const grCyclicData = 0x0042; export const grBlocksInfo = 0x0043; export const grSZL = 0x0044; export const grPassword = 0x0045; export const grBSend = 0x0046; export const grClock = 0x0047; export const grSecurity = 0x0045; // Event Params - Control Codes export const CodeControlUnknown = 0x0000; export const CodeControlColdStart = 0x0001; export const CodeControlWarmStart = 0x0002; export const CodeControlStop = 0x0003; export const CodeControlCompress = 0x0004; export const CodeControlCpyRamRom = 0x0005; export const CodeControlInsDel = 0x0006; // Event Results export const evrNoError = 0x0000; export const evrFragmentRejected = 0x0001; export const evrMalformedPDU = 0x0002; export const evrSparseBytes = 0x0003; export const evrCannotHandlePDU = 0x0004; export const evrNotImplemented = 0x0005; export const evrErrException = 0x0006; export const evrErrAreaNotFound = 0x0007; export const evrErrOutOfRange = 0x0008; export const evrErrOverPDU = 0x0009; export const evrErrTransportSize = 0x000A; export const evrInvalidGroupUData = 0x000B; export const evrInvalidSZL = 0x000C; export const evrDataSizeMismatch = 0x000D; export const evrCannotUpload = 0x000E; export const evrCannotDownload = 0x000F; export const evrUploadInvalidID = 0x0010; export const evrResNotFound = 0x0011; // Server Status export const SrvStopped = 0x00; export const SrvRunning = 0x01; export const SrvError = 0x02; // S7 Data Header export const S7_DATA_HEADER_LEN = 4; export const S7_READ_HEADER_LEN = 18; // 12 param + 4 data header + 2 error export const S7_WRITE_HEADER_LEN = 18; // S7 Setup Communication offsets export const S7_SETUP_PARAM_LEN = 8; export const S7_SETUP_DATA_LEN = 0; // SZL IDs export const SZL_ID_LIST = 0x0000; export const SZL_ID_CPU_INFO = 0x001C; // Upload/Download subfunctions export const S7_UD_REQ_DOWNLOAD = 0x1A; export const S7_UD_REQ_UPLOAD = 0x1D; // PLC Control subfunctions export const S7_PLC_START = 0x28; export const S7_PLC_STOP = 0x29; export const S7_PLC_HOT_START = 0x02; export const S7_PLC_COLD_START = 0x01; export const S7_PLC_COMPRESS = 0x04; export const S7_PLC_COPY_RAM_ROM = 0x05; // Security subfunctions export const S7_SEC_SET_PASSWORD = 0x01; export const S7_SEC_CLEAR_PASSWORD = 0x02;