Home

Target CoDeSys Reference Manual

image

Contents

1. leche 131 1 14 7 5485 132 1 14 8 54 85 FIUSHOULPUT 2225 133 1 14 9 RS485 GetStatus PE 134 1 14 10 48515 135 1 14 11 Rs4S5Purgelnp t 55 tote sa tc 136 1 14 12 RS485 PUrBE OUTPUT cetero rou ees oe ete Pe ee eps voee 137 1 14 13 Rs485ReceiveBloCck eicit re iet eer ceo 138 1 14 14 485 139 1 14 15 140 1 14 16 Rs485SendBr ak eot ret came Pe ERR IOS RR ge 141 1 14 17 RSABSSENC BY H 142 1 14 18 Rs485SetFlowCofitto eiie tinent bine oce seo Ln eo aa ae cu toda cac dee oe cheese dd 143 ui ENECHIgu c M 144 1 15 The RS485 Expansion library RS485_ ccc ccsscceessecesseeesseeeesececsseceseeeesseeeessececseeesseeecaeeeeaaecesees 145 EN Pu CAP qu tess ven chenananeu vast vadedeacndasnsycesdeestaaden seen 146 1 152 RS485 IAC A
2. MM 147 1 15 3 85485 RA c 148 1 16 The MODBUS library MODBUS Lib lib eese nnne nennen nennt tnnt innen 149 1 16 1 RTU adi 150 1 16 2 ISP 152 1 16 3 MB RTU 153 1 16 154 IS an a M M 155 1 16 6 Rd Hold Regs eiii tiene netten eh 156 1 16 7 MB Rd Input 157 1 16 89 MB RTU Rd IB Uts s eco tt eode oae ee de eU een NES DSi RS 158 1 16 9 MB RTU 159 1 16 10 MB Wr 161 1 16 11 MB Wr Hold teta eK gre de aE E Ne ee ea NER USERS 162 1 16 12 RTU Wr Rd Hold eter exea eno age rueda eve e 163 1 16 13 MB Wr Single 2 tiere toten i ette 165 Target CoDeSys Reference Manual 1 16 14 MB Wr Single ettet espe 166 1 16 15 MB 51 M 167 1 16 16 MB COMMOCE s 3s oie RR UR BER Te epe 170 1 16 17 TCP DISCORDIneCct ooo
3. nnne nnn 79 1 9 FRAM library FRAM Lib Jib 80 81 1 9 2 aden ees EISE 82 1 10 The RUG library RUC den een een dee pag needs ann 83 1 10 41 DateTime Read 84 LORIC CI m 85 T103 RTE e eee ee en EM MM M DET ML 86 1 11 The MODEM library MODEM Lib lib ertet tette 87 reu pA NONS STATUS PEE 88 1 11 2 MODEM CHAR SET Emm 89 1 11 3 MODEM COMMAND X 90 1 11 4 MODEM DATA E pues Ne eR a 91 1 11 5 MODEM STATUS 92 Tea aes etae BGs ae eds 94 M 96 1 11 8 GMO PPP SMIS Call chatter de pe tube ed 99 1 14 950 01 5 65 ENEE A 103 1 12 The TCPIP library AM 106 112 WIAA Pes E 107 1 12 2 LM 109 1 12 3 ERR 111 1 124 SNTP Date TM Gis a e a E ahaha eee 113 1 13 The MySQL library
4. 62 1 3 15 REOSGELVEPSION Cc 63 1 3 16 5 se 64 1 3 17 elec e 65 1 3 18 e EE 66 13 19 RtosS ndMIsB coner suse ee e opta 67 1 3 20 REOSSEMVENS t Pe ene Eti eene e beetle Eni ee E ee ree O RO OOOO 68 1 3 21 RtosSetlhIE LEV ott ode te deste vod eee oce neget edente quo 69 13 22 Rm DL 70 1 4 The SysLibEvent library 5 71 1 4 1 SysEventCreate sic 72 1 4 2 5 5 AEE 73 1 4 3 5 e 74 1 44 E 75 1 5 The SysLibCallback library SysLibCallback lib cccccccsccceessssececssecececsssseeeessesececssseeeesssececsesseseesesseeeeseaaeess 76 1 6 The SysLibDir library SysLibDir lib eeseeeees nnnnnn nnne 77 1 7 The SysLibPlcCtrl library nnne nnn nnn nnn nin 78 Target CoDeSys Reference Manual 1 8 The SysLibStr library
5. 3 222 The Result parameter is the string in which to insert the response from the server This response contains a header typical of HTTP followed by the actual output of the server body The header and the body are separated by a blank line which can be searched as the beginning of the body part The Result Max Len parameter is the maximum number of characters to receive in the response string The DNS parameter allows the specification of a different DNS server which has priority over the default setting into CHIP INI 109 Target CoDeSys Reference Manual configuration file The SSL connections require an enabling and configuration using the file CHIP INI refer to the administration pages Example Err Code HTTP Post www mysite com page php 1 1238 2 456 Result 500 E Related Topics HTTP Get 110 Target CoDeSys Reference Manual 1 12 3 SendMail FUNCTION SendMail BOOL VAR_INPUT Local_IP STRING From_Address STRING From_Alias STRING Server_Add STRING Username STRING Password STRING To_Address STRING Subject STRING Attached_File STRING Text STRING END_VAR Sends an E mail by the specified SMTP server Return Value TRUE success FALSE error Input Parameters Local IP IP address of sender into Local Area Network not necessary From Adaress E mail address of sender From Alias Alias name of sender not necessary Server Address
6. da dete edu 44 1 2 29 SysSockSetIPAddQLFess cac 45 1 2 30 57550 46 1 2 31 5 47 1 3 The RTOS functions library rtos lib sss s nnns nnn 48 WS VT VP EIMSG EX de tage donee 49 1 3 2 dees acdsee eee ented 50 13 3 REOSD CIELEM c 51 1 3 4 05 HM 52 1 35 REOSFINGIVIS Ry acco P EE 53 1 3 6 RtosGetBootstrapVersiOn iioc ecce saa nee de eden ger 54 1 3 7 orca 55 13 8 RtOSGEtDNCPS 56 1 3 9 RtOSGeEtINIENtry ut 57 1 3 10 REOSGECINIENUY EX ORE 58 1 3 11 RtosGetLinKstate sriain teatro Pete eat oco ded addens ence v 59 1 3 12 RtosGetMacAdd ress c M Mn 60 1 3 13 RtosGetMSS sissies c 61 1 3 14
7. RS232 port can also be used as programming port Set COMx PROG where x is 5232 port number in the CHIP INI file to enable this option The default for COMx option is USER enabling this port for user application by IEC libraries For COM1 to COM3 must be used RS485 Serial library instead or specific protocol library for example MODBUS RTU Limitations The following limitations have to be taken into account The DTR DSR DCD Signals are not supported The option 1 for stop bits 1 5 stop bits is not supported The total size of bits data parity stop may not exceed 10 bits It is strongly recomendend to check the return values of the functions Here is a list of all the functions this library offers SysComFlush SysComPurge SysComRxNum SysComReadLine Target CoDeSys Reference Manual 1 1 1 SysComFlush FUNCTION SysComFlush BOOL VAR_INPUT dwHandle DWORD END_VAR Wait until all data from the output buffer has been sent Return Value TRUE success FALSE error Input Parameters dwHandle Port handle Target CoDeSys Reference Manual 1 1 2 SysComPurge FUNCTION SysComPurge BOOL VAR_INPUT dwHandle DWORD bPurgeln BOOL bPurgeOut BOOL END_VAR Discard the contents of the serial Transmit and or Receive buffer s Return Value TRUE success FALSE error Input Parameters dwHandle Port handle bPurgeln Set to TRUE to purge the Input buffer bPurgeOut Set to TRUE to purge
8. INADDR SOCK_IP_MREQ SOCKADDRESS SOCKET FD SET SOCKET LINGER SOCKET TIMEVAL SysSockAccept SysSockBind SysSockClose SysSockConnect SysSockCreate SysSockGetHostByName SysSockGetHostName SysSockGetLastErrorSync SysSockGetOption SysSockHtonl SysSockHtons SysSocklnetAddr SysSocklnetNtoa SysSockloctl SysSockListen SysSockNtohl SysSockNtohs SysSockRecv SysSockRecvFrom SysSockSelect SysSockSend SysSockSendTo SysSockSetlPAddress SysSockSetOption SysSockShutdown 13 Target CoDeSys Reference Manual 1 2 1 TYPE INADDR TYPE INADDR TYPE INADDR STRUCT S_addr DWORD END_STRUCT END_TYPE Contains an IP address Member S addr IP address in DWORD format To compute the IP address in DWORD format see function SysSocklnetAddr 14 Target CoDeSys Reference Manual 1 2 2 TYPE SOCK_IP_MREQ TYPE SOCK_IP_MREQ TYPE SOCK_IP_MREQ STRUCT imr_multiaddr imr_interface END_STRUCT END_TYPE Multicast request data type Member imr_multiaddr Multicast group to join imr_interface Interface to join on INADDR INADDR 15 Target CoDeSys Reference Manual 1 2 3 TYPE SOCKADDRESS TYPE SOCKADDRESS TYPE SOCKADDRESS STRUCT sin family INT sin port UINT sin addr UDINT sin zero ARRAY 0 7 OF SINT END STRUCT END TYPE Contains an IP address and a port number Member sin family Address family must by equal to SOCKET AF INET sin port Port in network order To compute
9. Req Buf 3 1 IF MB TCP Connected THEN IF MB TCP Req Rsp MB TCP Socket 255 4 ADR Req Buf 4 ADR Rsp Buf 3 0 THEN Input Reg 256 Rsp Buf 1 Rsp Buf 2 END IF END IF Write one output word at address 1 to Slave 255 no RTU subnet Req Buf 0 Req Buf 1 15 Buf 2 Output Reg 256 Req Buf 3 Output Reg MOD 256 IF MB TCP Connected THEN MB TCP Req Rsp MB TCP Socket 255 6 ADR Req Buf 4 ADR Rsp Buf 4 END IF To read the input word is used the function code 4 followed by 4 bytes of data two for the start address of the object and two for the amount of words to read The expected response consists of 3 bytes of data The first is a input bytes count in this case 2 because is required 1 word while the remaining 2 bytes are for the input word requested To write the output word is used the function code 6 followed by 4 bytes two for the start address of the object and two for the value to be written The expected response is composed of 4 bytes the same as those sent Related Topics MB TCP Connect 178 Target CoDeSys Reference Manual MB TCP Disconnect 179 Target CoDeSys Reference Manual 1 16 23 MB_TCP_Wr_Coils FUNCTION MB_TCP_Wr_Coils UINT VAR_INPUT Socket INT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS TCP IP function code 15 Write Multiple Coils Return Value 0 success 144 Quantity parameter n
10. Rsp generic communication function for which operates as an interface with the specific command code Slave Add parameter selects the specific slave on serial bus Address parameter is the word address to write Value parameter indicates the value to be written into the word The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command Related Topics MB RTU Rd Hold Regs MB RTU Wr Hold Regs 166 Target CoDeSys Reference Manual 1 16 15 MB RTU Slave FUNCTION BLOCK MB RTU Slave VAR INPUT Start BOOL Port PORTS Baudrate UDINT Parity MB RTU PARITY Slave Add BYTE Coils Ptr POINTER TO BYTE Coils Max UINT Inputs Ptr POINTER TO BYTE Inputs Max UINT Hold Regs Ptr POINTER TO WORD Hold Regs Max UINT Input Regs Ptr POINTER TO WORD Input Regs Max UINT END VAR VAR OUTPUT Ready BOOL Status MODBUS STATUS END VAR VAR State INT Frame_Timeout UDINT Baud Low BOOL Delete Echo BOOL END VAR Function block to establish a permanent MODBUS RTU slave service Input Variables Start Activation signal Port Serial port number Default to COM2 Bauarate Speed of communication 300 1000000 bits s Default to 9600 Parity Parity select 0 1 2 NO ODD EVEN Default to PARITY EVEN Slave Add Slave address valid 1 247 Default to 1 Coils
11. 6 MODEM DEINIT 7 MODEM RETRY WAIT 8 DYNDNS REQUEST 10 DYNDNS OK 11 DYNDNS FAIL 12 SMS SENDING 20 SMS SENDED 21 SMS SEND ERROR 22 SMS GETTING 23 SMS RECEIVED 24 SMS NOT RECEIVED 25 CALL SENDING 30 CALL SENDED 31 CALL SEND ERROR 32 CALL RECEIVING 33 CALL TERMINATED 34 MODEM SIGNAL READING 40 MODEM STANDBY END TYPE This type enumerates the current status of generic MODEM function block Member MODEM STANDBY 0 Modem is OFF in standby mode MODEM INIT 1 Initialization of modem connection NET REGISTRATION 2 Registration on the radio network PPP CONNECTING 3 PPP connection in progress MODEM CONNECTED 4 Modem connected to the service PPP LINK LOST 5 Loss of the PPP link MODEM DCD LOST 6 Loss of DCD signal of the modem MODEM DEINIT 7 92 Target CoDeSys Reference Manual Deinitialization of the modem MODEM_RETRY_WAIT 8 Waiting before reconnection DYNDNS_REQUEST 10 Updating request in progress DYNDNS OK 11 IP address is updated on the server DYNDNS fail 12 Update on the server failed SMS SENDING 20 SMS sending in progress SMS SENDED 21 SMS sent successfully SMS SEND ERROR 22 Error while sending the SMS SMS GETTING 23 SMS getting in progress SMS RECEIVED 24 Received and getted an SMS SMS NOT RECEIVED 25 No SMS available in reception CALL SENDING 30 Outgoing call in progres
12. DMX512 Tx 5485 Init A 5485 Tx 145 Target CoDeSys Reference Manual 1 15 1 DMX512_Tx FUNCTION DMX512_Tx UINT VAR_INPUT Port PORTS Offset UINT Data Ptr DWORD Data Num UINT END VAR Executes the transmission of a DMX512 frame Return Value 0 success 200 bad parameter 201 serial initialization error Input Parameters Port Serial port number Offset Position of Data from the start of DMX512 frame Data Ptr Pointer of Data buffer to send Data Num Number of Data bytes Comments This function sends over RS485 port a sequence of bytes in accordance with the DMX512 protocol The speed of communication is 250kbit s and for synchronization is used a break of 3 characters 132us followed by start code one byte of 0 value Then the buffer data bytes are sent in quantities up to 512 The data is transmitted with a start bit 8 data bits and 2 stop bits The Offset parameter determines a transmission of data to 0 in an amount equal to Offset 1 before sending the bytes of the data buffer Normally this parameter is 1 since the data to be transmitted are justified by the DMX512 address 1 Data Ptr parameter is the pointer to the first byte of data buffer to be transmitted Data Num parameter is the number of bytes in the buffer to be transmitted 146 Target CoDeSys Reference Manual 1 15 2 RS485 Init A FUNCTION RS485 Init BOOL VAR INPUT Port PORTS Baudrate UDINT Timeo
13. Dial ATD 99 1 97 Retry_Seconds Target CoDeSys Reference Manual 60 The function block returns the current state of the connection with one of the values defined by the MODEM STATUS type Status Status 1 Status 2 Status 3 Status 4 Status 5 Status 6 Status 7 Status 8 Modem is OFF in standby mode Initialization of modem connection Registration on the network PPP connection in progress Modem connected to the service Loss of the PPP link Loss of DCD signal of the modem Deinitialization of the modem Waiting before reconnection The Signal output indicates the field strength of the radio network NOTE permanent PPP connection is useable as an alternative to other types of services like SMS management Related Topics MODEM DATA SERVICE MODEM STATUS DynDNS Client 98 Target CoDeSys Reference Manual 1 11 8 GMO1 PPP SMS Call FUNCTION BLOCK GM01 PPP SMS Call VAR INPUT Start BOOL PPP Disable BOOL DynDNS Enable BOOL Retry Seconds INT Char Set MODEM CHAR SET SMS Send Start BOOL SMS Send Phone STRING 20 SMS Send Text STRING 160 SMS Get Start BOOL Call Send Start BOOL Call Send Phone STRING 20 Call Hang Up BOOL Command MODEM COMMAND Command Data STRING 300 END VAR VAR OUTPUT Ready BOOL Status MODEM STATUS Signal USINT SMS News UINT SMS Get Time STRING 32 SMS Get Phone STRING 20 SMS Get Text STRING 1536
14. Socket POINTER TO INT END VAR Initializes and connect MODBUS TCP IP client to a specific server Return Value 0 success 128 initialization parameter not valid 129 inizialization error 137 reached the maximum number of instances 32 gt 200 error code according to the coding adopted by the TCP IP stack Input Parameters IP_Address Network address of the server to connect to Port Communication TCP IP port of the server Keepalive_En Activation of Keepalive feature Keepalive_Time Idle time s before Probes sending 10 32767 Keepalive_Intv Time s interval between Probes 1 600 Keepalive_Retry Maximun number of Probes before connection close 0 32767 Rsp_Timeout Maximum wait ms for server response reception for example 1000 Socket Returned socket descriptor to use as connection handle Comments This function initializes a MODBUS TCP IP client connection with a server at a specific IP address This function must be called before start a communication session Up to 32 instances of simultaneous connection are possible with different socket handles Address parameter identifies the network address of the server to which to connect The Port parameter identifies the TCP port used for connection Normally the 502 port is used for MODBUS TCP IP The Keepalive parameters set the feature of sending dummy messages Probes in order to check whether the connection with the counterpart server peer
15. Target CoDeSys Reference Manual 1 11 3 MODEM_COMMAND TYPE MODEM_COMMAND TYPE MODEM COMMAND MODEM NO COMMAND 0 2 MODEM_SIGNAL_READ 1 MODEM NO COMMAND END TYPE This type enumerates the codes of auxiliary commands for the modem Member MODEM NO COMMAND 0 No command is requested MODEM SIGNAL READ 1 Update the reading of field strength of the radio network 90 Target CoDeSys Reference Manual 1 11 4 MODEM DATA SERVICE TYPE MODEM DATA SERVICE TYPE MODEM DATA SERVICE MODEM DATA NO 0 MODEM DATA GPRS 1 MODEM DATA EDGE 2 MODEM DATA UMTS 3 MODEM DATA UMTS HSDPA 4 MODEM DATA UMTS HSUPA 5 MODEM DATA UMTS HSDPA HSUPA 6 MODEM DATA NO END TYPE This type enumerates the codes of packet data service established Member MODEM DATA 0 No data service available MODEM DATA GPRS 1 GPRS data service available MODEM DATA EDGE 2 EDGE data service available MODEM DATA UMTS 3 UMTS data service available MODEM DATA UMTS HSDPA 4 UMTS HSDPA data service available MODEM DATA UMTS HSUPA 5 UMTS HSUPA data service available MODEM DATA UMTS HSDPA HSUPA 6 UMTS HSDPA HSUPA data service available 91 Target CoDeSys Reference Manual 1 11 5 MODEM STATUS TYPE MODEM STATUS TYPE MODEM STATUS MODEM STANDBY 0 MODEM INIT 1 NET REGISTRATION 2 PPP CONNECTING 3 MODEM CONNECTED 4 PPP LINK LOST 5 MODEM DCD LOST
16. This type enumerates the current status of MODBUS slave server service Member MODBUS STANDBY 0 Service not activated MODBUS ACTIVE 100 Service activated MODBUS ERROR 200 Service stopped due to error MODBUS PARAMETER ERR 201 Service stopped parameter not valid MODBUS OPEN ERR 202 Service stopped error opening port RTU socket TCP MODBUS OPTION ERR 203 Service stopped error setting socket option MODBUS BIND ERR 204 Service stopped error binding listen socket to local address MODBUS LISTEN ERR 205 Service stopped error activating listen on socket Related Topics MB RTU Slave MB TCP Server 152 Target CoDeSys Reference Manual 1 16 3 MB_RTU_Deinit FUNCTION MB_RTU_Deinit BOOL Deinitializes the MODBUS RTU on RS485 RS232 for expansion communication Return Value Always TRUE Input Parameters None Comments Use this function to deinitialize the MODBUS RTU communication over RS485 RS232 with expansion slaves Normally for the continuous refreshing of the slave resources the communication is initialized only at poweron leaving always on So this function is not normally used Related Topics Init 153 Target CoDeSys Reference Manual 1 16 4 Init FUNCTION MB RTU Init UINT VAR INPUT Port PORTS Baudrate UDINT Parity MB RTU PARITY Rsp Timeout UINT END VAR Initializes the MODBUS RTU on RS485 RS232 for expansion communication Return Value 0
17. for each byte in RTU mode is Coding System 8 bit binary Bits per Byte 1 start bit 8 data bits least significant bit sent first 1 bit for parity completion 1 stop bit Even parity is required other modes odd parity no parity may also be used In order to ensure a maximum compatibility with other products it is recommended to support also No parity mode The default parity mode must be even parity Remark the use of no parity requires 2 stop bits Each character or byte is sent in this order left to right Least Significant Bit LSB Most Significant Bit MSB With Parlty Checking ras Se Figure 10 Bit Sequence in RTU mode Devices may accept by configuration either Even Odd or No Parity checking If No Parity is implemented an additional stop bit is transmitted to fill out the character frame to a full 11 bit asynchronous character Without Parity Checking d sls us Figure 11 Bit Sequence in RTU mode specific case of No Parity Frame Checking Field Cyclical Redundancy Checking CRC Modbus org http www modbus org 12 44 Dec 20 2006 151 Target CoDeSys Reference Manual 1 16 2 MODBUS STATUS TYPE MODBUS STATUS TYPE MODBUS STATUS MODBUS STANDBY 0 MODBUS ACTIVE 100 MODBUS ERROR 200 MODBUS PARAMETER ERR 201 MODBUS OPEN ERR 202 MODBUS OPTION ERR 203 MODBUS BIND ERR 204 MODBUS LISTEN ERR 205 END TYPE
18. parity error detected overrun occurred on receiver data is available in rx buffer 134 Target CoDeSys Reference Manual 1 14 10 Rs485IsByteAvailable FUNCTION Rs485IsByteAvailable INT VAR INPUT dwHandle DWORD END VAR Peek if received data is available without removing the data from the internal receive buffer Return Value Returns the received byte or 1 in case of an invalid parameter or no data available Input Parameters dwHandle Port handle returned by Rs485ComOpen Comments The only difference to Rs485ReceiveByte is that with Rs485IsByteAvailable the received byte is not removed from the receive buffer Related Topics Rs485ReceiveByte 135 Target CoDeSys Reference Manual 1 14 11 Rs485Purgelnput FUNCTION Rs485Purgelnput BOOL VAR_INPUT dwHandle DWORD END_VAR Discards the contents of the serial receive buffer Return Value TRUE success FALSE error Input Parameters dwHandle Port handle returned by Rs485ComOpen Comments All data in the serial receive buffer will be discarded and not be read Related Topics Rs485FlushOutput Rs485PurgeOutput 136 Target CoDeSys Reference Manual 1 14 12 Rs485PurgeOutput FUNCTION Rs485PurgeOutput BOOL VAR_INPUT dwHandle DWORD END_VAR Discards the contents of the serial transmit buffer Return Value TRUE success FALSE error Input Parameters dwHandle Port handle returned by Rs485ComOpen Comments All data in
19. 1005 Query parameter is not defined 2001 MySQL connection error 2002 Error selecting database 2003 Error executing query 3001 no tag received for the error code 3002 no tag received for number of rows records 3003 no tag received for result set available 3004 no tag received for number of fields columns 3005 no tag received for field names 3006 no tag received for field lengths 3007 no tag received for the result set row Input Parameters Query The query string to execute on the MySQL database Comments This function sends a query to the MySQL database that is currently selected by MySQL Database Set To prepare the query string passed directly to the database server refer to the official MySQL documentation The query INSERT UPDATE DELETE CREATE ALTER DROP do not return a result set a set of data readed from the database Queries such as SELECT SHOW DESCRIBE EXPLAIN instead save the result set into a buffer from which are then extracted values of the table rows with appropriate fetch functions The function returns 0 if it executes without error otherwise returns the error code The error code can be any of those provided by the function HTTP Get used to access the interface PHP page or a specific error code of PHP script execution Related Topics MySQL Connect Set MySQL Database Set 123 Target CoDeSys Reference Manual 1 13 10 MySQL_Result FUNCTION MySQL_Result STRING VAR_INPUT Cell S
20. 194 pE Napureldp 195 2A ETPUSER 196 c7 197 2 6 c esee nene ates e 198 199 258 NP CEG 200 AMI xd e 201 2 10 NETMASK qee 202 Bl cpm EE 203 2 12 REBOOT MEI 204 2 13 SETDATETIME 205 2 555 tous sees ib en save dunes 206 215 VER 207 2 16 WEBPASSWORD eaaet Feeder ene eed acre pue ena Duane On Cue po ver 208 2 17 WEBUSER 209 3 Error handling Target CoDeSys Reference Manual Target CoDeSys Reference Manual 1 Target libraries The libraries below provide access to the special hardware and software functionalities of the specific target They are implemented on the target system and can be used by the CoDeSys project In simulation mode the target system is not reachable To allow running a CoDeSys project which uses these libraries in simulation mode there will be dummy functions called instead T
21. 2 Quantity The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB TCP Rsp function to which are added those of the specific command Related Topics MB TCP Rd Hold Regs MB TCP Wr Single Reg 181 Target CoDeSys Reference Manual 1 16 25 MB_TCP_Wr_Rd_Hold_Regs FUNCTION MB_TCP_Wr_Rd_Hold_Regs UINT VAR_INPUT Socket INT Slave Add BYTE Wr Address WORD Wr Quantity WORD Wr Data DWORD Rd Address WORD Rd Quantity WORD Rd Data DWORD END VAR Executes the MODBUS TCP IP function code 23 Write Read Multiple Registers Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Wr Address Address of first word to be write Wr_Quantity Number of words to be write Wr_Data Pointer of data buffer for writing Rd Adaress Address of first word to be read Rd Quantity Number of words to be read Rd Data Pointer of data buffer for reading Comments The function simultaneously writes and reads the value of one or more words of memory Holding Registers into and from a specific server slave using the MODBUS TCP IP protocol This is based on Rsp generic communication function for which operates as an interface with the specific command c
22. Address parameter is the starting word address to read Quantity parameter indicates the number of words to be read Data parameter is the pointer of the buffer in which receive the values of the words The amount of bytes placed in the receive buffer is equal to Data Len 2 Quantity The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB TCP Rsp function to which are added those of the specific command Related Topics MB TCP Wr Hold Regs MB TCP Wr Single Reg 174 Target CoDeSys 1 16 20 MB_TCP_Rd_Input_Regs FUNCTION MB_TCP_Rd_Input_Regs UINT VAR_INPUT Socket INT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Reference Manual Executes the MODBUS TCP IP function code 4 Read Input Registers Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Address Address of first word to be read Quantity Number of words to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more words of input protocol This is based on MB TCP Req Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific conne
23. Closes a connection Return Value TRUE success FALSE error Input Parameters diSocket Socket descriptor diHow Must be equal to null Target CoDeSys Reference Manual 47 Target CoDeSys Reference Manual 1 3 The RTOS functions library rtos lib The RTOS library offers various functions of the underlying Real Time Operating System to the PLC programmer These functions include IP configuration device names and versions and message exchange functions Some of the functions are only useful on controllers supporting parallel execution of DOS EXE programs others can also be used in pure PLC applications Here is a list of all the functions and data type this library offers TYPE MSG EX RtosCreateMsg RtosDeleteMsg RtosDhcpUse RtosFindMsg RtosGetBootstrapVersion RtosGetDevicenames RtosGetDhcpStat RtosGetlniEntry RtosGetlniEntryEx RtosGetLinkstate RtosGetMacAddress RtosGetMsg RtosGetRebootReason RtosGetVersion RtosGetVersionString Rtoslpconfig RtosReboot RtosSendMsg RtosServers RtosSetlniEntry RtosSetlniEntryEx 48 Target CoDeSys Reference Manual 1 3 1 TYPE MSG_EX TYPE MSG_EX TYPE MSG_EX STRUCT msgID UINT 0 nameO USINT 77 M USINT 83 S name2 USINT 71 G name3 USINT 88 X mbO INT 2 mb1 INT 2 mb2 INT 2 mb3 INT 2 END STRUCT END TYPE This structure contains information about a message
24. IP address of DNS server 2 Retry_Timer Remaining time to the reconnection Comments This function block provides a permanent Internet connection using PPP with a modem of 1 type Refer to the documentation of the target to verify the type of modem available The function block once activated with the Start signal starts a connection procedure that could during certain phases block the execution of the POU for relatively long periods When the connection is established shall enter into a permanent state with a minimum processing time For this reason the function block must be inserted into a POU of the IEC program updated by a dedicated task When the connection is established the Ready output becomes TRUE and from this moment should be considered the execution of other parts of the POU such as the activation of DynDNS Client function block By setting the Start signal to FALSE shall start a procedure for disabling the modem connection and shutdown The configuration parameters passed as input to the function block are not all necessary for the connection Refer to specific settings of the service provider Moreover for each parameter that is not explicitly defined in the function block the value in the CHIP INI configuration file is used and if not available in that file it uses a fixed default value Sim_Pin disabled Auth No User disabled Password disabled Connect String AT CGDCONT 1 IP ibox tim it
25. Value keepalive interval in seconds min 10 max 32767 default 7200 diOption SOCKET SO SNDBUF Value type DINT Value Sendbuffer size for that socket in bytes default 4096 for TCP 2048 for UDP We recommend a maximum size of 8192 bytes diOption SOCKET SO RCVBUF Value type DINT Value Receivebuffer size for that socket in bytes default 4096 for TCP 2048 for UDP We recommend a maximum size of 8192 bytes diOption SOCKET SO ERROR Value type DUINT Value Last error occurred on that socket error codes see below SOCKET IPPROTO TCP diOption SOCKET TCP NODELAY Value type INT Value 1 disable nagle algorithm 0 nagle algorithm is enabled default 0 29 Target CoDeSys Reference Manual Socket error codes 201 Operation not permitted 202 No such file or directory 203 No such process 204 Interrupted system call 205 Input output error 206 Device not configured 209 Bad file descriptor 210 No child processes 211 Cannot allocate memory 213 Permission denied 214 Bad address 217 File exists 219 Operation not supported by device 220 Not a directory 221 Is a directory 222 Invalid argument 224 No resource available 235 Operation would block 236 Operation now in progress 237 Operation already in progress 238 Socket operation on non socket 239 Destination address required 240 Message too long 241 Protocol wrong type for socket 242 Protocol not available 243 Protocol not supported 24
26. success 128 initialization parameter not valid 129 inizialization error Input Parameters Port Serial port number Baudrate Speed of communication 300 1M bits s Parity Parity select 0 1 2 NO ODD EVEN Rsp_Timeout Maximum wait ms for slave response reception for example 10 Comments Use this function to initialize the MODBUS RTU communication over RS485 RS232 with expansion slaves This function must be called before executing a MODBUS communication Normally for the continuous refreshing of the slave resources the communication is initialized only at poweron leaving always on Related Topics MB RTU Deinit 154 Target CoDeSys Reference Manual 1 16 5 MB_RTU_Rd_Coils FUNCTION MB_RTU_Rd_Coils UINT VAR_INPUT Slave_Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS function code 1 Read Coils Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Slave Add Slave address valid 1 247 Address Address of first bit to be read Quantity Number of bits to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more bits of memory Coils from a specific slave using the MODBUS RTU protocol This is based on MB_RTU_Req_Rsp generic communication function for which operates as an interface with the specific command code Slave Add parameter sele
27. the connection is automatically closed Coils_Ptr and Coils_Max parameters respectively define the pointer to the first byte of the area containing the bits associated with the 187 Target CoDeSys Reference Manual Coils block of the MODBUS memory model and the maximum number of addressable bits The number of bits may not be a multiple of 8 but the first bit must necessarily be aligned with the LSB of the first byte Similarly Inputs_Ptr and Inputs_Max parameters work relatively to the area containing the bits associated with Discrete inputs block of the MODBUS memory model Hold_Regs_Ptr and Hold_Regs_Max parameters respectively define the pointer to the first word of the area containing the words associated with the Holding Registers block of the MODBUS memory model and the maximum number of addressable words Similarly Input_Regs_Ptr and Input_Regs_Max parameters work relatively to the area containing the words associated with the Input Registers block of the MODBUS memory model NOTE all the elements of each block of the MODBUS model are contiguous and addressed from 0 coinciding with the initial position of the memory area pointed by the supplied parameters Related Topics MODBUS STATUS 188 Target CoDeSys Reference Manual 1 16 29 MB Swap Dword FUNCTION MB Swap Dword DWORD VAR INPUT Value DWORD END VAR Big endian Little endian conversion for the bytes of a DWORD Return Value Double word value with swapped bytes I
28. to be written The expected response is composed of 4 bytes the same as those sent Related Topics MB RTU Init MB RTU Deinit 160 Target CoDeSys Reference Manual 1 16 10 MB RTU Wr Coils FUNCTION MB RTU Wr Coils UINT VAR INPUT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS RTU function code 15 Write Multiple Coils Return Value 0 success 144 Quantity parameter not valid 146 replay with address not valid 148 replay with quantity not valid Input Parameters Slave Add Slave address valid 1 247 Address Address of first bit to be write Quantity Number of bits to be write Data Pointer of data buffer for writing Comments The function writes the status of one or more bits of memory Coils into a specific slave using the MODBUS RTU protocol This is based on MB_RTU_Req_Rsp generic communication function for which operates as an interface with the specific command code Slave_Add parameter selects the specific slave on serial bus Address parameter is the starting bit address to write Quantity parameter indicates the number of bits to be write Data parameter is the pointer of the buffer containing the values of the bits to be written The LSB of the first byte of the buffer contains the status to write into the addressed bit The number of bytes in the buffer to be sent must be equal to Data Len Quantity 8 where if remainder gt 0 then Data
29. Call Active BOOL Call ID Phone STRING 20 Call Rings UINT Command Replay STRING 300 END VAR VAR State INT Data Service MODEM DATA SERVICE My IP STRING 15 Remote IP STRING 15 Netmask STRING 15 DNS1 STRING 15 DNS2 STRING 15 Last_IP STRING 15 Retry_Timer INT Retry Counter UDINT END VAR Function block to establish a permanent Internet connection with PPP for GMO1 modem Within the same radio connection all other services like SMS and incoming outgoing calls are allowable Input Variables Start Activation signal If FALSE starts the shutdown procedure PPP Disable Disable the PPP data connection allowing only SMS and Calls DynDNS Enable Enable the DynDNS client function Seconds Number of seconds before retrying the connection 1 undefined 99 Target CoDeSys Reference Manual Char_Set Characters set used in text messages according to the MODEM_CHAR_SET type SMS_Send_Start Activation signal for sending SMS SMS_Send_Phone Phone number to send the SMS SMS_Send_Text Text of the SMS to be sent SMS_Get_Start Activation signal for getting SMS Call_Send_Start Activation signal for sending an outgoing call Call_Send_Phone Phone number of outgoing call Call_Hang_Up Signal for incoming outgoing call hang up Command Activation of a specific request to modem Command_Data Optional data for a specific request to modem Output Variables Ready Connection r
30. FALSE error Input Parameters dwHandle Handle to event which should be set Target CoDeSys Reference Manual 74 Target CoDeSys Reference Manual 1 4 4 SysEventWait FUNCTION SysEventWait BOOL VAR_INPUT dwHandle DWORD dwTimeout DWORD END VAR Wait for an event to occur Return Value TRUE success event occurred within timeout period FALSE error or timeout Input Parameters dwHandle Handle to event which should be waited for dwTimeout Timeout in ms after which the function will return at the latest 75 Target CoDeSys Reference Manual 1 5 The SysLibCallback library SysLibCallback lib The implementation of the SysLibCallback lib on the CoDeSys Platform is identical with the standard CoDeSys SysLibCallback documentation So we request you to use that documentation Important Note For a stable operation of the RTS it is very important that the callback function is defined exactly as described in the 3S online help Such a function may not have any local variables If local variables are needed an empty Wrapper function must be used 76 Target CoDeSys Reference Manual 1 6 The SysLibDir library SysLibDir lib The implementation of the SysLibDir lib on the CoDeSys Platform is identical with the standard CoDeSys SysLibDir documentation So we request you to use that documentation Comments The File DateTime field of the DIRECTORY_INFO stucture is not supported yet Use the function SysFile
31. FALSE error Input Parameters pHostName Pointer to a variable of type STRING in which the hostname will be written minimal 16 chars diNameLength Length of the string in which the hostname will be written minimal 16 26 Target CoDeSys Reference Manual 1 2 14 SysSockGetLastErrorSync FUNCTION SysSockGetLastErrorSync DINT VAR_INPUT diSocket DINT END_VAR Return error code of last socket error Return Value Error code of last occurred socket error Input Parameters diSocket Socket descriptor Comments Socket error codes 201 Operation not permitted 202 No such file or directory 203 No such process 204 Interrupted system call 205 Input output error 206 Device not configured 209 Bad file descriptor 210 No child processes 211 Cannot allocate memory 213 Permission denied 214 Bad address 217 File exists 219 Operation not supported by device 220 Not a directory 221 15 a directory 222 Invalid argument 224 No resource available 235 Operation would block 236 Operation now in progress 237 Operation already in progress 238 Socket operation on non socket 239 Destination address required 240 Message too long 241 Protocol wrong type for socket 242 Protocol not available 243 Protocol not supported 244 Socket type not supported 245 Operation not supported 246 Protocol family not supported 247 Address family not supported by protocol family 248 Address already in use 249 Can t assign
32. Input Parameters dwHandle Port handle returned by Rs485ComOpen pBuffer Pointer to data to send can be obtained using the ADR function count Number of bytes to send Related Topics Rs485SendByte Rs485ReceiveByte Rs485ReceiveByte 140 Target CoDeSys Reference Manual 1 14 16 Rs485SendBreak FUNCTION Rs485SendBreak BOOL VAR_INPUT dwHandle DWORD length RS485_BREAK END_VAR Sends a break signal on a serial port Return Value TRUE success FALSE error Input Parameters dwHandle Port handle returned by Rs485ComOpen length Length of the break pulse enumeration type Comments A short break is a continuous Low on the TXD output for a duration of more than one frame transmission time M where M startbit data bits parity bit stop bit A long break is a continuous Low on the TXD output for a duration of more than two frame transmission times plus the transmission time for three additional bits 2M 3 An extra long break is a continuous Low on the TXD output for a duration of more than three frame transmission times Related Topics Rs485GetStatus 141 Target CoDeSys Reference Manual 1 14 17 Rs485SendByte FUNCTION Rs485SendByte INT VAR INPUT dwHandle DWORD ch BYTE END VAR Sends a byte of data to a serial port Return Value Returns 0 if no buffer space to store character available or 1 on success or 1 on invalid parameter Input Parameters dwHandle Port han
33. Len Data Len 1 The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command Related Topics MB RTU Rd Coils MB RTU Wr Single Coil 161 Target CoDeSys Reference Manual 1 16 11 MB RTU Wr Hold Regs FUNCTION MB RTU Wr Hold Regs UINT VAR INPUT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS RTU function code 16 Write Multiple Registers Return Value 0 success 144 Quantity parameter not valid 146 replay with address not valid 148 replay with quantity not valid Input Parameters Slave Add Slave address valid 1 247 Address Address of first word to be write Quantity Number of words to be write Data Pointer of data buffer for writing Comments The function writes the status of one or more words of memory Holding Registers into a specific slave using the MODBUS RTU protocol This is based on Rsp generic communication function for which operates as an interface with the specific command code Slave Add parameter selects the specific slave on serial bus Address parameter is the starting word address to write Quantity parameter indicates the number of words to be write Data parameter is the pointer of the buffer containing the values of the words to be written The number of bytes in th
34. MB TCP Wr Single Coil 180 Target CoDeSys Reference Manual 1 16 24 MB_TCP_Wr_Hold_Regs FUNCTION MB_TCP_Wr_Hold_Regs UINT VAR_INPUT Socket INT Slave_Add BYTE Address WORD Quantity WORD Data DWORD END_VAR Executes the MODBUS TCP IP function code 16 Write Multiple Registers Return Value 0 success 144 Quantity parameter not valid 146 replay with address not valid 148 replay with quantity not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Adaress Address of first word to be write Quantity Number of words to be write Data Pointer of data buffer for writing Comments The function writes the status of one or more words of memory Holding Registers into a specific server slave using the MODBUS TCP IP protocol This is based on MB TCP Req Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific connection on which execute the request Slave Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet Address parameter is the starting word address to write Quantity parameter indicates the number of words to be write Data parameter is the pointer of the buffer containing the values of the words to be written The number of bytes in the buffer to be sent must be equal to Data Len
35. MySQL 4 eese nnne nnn nnns 114 1 13 MySQL Connect Set roter ete etre e eoe Cet teu dee bo tese eee tene eo eec Qe eeu heed eo ege ee eed eee 115 1 13 2 MySQL Data Seek Monta ee Penne 116 1 13 3 MySQL Database Sea tatto e a Rea ede Ree T pecca deque ue 117 uim MYSQL oa 118 1 13 5 MySQL Field Len tette treten tetto tetto ttt 119 1 13 6 MySQL Field che parken tat ona ie bo Eva cuerda aera e 120 1 13 7 MySQL _Num_FieldS s o etr 121 1 13 8 MySQL N M ROW itio oec te tein athe ioe a tice aches rub ce Qu acne Eo beoe each ue ro ES uou eue 122 1 13 9 5 123 1 13 10 MySQL_Result er St 124 1 14 The RS485 Serial library 485 16 ccecccssecesscecsssccesseceessecessecesssecessececseecesseecsseeecsaeceseeesseeccaueecaaecesees 125 1 14 1 TYPE RS485 BREAK 126 Target CoDeSys Reference Manual 1 14 2 TYPE RS485 FLOW CTR Levees e intere 127 1 14 3 TYPE RS485 op 128 Ra NEN aME 129 1 14 5 TYPE RS485 PORTS 2 0 130 1 14 RCchECISDII san ee Rizk sak
36. NETMASK The NETMASK command sets the subnet mask of the ethernet interface After setting the IP configuration the ethernet interface must be reinitialized using the IPETH command Command Syntax netmask XXX XXX XXX XXX Example netmask 255 255 255 0 Related Topics GATEWAY command IP command IPETH command 202 Target CoDeSys Reference Manual 2 11 PING The PING command allows to check if a particular other computer can be reached via the network After starting PING four packets of data are sent to the other computer which will then send a reply back to the controller The result of the PING number of packets successfully received will then be displayed in the PLC Browser Note that while waiting for the reply a series of numbers is output in the PLC Browser to indicate that the command is still in process Command Syntax ping XXX XXX XXX XXX Example ping 192 168 1 2 203 Target CoDeSys Reference Manual 2 12 REBOOT This command reboot the CPU and restart the execution of all services and programs NOTE after this comand the communication with PLC is lost for some seconds Command Syntax reboot 204 Target CoDeSys Reference Manual 2 13 SETDATETIME The SETDATETIME command writes the updated Date and Time into controller The format of Date and Time is the same of DT data type Command Syntax setdatetime yyyy mm dd hh mm ss Example setdatetime 2010 04 29 16 35 40 Related Topics GETDATETIME comm
37. Ptr Pointer to bit addressable area for Coil elements Coils Max Maximum number of Coil elements Inputs Ptr Pointer to bit addressable area for Discrete Input elements Inputs Max 167 Target CoDeSys Reference Manual Maximum number of Discrete Input elements Hold_Regs_Ptr Pointer to word addressable area for Holding Register elements Hold_Regs_Max Maximum number of Holding Register elements Input_Regs_Ptr Pointer to word addressable area for Input Register elements Input_Regs_Max Maximum number of Input Register elements Output Variables Ready Service ready flag Status Current status of the service Internal Variables State Current status of the state graph of the function block Frame_Timeout Calculated maximum time x 1us for frame receiving Baud_Low Selected baudrate is less equal to 115200 Delete_Echo Deleting of RS485 driver echo automatically defined on specific hardware Comments This function block installs a permanent slave service with MODBUS RTU protocol The function block once activated with the Start signal initializes the communication and then enter into a state of service activity In the active state the block awaits the arrival of a command frame from MODBUS master When the frame is received it is checked and if the command is correct for the specific slave the response is transmitted To deactivate the service the Start signal must be forced FALSE Port parameter identifies the serial
38. Regs Ptr POINTER TO WORD Hold Regs Max UINT Input Regs Ptr POINTER TO WORD Input Regs Max UINT END VAR VAR OUTPUT Ready BOOL Status MODBUS STATUS END VAR VAR State INT Listen Socket NT Accepted Socket 7 OF INT Highest Socket NT Socket Flags ARRAY 0 15 OF WORD END VAR Function block to establish a permanent MODBUS TCP IP server function Input Variables Start Activation signal Port TCP IP port number Default to 502 Keepalive En Activation of Keepalive feature Default to TRUE Keepalive Time Idle time s before Probes sending Range 10 32767 default to 7200 Keepalive Intv Time s interval between Probes Range 1 600 default to 75 Keepalive Maximun number of Probes before connection close Range 0 32767 default to 8 Coils Ptr Pointer to bit addressable area for Coil elements Coils Max Maximum number of Coil elements 186 Target CoDeSys Reference Manual Inputs_Ptr Pointer to bit addressable area for Discrete Input elements Inputs_Max Maximum number of Discrete Input elements Hold_Regs_Ptr Pointer to word addressable area for Holding Register elements Hold_Regs_Max Maximum number of Holding Register elements Input_Regs_Ptr Pointer to word addressable area for Input Register elements Input_Regs_Max Maximum number of Input Register elements Output Variables Ready Service ready flag Status Current status of the service Inte
39. TCP IP functions error 1 2 4 8 16 SSL functions error Input Parameters Request URL of the requested resource max 2000 characters Result String to receive the response max 4000 characters Result_Max_Len Max number of characters to receive DNS Specific DNS server address Comments This function sends a request to a web server using an URL with GET method and returns all the string including header of the page The Request parameter is the string containing the request with the form Username Password Host Port Path Query Username Password send optional authorization fields Host address of the server that has the resource Port select a port other than the default 80 Path full path to the server resource Query parameters to send 1 2 3 222 The Result parameter is the string in which to insert the response from the server This response contains a header typical of HTTP followed by the actual output of the server body The header and the body are separated by a blank line which can be searched as the beginning of the body part The Result Max Len parameter is the maximum number of characters to receive in the response string The DNS parameter allows the specification of a different DNS server which has priority over the default setting into CHIP INI configuration file The SSL connections require an enabling and configuration using the file CHIP INI refer
40. Time Clock device The value returned is of SystemTimeDate type defined into SysLibTime lib standard library You advises to periodically execute the function for example at intervals of 1s to refresh the value of date and time into a global variable Related Topics RTC_Write 85 Target CoDeSys Reference Manual 1 10 3 RTC_Write FUNCTION RTC_Write BOOL VAR_INPUT Enable BOOL Setup SystemTimeDate END_VAR Updates current date and time into Real Time Clock Return Value TRUE Success FALSE Error Input Parameters Enable Enable the function execution Setup Value of SystemTimeDate type to be forced into Real Time Clock Comments This function updates date and time into external Real Time Clock device The value to be forced is of SystemTimeDate type defined into SysLibTime lib standard library Related Topics RTC Read 86 Target CoDeSys Reference Manual 1 11 The MODEM library MODEM_Lib lib This library offers the functions for the management of the MODEM Refer to the documentation of the specific Target to check the availability and type of modem Here is a list of all the functions this library offers TYPE DYNDNS STATUS TYPE MODEM CHAR SET TYPE MODEM COMMAND TYPE MODEM DATA SERVICE TYPE MODEM STATUS DynDNS Client 1 PPP GMO1 PPP SMS Call GMO1 SMS NOTE GMO1 PPP and GMO1 SMS function blocks perform the functions limited to their type of service and cann
41. USINT END VAR VAR State INT Data_Service MODEM_DATA_SERVICE My STRING 15 Remote IP STRING 15 Netmask STRING 15 DNS1 STRING 15 DNS2 STRING 15 Retry Timer NT END VAR Function block to establish a permanent Internet connection with PPP for GMO1 modem Input Variables Start Activation signal If FALSE starts the shutdown procedure Sim Pin Pin code of the data SIM Default is disabled Auth Authorization type 1 undefined 0 1 PAP 2 CHAP 3 PAPPEER 4 CHAPPEER User Username for the PPP connection Required if Auth gt 0 Password Password for the PPP connection Required if Auth gt 0 Connect String Connection string with the APN Example AT CGDCONT 1 IP ibox tim it Dial Call string with the dial number Example ATD 99 13 Seconds Number of seconds before retrying the connection 1 undefined Output Variables 96 Target CoDeSys Reference Manual Ready Connection ready flag The Internet link is available Status Current status of the connection Signal Field strength of the radio network 02Min 10 Max Internal Variables State Current status of the state graph of the function block Data Service Information about the Packet Data Service type of the connection My IP address assigned by service provider IP Remote IP address of the peer to peer connection Netmask Netmask value for the subnet DNS1 IP address of DNS server 1 DNS2
42. character The SSL connections require an enabling and configuration using the file CHIP INI refer to the administration pages The E mail address of the recipient is set into To_Address parameter The Subject parameter is a string that describe the object of the E mail Any attached file to the E mail can be indicated by the File parameter The attached file must reside on a accessible disk of the system The text of E mail must be passed using the Text string The use special of characters as N for new line and L for line feed are allowed Example Result SendMail 192 168 1 101 MyTarget gmx com MyTarget 213 165 64 45 username password infog destination com E mail test A PLC_PRG Attached txt This is the E mail text 112 Target CoDeSys Reference Manual 1 12 4 SNTP_DateTime FUNCTION SNTP_DateTime BOOL VAR_INPUT Server_IP STRING TimeZone INT Daylight_Save BYTE END_VAR Synchronizes Real Time Clock with the specified NTP server Return Value TRUE success FALSE error Input Parameters Server_IP IP address of NTP server TimeZone Geographical zone offset UTC n Daylight_Save Daylight saving enable 1h Comments This function connects to a NTP server and request the reference date and time The IP address of NTP server can be specifies in the format xxx xxx xxx xxx or with the string of address name in this case the internal DNS resolver is
43. into a DWORD for the INADDR struct Return Value IP Address as DWORD This return value will be used to specify the field 5 addr of the INADDR struct Input Parameters stlPAddr IP address string e g 192 168 100 1 33 Target CoDeSys Reference Manual 1 2 19 SysSocklnetNtoa FUNCTION SysSocklnetNtoa BOOL VAR INPUT POINTER to INADDR plPAddr POINTER to STRING dilPAddrSize DINT END VAR Converts a IP address from INADDR format to String Return Value TRUE success FALSE error Input Parameters pinAddr Pointer to structure INADDR which contains the IP address plPAdar Pointer to String where the IP address in String format should be stored dilPAdarSize Size of the plPAddr String 34 Target CoDeSys Reference Manual 1 2 20 SysSockloctl FUNCTION SysSockloctl DINT VAR_INPUT diSocket DINT diCommand DINT piParameter POINTER END VAR Manipulates a socket Return Value Depends on dicommand parameter Input Parameters diSocket Socket descriptor diCommand Command which specifies what should be done with the socket see below piParameter Pointer to Parameter depending on the command see below Comments Possible commands e SOCKET FIONREAD Returns the number of bytes waiting in the receive buffer Returns 0 on success and 1 on error O Parameter Pointer to DINT where the number of bytes will be stored SOCKET FIONBIO Switches the socket be
44. of Add Cmd parameter that contains the address command is transmitted with the 9 bit forced to 1 If TxNum gt 0 are then transmitted TxNum bytes pointed by IO Ptr The checksum XOR of the only data bytes is finally trasmitted At the end is attended the 0 value to confirm the correct reception by the slave Else if Rx Num 0 is attended the reception of Rx Num bytes plus checksum saving the values in a temporary buffer Verified the checksum the buffer is copied to the area pointed by IO Ptr The Swap parameter flips the order of the bytes from big endian to little endian and vice versa for word values set Swap to 2 and for dword values set Swap to 4 This is also applied for array of words or dwords Related Topics 5485 Init A 148 Target CoDeSys Reference Manual 1 16 The MODBUS library MODBUS_Lib lib This library offers the functions for the management of the slave expansions using MODBUS protocol A complete refresh of slave expansion resources is obtained using this functions into IEC program Here is a list of all the functions this library offers TYPE MB RTU PARITY TYPE MODBUS STATUS MB RTU Deinit MB RTU Init MB RTU Rd Coils MB RTU Rd Hold Regs MB RTU Rd Input Regs MB RTU Rd Inputs MB RTU Req Rsp MB RTU Wr Coils MB RTU Wr Hold Regs MB RTU Wr Rd Hold Regs MB RTU Wr Single Coil MB RTU Wr Single Reg MB RTU Slave MB TCP Connect MB TCP Disconnect MB TCP Rd Coils MB TCP Rd Hold Regs MB TCP Rd Inp
45. of SMTP server E mail account Username Username for SMTP server login E mail account Password Password for SMTP server login E mail account To Adaress Address of the recipient of E mail Subject Description of the E mail subject not necessary Attached File Path name of attached file not necessary Text Text of the E mail not necessary Comments 111 Target CoDeSys Reference Manual This function connects to a SMTP server and sends an E mail to a destination address The first six parameters are normally fixed because they define the sender informations and the specific E mail account on a SMTP server The data of the account are furnished by the provider of E mail service Local_IP From_Address and From_Alias parameters identify the sender that is the IEC system calling this function to send mail For the purposes of sending mail are not necessary but however their definition allows the recipient to know the origin of the message Server_Add Username and Password parameters are instead mandatory because they must match those of the E mail account that is activated by a SMTP service provider The Server_Add parameter can be specified in the format xxx xxx xxx xxx or by the server name In this case the DNS client is used to resolve the IP address of the name The communication with the server use the standard port 25 A different port can be specified in the Server_Add parameter adding the port number after the separator
46. phases block the execution of the POU for relatively long periods When the connection is established shall enter into a permanent state with a minimum processing time For this reason the function block must be inserted into a POU of the IEC program updated by a dedicated task The Ready output signal indicates that the modem is connected and the Status output variable assumes the MODEM CONNECTED value The Signal output variable indicates the field strength of the radio connection By setting the Start signal to FALSE shall start a procedure for disabling the modem connection and shutdown 101 Target CoDeSys Reference Manual The PPP data connection is set by default but can be disabled forcing PPP_Disable input signal to TRUE value This allows the use of function block only for SMS and calls If the data connection is enabled the default address of device gateway is redefined using the IP value provided by the network operator allowing a permanent radio connection to the Internet If DynDNS Enable signal is active as soon as the PPP connection is established a new update of IP address on DynDNS server is also executed When the modem is connected the SMS send receive services can be executed The SMS Send Start input signal forces the graph of the function block in the state of sending the SMS according to the previously prepared data The result of the operation is indicated by the value of the Status output variable The SMS
47. port 1 3 used for communication Coils_Ptr and Coils_Max parameters respectively define the pointer to the first byte of the area containing the bits associated with the Coils block of the MODBUS memory model and the maximum number of addressable bits The number of bits may not be a multiple of 8 but the first bit must necessarily be aligned with the LSB of the first byte Similarly Inputs_Ptr and Inputs_Max parameters work relatively to the area containing the bits associated with Discrete inputs block of the MODBUS memory model Hold_Regs_Ptr and Hold_Regs_Max parameters respectively define the pointer to the first word of the area containing the words associated with the Holding Registers block of the MODBUS memory model and the maximum number of addressable words Similarly Input_Regs_Ptr and Input_Regs_Max parameters work relatively to the area containing the words associated with the Input Registers block of the MODBUS memory model NOTE all the elements of each block of the MODBUS model are contiguous and addressed from 0 coinciding with the initial position of the memory area pointed by the supplied parameters Related Topics 168 Target CoDeSys Reference Manual MODBUS STATUS 169 Target CoDeSys Reference Manual 1 16 16 MB TCP Connect FUNCTION MB TCP Connect UINT VAR INPUT Address STRING Port Keepalive En BOOL Keepalive Time NT Keepalive Intv NT Keepalive Retry INT Rsp Timeout UINT
48. requested address 250 Network is down 251 Network is unreachable 252 Network dropped connection on reset 253 Software caused connection abort 254 Connection reset by peer 255 No buffer space available 256 Socket is already connected 257 Socket is not connected 258 Can t send receive after socket shutdown There is no more data to be received 259 Too many references can t splice 260 Operation timed out 27 Target CoDeSys Reference Manual 261 Connection refused 264 Host is down 265 No route to host 28 Target CoDeSys Reference Manual 1 2 15 SysSockGetOption FUNCTION SysSockGetOption BOOL VAR_INPUT diSocket DINT diLevel DINT diOption DINT pOptionValue POINTER piOptionValueLength POINTER to DINT END VAR Reads the setting of specified socket and the specified option Return Value TRUE success FALSE error Input Parameters diSocket Socket descriptor Option which should be read see below Pointer to a variable to store the option value see below Pointer to an DINT which tells the size of the variable to which pOptionValue points see below diLevel Protocol level diOption pOptionValue piOption ValueLength Comments Supported Options diLevel diLevel SOCKET SOL diOption SOCKET SO REUSEADDR Value type INT Value 1 enable reuse address 0 disable reuse address default 1 diOption SOCKET SO KEEPALIVE Value type INT
49. the CHIP INI file this is not possible because FRAM is directly handled by the operating system This library offers the following functions FRAM Read FRAM Write 80 Target CoDeSys Reference Manual 1 9 1 FRAM_Read FUNCTION FRAM_Read BOOL VAR_INPUT Address UINT NumBytes UINT Buffer DWORD END VAR Reads a FRAM memory area Return Value TRUE success FALSE error Input Parameters Address Start address of FRAM memory area 0 8191 BumBytes Number of bytes to read Buffer Pointer to buffer where to store readed bytes use ADR function Comments This function reads an array of bytes from external FRAM device External FRAM device has a dimension of 8Kbytes 8192 bytes and is addressed from 0 to 8191 For the pointer value of a IEC variable to store the readed bytes ADR function can be used Related Topics FRAM_Write 81 Target CoDeSys Reference Manual 1 9 2 FRAM_Write FUNCTION FRAM_Write BOOL VAR_INPUT Address UINT NumBytes UINT Buffer DWORD END VAR Writes a FRAM memory area Return Value TRUE success FALSE error Input Parameters Address Start address of FRAM memory area 0 8192 BumBytes Number of bytes to read Buffer Pointer to buffer where to store readed bytes use ADR function Comments This function writes an array of bytes into external FRAM device External FRAM device has a dimension of 8Kbytes 8192 bytes and is addresse
50. the Output buffer 10 Target CoDeSys Reference Manual 1 1 3 SysComReadLine FUNCTION SysComReadLine DWORD VAR_INPUT dwHandle DWORD dwBufferAddress DWORD dwMaxBytesToRead DWORD dwTimeout DWORD END VAR Read a line from the Com port until Linefeed or max chars Return Value Returns the number of characters read including linefeed 0 Error or no chars read Input Parameters dwHandle Port handle acquired by SysComOpen dwBufferAddress Address of the buffer to store the read chars dwMaxBytes ToRead Maximum number of characters to read dwTimeout Time ms after that the function returns at the latest 11 Target CoDeSys Reference Manual 1 1 4 SysComRxNum FUNCTION SysComRxNum INT VAR INPUT dwHandle DWORD END VAR Return the number of available characters in the input buffer Return Value The number of characters available Input Parameters dwHandle Port handle 12 Target CoDeSys Reference Manual 1 2 The SysLibSockets library SysLibSockets lib This chapter describes all functions which are available Important Some functions of the socket interface are blocking This means that the task which is calling the function pauses until the function can return an expected result e g SysSockRecv waits for some TCP data SysSockRecvFrom waits for receiving an UDP datagram SysSockAccept waits for an incoming connection This library offers the following functions and data types
51. the gateway or in the absence of subnets Fun_Code parameter is the code of the function to execute Req_Data parameter is the pointer to the buffer with the data to be transmitted for the specific function code Req Len parameter indicates the number of bytes in the Reg Data buffer to be transmitted to the slave Rsp Data parameter is the pointer to the buffer in which receive the data of response to the function from the slave Rsp Len parameter indicates the number of data bytes expected in the Data receive buffer as response to the specific function code The function returns 0 if performed without error otherwise it returns the error code To use the MODBUS communication function refer to the technical documentation MODBUS Application Protocol Specification downloadable at http www modbus ida org tech php In the following example one input word and one output word are refreshed for the server 192 168 1 102 PROGRAM MB TCP VAR MB TCP Connected BOOL FALSE MB TCP Socket INT Req Buf ARRAY 0 10 OF BYTE Buf ARRAY 0 10 OF BYTE Input Reg WORD Output Reg WORD END VAR Initialize MODBUS connection IF NOT MB TCP Connected THEN IF MB TCP Connect 192 168 1 102 502 TRUE 7200 75 8 1000 ADR MB TCP Socket THEN MB TCP Connected TRUE END IF END IF Read one input word at address 0 from slave 255 no RTU subnet Req Buf 0 Req Buf 1 0 Req Buf 2
52. the port in network order use function SysSockHtons sin addr IP address in DWORD format To compute the IP address in DWORD format see function SysSocklnetAdar sin zero Not used 16 Target CoDeSys Reference Manual 1 2 4 TYPE SOCKET_FD_SET TYPE SOCKET FD SET TYPE SOCKET FD SET STRUCT fd count UDINT fd array ARRAY 0 63 OF DINT END STRUCT END TYPE Contains a socket descriptor set Member fd count Number of sockets in this set fd array Socket descriptor list 17 Target CoDeSys Reference Manual 1 2 5 TYPE SOCKET_LINGER TYPE SOCKET_LINGER TYPE SOCKET_LINGER STRUCT 1 onoff WORD l linger WORD END STRUCT END TYPE Linger data type of TCP socket Member onoff On Off of linger linger Value of linger 18 Target CoDeSys Reference Manual 1 2 6 TYPE SOCKET_TIMEVAL TYPE SOCKET_TIMEVAL TYPE SOCKET_TIMEVAL STRUCT tv sec DINT tv usec DINT END STRUCT END TYPE Contains a Time specification Member tv sec Time in Seconds tv usec Time in Microseconds 19 Target CoDeSys Reference Manual 1 2 7 SysSockAccept FUNCTION SysSockAccept DINT VAR_INPUT diSocket DINT pSockAddr POINTER to SOCKADDR piSockAddrSize POINTER to DINT END_VAR Accepts an incoming connections NOTE pSockAddr sin family must be set to SOCKET_AF_INET prior to call Return Value 1 error gt 0 success new Socketdescriptor of accepted connection Input Par
53. the serial transmit buffer will be discarded and not be sent Related Topics Rs485FlushOutput Rs485Purgelnput 137 Target CoDeSys Reference Manual 1 14 13 Rs485ReceiveBlock FUNCTION Rs485ReceiveBlock UINT VAR_INPUT dwHandle DWORD pBuffer POINTER to BYTE count UINT END VAR Receives a block of data from a serial port Returns immediately if no data has been received Return Value Returns the number of bytes transferred to the buffer Input Parameters dwHandle Port handle returned by Rs485ComOpen pBuffer Pointer to buffer where to store received data count Maximum number of bytes to put into the buffer Related Topics Rs485ReceiveByte Rs485SendBlock Rs485SendByte 138 Target CoDeSys Reference Manual 1 14 14 Rs485ReceiveByte FUNCTION Rs485ReceiveByte INT VAR_INPUT dwHandle DWORD END_VAR Receives a byte of data from a serial port Returns immediately if no data has been received Return Value Returns the received byte or 1 in case of an invalid parameter or no data available Input Parameters dwHandle Port handle returned by Rs485ComOpen Related Topics Rs485SendByte Rs485SendBlock Rs485ReceiveBlock 139 Target CoDeSys Reference Manual 1 14 15 Rs485SendBlock FUNCTION Rs485SendBlock UINT VAR_INPUT dwHandle DWORD pBuffer POINTER to BYTE count UINT END VAR Sends a block of data via a serial port Return Value Returns the number of bytes sent
54. the specific slave on serial bus Wr Address parameter is the starting word address to write Wr Quantity parameter indicates the number of words to be write Wr Data parameter is the pointer of the buffer containing the values of the words to be written The number of bytes in the buffer to be sent must be equal to Wr Data Len 2 Wr Quantity Rd Address parameter is the starting word address to read Rd Quantity parameter indicates the number of words to be read Rd Data parameter is the pointer of the buffer in which receive the values of the words The amount of bytes placed in the receive buffer is equal to Rd Data Len 2 Rd Quantity The function returns O if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command 163 Target CoDeSys Reference Manual Related Topics MB RTU Rd Hold Regs MB RTU Wr Hold Regs 164 Target CoDeSys Reference Manual 1 16 13 MB RTU Wr Single Coil FUNCTION MB RTU Wr Single Coil UINT VAR INPUT Slave Add BYTE Address WORD Value WORD END VAR Executes the MODBUS RTU function code 5 Write Single Coil Return Value 0 success 145 Value parameter not valid 146 replay with address not valid 149 replay with value not valid Input Parameters Slave_Add Slave address valid 1 247 Address Address of bit to be write Value State to write
55. 0 parity Parity enumeration type wordlen Data length 7 or 8 bits stopbits Number of stop bits 1 or 2 Related Topics Rs485ComClose Rs485SetFlowcontrol 132 Target CoDeSys Reference Manual 1 14 8 Rs485FlushOutput FUNCTION Rs485FlushOutput BOOL VAR INPUT dwHandle DWORD END_VAR Waits until all data from the output buffer has been sent Return Value TRUE success FALSE error Input Parameters dwHandle Port handle returned by Rs485ComOpen Comments Be careful when using this function The controller will wait until the function is finished This might take a while if the baud rate is low and there are many characters in the buffer to send Related Topics Rs485PurgeOutput Rs485Purgelnput 133 Target CoDeSys Reference Manual 1 14 9 Rs485GetStatus FUNCTION Rs485GetStatus INT VAR_INPUT handle DWORD END_VAR Returns the status of a serial port Return Value Returns a status code bit field Input Parameters handle Port handle returned by Rs485ComOpen Comments The status bits have the following meaning bit 6 bit 5 RS485_OUTPUT_NOT_FULL bit 4 RS485_LINE_BREAK bit 3 RS485 FRAMING ERROR bit 2 5485 PARITY ERROR bit 1 RS485 OVERRUN ERROR bit 0 RS485 DATA AVAILABLE Related Topics Rs485SetFlowcontrol Rs485SendBreak Rs485ComOpen RS485 OUTPUT BUFFER EMPTY tx buffer is empty tx buffer is not full line break detected framing error detected
56. 4 Socket type not supported 245 Operation not supported 246 Protocol family not supported 247 Address family not supported by protocol family 248 Address already in use 249 Can t assign requested address 250 Network is down 251 Network is unreachable 252 Network dropped connection on reset 253 Software caused connection abort 254 Connection reset by peer 255 No buffer space available 256 Socket is already connected 257 Socket is not connected 258 Can t send after socket shutdown 259 Too many references can t splice 260 Operation timed out 261 Connection refused 264 Host is down 265 No route to host 30 Target CoDeSys Reference Manual 1 2 16 SysSockHtonl FUNCTION SysSockHtonl DWORD VAR INPUT dwHost DWORD END VAR Converts a DWORD from host byte order to network byte order in context with Big Endian and Little Endian format Return Value Converted DWORD value Input Parameters dwHost Value to convert 31 Target CoDeSys Reference Manual 1 2 17 SysSockHtons FUNCTION SysSockHtons WORD VAR_INPUT wHost WORD END_VAR Converts a WORD from host byte order to network byte order in context with Big Endian and Little Endian format Return Value Converted WORD value Input Parameters wHost Value to convert 32 Target CoDeSys Reference Manual 1 2 18 SysSocklnetAddr FUNCTION SysSocklnetAddr DWORD VAR INPUT stlPAddr STRING END VAR Converts an IP address from String
57. 5 1 5485 2 RS485 COM3 5485 4 RS485 5 5485 6 5485 7 5485 v coo ui v 3 END_TYPE This type enumerates the desired serial port Member RS485_COM1 1 RS485 COM 2 5485 3 Uart2 RS485_COM4 4 Uart3 RS485 5 Virtual Serial Interface via USB RS485 COM6 6 Virtual Serial Interface via USB RS485 COM7 7 Virtual Serial Interface via USB RS485 8 Virtual Serial Interface via USB 130 Target CoDeSys Reference Manual 1 14 6 Rs485ComClose FUNCTION Rs485ComClose BOOL VAR_INPUT handle DWORD END VAR Closes a serial communications port Return Value TRUE success FALSE error Input Parameters handle Port handle returned by Rs485ComOpen Comments Use this function to close a port that is no longer used Related Topics Rs485ComOpen 131 Target CoDeSys Reference Manual 1 14 7 Rs485ComOpen FUNCTION Rs485ComOpen DWORD VAR_INPUT port RS485_PORTS baud DINT parity RS485_PARITY wordlen INT stopbits INT END_VAR Opens a serial port Return Value Returns 16 FFFFFFFF when called with invalid parameters Otherwise a port handle is returned This handle has to be used in further calls to this interface Input Parameters port Number of desired port enumeration type baud Baud rate 110 11520
58. DhcpUse 56 Target CoDeSys Reference Manual 1 3 9 RtosGetlniEntry FUNCTION RtosGetlniEntry INT VAR INPUT pSection POINTER to STRING pltemname POINTER to STRING pltemtext POINTER to STRING len END VAR Reads an entry from the configuration file CHIP INI on the controller s flash disk Return Value 0 entry not found 1 CHIP INI not found otherwise number of characters read Input Parameters pSection Pointer to string holding the section pltemname Pointer to string holding the name of the desired entry pltemtext Pointer to string in which the text of the desired entry will be copied must be max 1en 1 size len Maximum lenghth of the target string at pltemtext not including terminating null character Comments The functions RtosGetlniEntry and RtosSetlniEntry are not reentrant Do not use these in different tasks or in combination with other functions or commands which write to CHIP INI e g the DHCP or IP configuration functions Related Topics RtosGetlniEntryEx RtosSetlniEntry RtosSetlniEntryEx 57 Target CoDeSys Reference Manual 1 3 10 RtosGetiniEntryEx FUNCTION RtosGetlniEntryEx INT VAR INPUT pFilename POINTER to STRING pSection POINTER to STRING pltemname POINTER to STRING pltemtext POINTER to STRING len END VAR Reads an entry from a specified configuration file on the controller s flash disk Return Value 0 entry not found 1 configura
59. GetTime to get this information 77 Target CoDeSys Reference Manual 1 7 SysLibPlicCtrl library SysLibPlIcCtrl lib The implementation of the SysLibPlcCtrl lib on the CoDeSys Platform is identical with the standard CoDeSys SysLibPlcCtrl documentation So we request you to use that documentation Comments The functions SysShutdownPlc SysEnableScheduling and GetPlcLoad are not supported in this Release 78 Target CoDeSys Reference Manual 1 8 The SysLibStr library SysLibStr lib The implementation of the SysLibStr lib on the CoDeSys Platform is identical with the standard CoDeSys SysLibStr documentation So we request you to use that documentation Comments The maximum length of strings is limited to 64Kb in this Release 79 Target CoDeSys Reference Manual 1 9 The FRAM library FRAM_Lib lib This library offers the functions for the management of the FRAM memory The FRAM memory Ferroelectric RAM is a memory that has all the characteristics of the ideal memory It is in fact retentive to the default of power supply without necessity of batteries high speed in writing in the order of the microseconds against the milliseconds of the EEprom Flash memory rewritetable around 10e16 times against 10e6 10e5 times of the EEprom Flash and retainment of data for 45 years The management of FRAM device is faculty of the programmer Nevertheless in the case of IEC retain memory saving into FRAM option RETAIN FRAM in
60. L dtes ret enter ende adeo hee eee heo si adeo Ote 23 1 2 VAS VSS OK CC dLG 55 etse 24 1 2 125 55 dedere aote o eee dene rented aes 25 1 2 13 5 550 ere he hagas eria cse 26 1 2 14 SysSockGetLastEFrorSync 27 1 2 15 SySSOCKGEtOPTION RRRRRRRRRREMMMEEEEEEMMEEEEEEMM 29 1 2 16 SySSOCKLHEODL eet dentes e eel 31 1 2 17 SysSockHtons iiec eed edie c dt ae On ives reser da d eer 32 1 2 18 33 1 2 19 5 55 34 1 2 20 35 1 2 21 5 37 Briss redo 38 1 2 23 SUSSOCKNEONnS cce tote terno ivre seus ictus tee mtr MM LM E 39 1 2 24 SySSOCKRECV c ses 40 1 2 25 eost riter EE Erro pua 41 1 2 26 5 550 5 uen tede 42 Target CoDeSys Reference Manual 112 2 SVSSOCKS OM Gece ccs tle IN ME 43 1 2 28 SysSockSendrTo ec edi onec cau alee ect xir d ecc dean od
61. LSE OR diError lt gt 235 THEN bConnectionError TRUE END_IF ELSE 35 Target CoDeSys Reference Manual ConnectionIsEstablished TRUE END_IF END_IF 36 Target CoDeSys Reference Manual 1 2 21 SysSockListen FUNCTION SysSockListen BOOL VAR_INPUT diSocket DINT diMaxConnections DINT END VAR Switches a sockets into the listen mode so it can accept connection requests Return Value TRUE success FALSE error Input Parameters diSocket Socket descriptor diMaxConnections Max number of simultanious connections 37 Target CoDeSys Reference Manual 1 2 22 SysSockNtohl FUNCTION SysSockNtohl DWORD VAR INPUT dwNet DWORD END VAR Converts a DWORD from network byte order to host byte order in context with Big Endian and Little Endian format Return Value Converted DWORD value Input Parameters dwNet Value to convert 38 Target CoDeSys Reference Manual 1 2 23 SysSockNtohs FUNCTION SysSockNtohs WORD VAR_INPUT wNet WORD END_VAR Converts a WORD from network byte order to host byte order in context with Big Endian and Little Endian format Return Value Converted WORD value Input Parameters wNet Value to convert 39 Target CoDeSys Reference Manual 1 2 24 SysSockRecv FUNCTION SysSockRecv DINT VAR_INPUT diSocket DINT pbyBuffer POINTER to BYTE diBufferSize DINT diFlags DINT END VAR Receives some data from an established TCP connectio
62. NPUT Row END VAR Forces the row pointer for result set reading Return Value TRUE success FALSE error Input Parameters Row Position of the next line read from the result set Comments The function sets the pointer position of the next row of result set to be read with the MySQL_Fetch_Row function After a query the pointer is positioned to value 0 corresponding to read the first row of the result set Each sequential row read increment the pointer by one position With this function you can reposition the cursor on a row between 0 and Num_Rows 1 where Num_Rows is the value returned by the MySQL_Num_Rows The function returns 1 if successful and returns 0 if the location requested is not available Related Topics MySQL _ Fetch Row 116 Target CoDeSys Reference Manual 1 13 3 MySQL_Database_Set FUNCTION MySQL Database Set BOOL VAR INPUT Database STRING END VAR Selects the MySQL database currently in use Return Value Always TRUE Input Parameters Database Name of the current database to use Comments This function sets the name of the MySQL database to be used for all subsequent management functions The management is done by running the PHP script that initially make the MySQL connection using the parameters set by the MySQL Connect Set function Then the database selection is made using the name set by the MySQL Database Set function After running the script interface and returning the re
63. ODEM STATUS Signal USINT SMS Get Time STRING 32 SMS Get Phone STRING 20 SMS Get Text STRING 1536 END VAR VAR State INT END VAR Function block for handling SMS send receive with GM01 modem Input Variables Start Activation signal If FALSE starts the shutdown procedure Sim Pin Pin code of the SIM Default is disabled Char Set Characters set used in text messages according to the MODEM CHAR SET type SMS Send Start Activation signal for sending SMS SMS Send Phone Phone number to send the SMS SMS Send Text Text of the SMS to be sent SMS Get Start Activation signal for getting SMS Output Variables Ready SMS service ready flag Status Current status of the SMS management 103 Target CoDeSys Reference Manual Signal Field strength of the radio network 02Min 10 Max SMS Get Time Time of receipt of the SMS SMS Get Phone Telephone number of the sender of the SMS SMS Get Text Text of the SMS received Internal Variables State Current status of the state graph of the function block Comments This function block allows the management of SMS send receive using a modem of 1 type Refer to the documentation of the target to verify the type of modem available The function block once activated with the Start signal starts a connection procedure that could during certain phases block the execution of the POU for relatively long periods When the connection is established shall enter into a permanent
64. Related Topics RtosGetVersion RtosGetVersionString 54 Target CoDeSys Reference Manual 1 3 7 RtosGetDevicenames FUNCTION RtosGetDevicenames BYTE VAR_INPUT ppChipName POINTER to POINTER to STRING pplniName POINTER to POINTER to STRING ppProductName POINTER to POINTER to STRING END VAR Returns pointers to the device names of the controller Input Parameters ppChipName Output paramter pointer to a string pointer which will receive a pointer to the fixed device name stored in the processor s flash memory pplniName Output paramter pointer to a string pointer which will receive a pointer to the device name configured in CHIP INI ppProductName Output paramter pointer to a string pointer which will receive a pointer to the fixed product device name stored in the flash memory Comments Example for using RtosGetDeviceNames in Structured Text language VAR 1 POINTER TO STRING p2 POINTER TO STRING p3 POINTER TO STRING S1 STRING 52 STRING S3 STRING END VAR RtosGetDevicenames ADR p1 ADR p2 ADR p3 S1 p1 2 p2 3 p3 55 Target CoDeSys Reference Manual 1 3 8 RtosGetDhcpStat FUNCTION RtosGetDhcpStat WORD VAR_INPUT dummy BYTE END_VAR Returns the status of the DHCP client if DHCP is on Return Value 0 DHCP configuration in progress 1 successfully configured via DHCP 2 DHCP failed Input Parameters dummy Not used Related Topics Rtos
65. SQL Connect Set MySQL Data Seek MySQL Database Set MySQL Fetch Row MySQL Field Len MySQL Field Name MySQL Num Fields MySQL Num Rows MySQL Query MySQL Result 114 Target CoDeSys Reference Manual 1 13 1 MySQL_Connect_Set FUNCTION MySQL_Connect_Set BOOL VAR_INPUT Php Url STRING Server STRING Username STRING Password STRING END VAR Sets the parameters for connecting to MySQL database Return Value Always TRUE Input Parameters Php Url URL path containing the PHP interface page Server Address of the server for MySQL database access Username Username for database access Password Password for database access Comments This function sets the connection parameters to be used for all subsequent operations on the MySQL database The database management is done through the HTTP client access to the PHP page as interface with the MySQL server The query php file must be installed on a PHP server set by the Php Url parameter not necessarily the same server used for MySQL database The Server parameter sets the address of the database host and is usually localhost if the same server running the PHP interface code The Username and Password parameters must match the authorization for the user enabled to perform operations on the MySQL database Related Topics MySQL Database Set 115 Target CoDeSys Reference Manual 1 13 2 MySQL Data Seek FUNCTION MySQL Data Seek BOOL VAR I
66. Send Start signal can be forced also for only one cycle and should be resetted to return to idle state waiting for a new command The SMS Get Start input signal forces the graph of the function block in the state of the received SMS extraction The Status output variable indicates the availability or not of an SMS in reception and the data of a new SMS are available in the respective output variables The SMS Get Start signal can be forced also for only one cycle and should be resetted to return to idle state waiting for a new command The SMS News output variable indicates the current availability of new incoming messages In the state of modem connected the monitoring of any incoming call is always active During the entire duration of the incoming call the Active signal is TRUE indicating the bell ringing If the service is enabled to recognize the caller ID its telephone number is forced into the Call ID Phone output variable The number of rings received is counted in the Call Rings output variable When the caller hangs up the call Call Active output returns to FALSE leaving in memory the phone number and the rings counter until the next call To terminate an incoming call before the caller hung up activate even for a single cycle the Call Hang Up input variable and then reset it inactive To make an outgoing call should be set up phone number in the Call Send Phone input variable and activate the Call Send Start signal If the remo
67. TRING Row Field UINT END VAR Extracts a single cell of the query result set Return Value The same string pointer passed as parameter Input Parameters Cell Pointer of string where to copy the cell readed Row Row number of the cell to read Field Field number of the cell to read Comments The database queries such as SELECT SHOW DESCRIBE EXPLAIN returns a result set consisting of whole rows table records that satisfy the condition of the query The query function saves the entire result set into a memory buffer from which can then extract the value of a single cell with MySQL_Result function directly specifying the line and column number using the Row and Field parameters The value of the cell is returned as a string to the position defined by the pointer passed as a Cell parameter Furthermore if the contents of the cell is a variable of string type the result is delimited by single quotes apostrophe as it does for MySQL_Fetch_Row function This function accesses randomly and not sequentially as MySQL_Fetch_Row to a single cell of the table a cross between the row and column of the result set However to read more cells in a row you should use the MySQL Fetch Row that is faster than MySQL Result If the cell is not available returns the empty string Related Topics MySQL Num Rows MySQL Num Fields 124 Target CoDeSys Reference Manual 1 14 The RS485 Serial library rs485 lib This library o
68. Target CoDeSys Reference M anual update 20 12 2014 IEC line by OVERDIGIT overdigit com Target CoDeSys Reference Manual Table of Contents 1 libras 5 enim Enim e eM RIPE ME 7 1 1 The SysLibCom library 5 8 MSL 9 1 1 2 SysCombPUrge iet diete erede nmin eate Eoi eu ede nea nulla eae Eo e ee hee eae Eon vou es 10 1 1 3 SysComiReadLine iic tier 11 1 1 4 5 ane es dade gates 12 1 2 The SysLibSockets library SysLibSockets lib nnns nennt nis 13 T2 TYPE TNADDR zt intrent ETA cit erem entere s LU AE 14 1 22 TYPE SOCK IP MREQ ossei aeaaee 15 Ep ice dip idc 16 1 2 4 TYPE SOCKET IP 17 1 2 5 TYPE SOCKET LINGER C D 18 1 2 6 SOCKET TIMEVAL rentrer pn nte eror retur ee ree Yen HERE tv ases eee ERR ud E ERE 19 1 2 7 SVSSOCKACCE DI ii eccc T 20 1 28 SVSSOCK BING esistere eh dere ee a eee 21 1 2 9 5 550 22 1 2 10 SysSOCKCOnHnle C
69. Value 0 success 146 replay with address not valid 149 replay with value not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Address Address of word to be write Value Value to write into the word Comments The function writes the value of single word of memory Holding Register into a specific server slave using the MODBUS TCP IP protocol This is based on MB_TCP_Req_Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific connection on which execute the request Slave_Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet Address parameter is the word address to write Value parameter indicates the value to be written into the word The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB_TCP_Req_Rsp function to which are added those of the specific command Related Topics MB_TCP_Rd_Hold_Regs MB Wr Hold Regs 185 Target CoDeSys Reference Manual 1 16 28 MB_TCP_Server FUNCTION BLOCK MB_TCP_ Server VAR_INPUT Start BOOL Port UINT Keepalive En BOOL Keepalive Time NT Keepalive Intv NT Keepalive Retry INT Coils Ptr POINTER TO BYTE Coils UINT Inputs Ptr POINTER TO BYTE Inputs Max UINT Hold
70. able following the execution of a query that returns a result set Related Topics MySQL Num Rows 121 Target CoDeSys Reference Manual 1 13 8 MySQL_Num_Rows FUNCTION MySQL Num Rows UINT Reads the current number of rows after a query execution Return Value Number of rows in the table related to the query Input Parameters None Comments This feature allows you to read the number of rows in the table after a query execution For queries that return a result set the readed number of rows corresponds to many records in the table have been affected by the query For example after a DELETE FROM table WHERE condition returns the number of deleted rows in the table according to the WHERE condition For query functions that return a result set the number of rows resulting from the function corresponds to the number of records readed from the table according to a certain condition and that can be readed with subsequent MySQL Fetch Row function calls Related Topics MySQL Num Fields 122 Target CoDeSys Reference Manual 1 13 9 MySQL_Query FUNCTION MySQL_Query STRING VAR_INPUT Query STRING END VAR Sends a query to the MySQL database Return Value 0 success 1 4 DNS client error 201 265 TCP IP functions error 1 2 4 8 16 SSL functions error 1001 Server parameter is not defined 1002 Username parameter is not defined 1003 Password parameter is not defined 1004 Database parameter is not defined
71. aintaining its IP on a Dynamic DNS server as dyndns com no ip com and others After establishing a connection with the Internet provider it usually gives to the device a dynamic IP address that can vary each time To simplify access to the system from the outside through the Internet it s possible to communicate the current IP to a Dynamic DNS server in order to make known to the whole network In addition the server performs an important function associatiating the IP number to a symbolic name chosen for the device and easier to remember In this way you can access the Web server and FTP server of the system by typing the same address string usually a third level domain for example myplc dyndns org To use this service you must register free of charge or with a small amount at a provider of Dynamic DNS server choosing a username and password After creating an account you must install on the server a Hostname a specific equipment for which perform the service The Hostname coincides with the full address for the selected device At this point the function block installs the Dynamic DNS client which must be suitably configured to communicate with the server Server_Url parameter is the address where the server is available and this is characteristic of the service provider The User and Password are those chosen during registration to the service that usually involves managing of more Hosts Updating the IP in the server record associated
72. already implemented with specific functions the word data conversions are handled by the functions itself Related Topics MB Swap Dword MB Swap Dword2 191 Target CoDeSys Reference Manual 2 PLC Browser Commands The PLC Browser i e command line interpreter is extended by some commands specific to the target These commands include checking the versions of the operating system and run time kernel and setting and checking the IP configuration To execute a command you must be logged into the controller Then change to the PLC Browser by clicking on the Resources tab of the project tree Then double click on PLC Browser type the command into the first line of the PLC browser window and press the Enter key The controller s response to the command will be displayed in the lower area of the PLC Browser window Here is a list of all extended commands available DHCP DNSNAME FTPPASSWORD FTPUSER GATEWAY GETDATETIME IP IPCFG 5 PING REBOOT SETDATETIME TCPIPMEM VER WEBPASSWORD WEBUSER 192 Target CoDeSys Reference Manual 2 1 DHCP The DHCP command enables or disables the use of the Dynamic Host Configuration Protocol for the internal ethernet interface to obtain an IP configuration When DHCP is enabled it is not necessary to set the IP configuration manually using the commands IP NETMASK and GATEWAY After setting the IP configuration or turning DHCP on or off the ethernet interface mu
73. ameters diSocket Socket descriptor of the listening socket which waits for connections Pointer to SOCKADDRESS struct where port and address of the incoming connection will be stored piSockAdarSize Pointer to a variable of type DINT This variable has got assigned the length of the structure SockAddr can be retrieved with the aid of the SIZEOF operator 20 Target CoDeSys Reference Manual 1 2 8 SysSockBind FUNCTION SysSockBind BOOL VAR_INPUT diSocket DINT pSockAddr POINTER to SOCKADDRESS diSockAddrSize DINT END VAR Binds a socket to a specified local port or local address NOTE pSockAddr sin family must be set to SOCKET prior to call Return Value TRUE success FALSE error Input Parameters diSocket Socket descriptor Pointer to SOCKADDRESS struct which specifies port and address diSockAdarSize Size of the SOCKADDRESS struct in bytes 21 Target CoDeSys Reference Manual 1 2 9 SysSockClose FUNCTION SysSockClose BOOL VAR_INPUT diSocket DINT END_VAR Closes a opened socket Return Value TRUE success FALSE error Input Parameters diSocket Socket descriptor of the socket which should be closed 22 Target CoDeSys Reference Manual 1 2 10 SysSockConnect FUNCTION SysSockConnect BOOL VAR_INPUT diSocket DINT pSockAddr POINTER to SOCKADDR diSockAddrSize DINT END VAR Establishs a connection to a TCP ser
74. and 205 Target CoDeSys Reference Manual 2 14 TCPIPMEM The TCPIPMEM command displays TCP IP memory usage This command shows the maximum reserved memory for the TCP IP stack and the current TCP IP stack memory used Command Syntax tcpipmem 206 Target CoDeSys Reference Manual 2 15 VER The VER command displays the version numbers of the controller s operating system and of the controller s run time kernel Command Syntax ver 207 Target CoDeSys Reference Manual 2 16 WEBPASSWORD Change the current value of WEB SEC_PASSWORD0 1 entry into CHIP INI file User name and password registration protects access to WEB server connection NOTE two user setting is available 0 and 1 Command Syntax webpassword n password Example webpassword 0 web password0 Related Topics WEBUSER command 208 Target CoDeSys Reference Manual 2 17 WEBUSER Change the current value of WEB SEC USERO 1 entry into CHIP INI file User name and password registration protects access to WEB server connection NOTE two user setting is available 0 and 1 Command Syntax webuser n user name Example webuser 0 web _user0 Related Topics WEBPASSWORD command 209 Target CoDeSys Reference Manual 3 Error handling The CoDeSys error handling concept CoDeSys uses events to handle runtime errors A runtime error is an exception that occurs during the execution of an IEC project that disrupts the normal flow of inst
75. ction on which execute the request if the server is a gateway to a RTU subnet Slave Add parameter select the specific slave on serial bus Address parameter is the starting word address to read Input Registers from a specific server slave using the MODBUS TCP IP Quantity parameter indicates the number of words to be read Data parameter is the pointer of the buffer in which receive the values of the words The amount of bytes placed in the receive buffer is equal to Data Len 2 Quantity The function returns 0 if it executes without error otherwise Related Topics MB TCP Rd Inputs it returns the error code The error codes are those of the MB Rsp function to which are added those of the specific command 175 Target CoDeSys 1 16 21 MB_TCP_Rd_Inputs FUNCTION MB TCP Rd Inputs UINT VAR INPUT Socket INT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Reference Manual Executes the MODBUS TCP IP function code 2 Read Discrete Inputs Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Address Address of first bit to be read Quantity Number of bits to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more bits of input Discrete Inputs fro
76. cts the specific slave on serial bus Address parameter is the starting bit address to read Quantity parameter indicates the number of bits to be read Data parameter is the pointer of the buffer in which receive the values of the bits The LSB of the first byte of the buffer contains the addressed bit The amount of bytes placed in the receive buffer is equal to Data Len Quantity 8 where if remainder gt 0 then Data Len Data Len 1 The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command Related Topics MB RTU Wr Coils MB RTU Wr Single Coil 155 Target CoDeSys Reference Manual 1 16 6 MB_RTU_Rd_Hold_Regs FUNCTION MB RTU Rd Hold Regs UINT VAR INPUT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS RTU function code 3 Read Holding Registers Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Slave Add Slave address valid 1 247 Address Address of first word to be read Quantity Number of words to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more words of memory Holding Registers from a specific slave using the MODBUS RTU protocol This is based on MB_RTU_Req_Rsp generic commu
77. d from 0 to 8191 For the pointer value of a IEC variable to get the bytes to write ADR function can be used Related Topics FRAM Read 82 Target CoDeSys Reference Manual 1 10 The RTC library RTC_Lib lib This library offers the functions for the management of the Real Time Clock Here is a list of all the functions this library offers DateTime Read RTC Read RTC Write 83 Target CoDeSys Reference Manual 1 10 1 DateTime_Read FUNCTION DateTime_Read DT VAR_INPUT Enable BOOL END_VAR Reads current date and time from Real Time Clock Return Value Returns current date and time into DT type variable Input Parameters Enable Enable the function execution Comments This function reads date and time from external Real Time Clock device The value returned is of DT DATE AND TIME standard type You advises to periodically execute the function for example at intervals of 1s to refresh the value of date and time into a global variable If the function is not enabled returns the reference date and time value DT 1970 01 01 00 00 84 Target CoDeSys Reference Manual 1 10 2 RTC_Read FUNCTION RTC_Read SystemTimeDate VAR_INPUT Enable BOOL END_VAR Reads current date and time from Real Time Clock Return Value Returns current date and time into SystemTimeDate type variable Input Parameters Enable Enable the function execution Comments This function reads date and time from external Real
78. dle returned by Rs485ComOpen ch Character to send Related Topics Rs485ReceiveByte Rs485SendBlock Rs485ReceiveBlock 142 Target CoDeSys Reference Manual 1 14 18 Rs485SetFlowcontrol FUNCTION Rs485SetFlowcontrol USINT VAR_INPUT dwHandle DWORD flowctrl RS485_FLOWCTRL END_VAR Sets the flowcontrol method of a serial port Return Value TRUE success FALSE error Input Parameters dwHandle Port handle returned by Rs485ComOpen flowctrl Flowcontrol method bit field enumeration type Comments RS485_FLOWCTRL enumeration type is also declared in this library Related Topics Rs485ComOpen 143 Target CoDeSys Reference Manual 1 14 19 Rs485SetMode FUNCTION Rs485SetMode BOOL VAR_INPUT dwHandle DWORD mode RS485_MODE END_VAR Selects the operating mode of the port Return Value TRUE success FALSE error Input Parameters dwHandle Port handle returned by Rs485ComOpen mode Mode enumeration type Comments This function should be the first function called before any data exchange can take place Related Topics Rs485ComOpen 144 Target CoDeSys Reference Manual 1 15 The RS485 Expansion library RS485 Lib lib This library offers the functions for the management of the RS485 slave expansion A complete refresh of slave expansion resources is obtained using this functions into IEC program Here is a list of all the functions and data type this library offers
79. e buffer to be sent must be equal to Data Len 2 Quantity The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command Related Topics MB RTU Rd Hold Regs MB RTU Wr Single Reg 162 Target CoDeSys Reference Manual 1 16 12 MB RTU Wr Rd Hold Regs FUNCTION MB RTU Wr Rd Hold Regs UINT VAR INPUT Slave Add BYTE Wr Address WORD Wr Quantity WORD Wr DWORD Rd Address WORD Rd Quantity WORD Rd Data DWORD END VAR Executes the MODBUS RTU function code 23 Write Read Multiple Registers Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Slave Add Slave address valid 1 247 Wr Address Address of first word to be write Wr Quantity Number of words to be write Wr Data Pointer of data buffer for writing Rd Adaress Address of first word to be read Rd Quantity Number of words to be read Rd Data Pointer of data buffer for reading Comments The function simultaneously writes and reads the value of one or more words of memory Holding Registers into and from a specific slave using the MODBUS RTU protocol This is based on RTU Rsp generic communication function for which operates as an interface with the specific command code Slave Add parameter selects
80. eady flag The Internet link is available Status Current status of the connection Signal Field strength of the radio network 0 10 SMS_News Number of new SMS available SMS_Get_Time Time of receipt of the SMS SMS_Get_Phone Telephone number of the sender of the SMS SMS_Get_Text Text of the SMS received Call_Active 100 Target CoDeSys Reference Manual An incoming call is active bell is ringing Call ID Phone Telephone number of the caller ID Call Rings Number of rings detected for the incoming call Command Replay Modem replay to a specific command code Internal Variables State Current status of the state graph of the function block Data Service Information about the Packet Data Service type of the connection My IP address assigned by service provider Remote IP address of the peer to peer connection Netmask Netmask value for the subnet DNS1 IP address of DNS server 1 DNS2 IP address of DNS server 2 Last_IP Currently registered IP address on DynDNS server Retry_Timer Remaining time to the reconnection Retry_Counter Counting of connection retries Comments This function block combines in a single central control all the operations carried out by a modem of GM01 type Refer to the documentation of the target to verify the type of modem available The function block once activated with the Start signal starts a connection procedure that could during certain
81. eception 131 received from slave a bad parity 132 received from slave a bad checksum 133 bad slave address in replay 134 bad function code in replay 135 bad number of bytes transmitted 136 bad number of bytes received c1 0n Input Parameters Slave Add Slave address valid 1 247 Fun Code MODBUS function code Data Pointer to request data buffer Len Number of request data bytes Hsp Data Pointer to response data buffer Hsp Len Number of response data bytes aspected Comments This function execute a complete MODBUS RTU communication sequence over RS485 RS232 port with expansion slaves Slave Add parameter select the specific slave on the serial bus Fun Code parameter is the code of the function to execute Req Data parameter is the pointer to the buffer with the data to be transmitted for the specific function code Req Len parameter indicates the number of bytes in the Req Data buffer to be transmitted to the slave Rsp Data parameter is the pointer to the buffer in which receive the data of response to the function from the slave The Rsp Len parameter indicates the number of data bytes expected in the Rsp Data receive buffer as response to the specific function code 159 Target CoDeSys Reference Manual The function returns 0 if performed without error otherwise it returns the error code To use the MODBUS communication function refer to the technical documentation MODBUS Applicatio
82. eee tuere eode tee eode eee 172 1 16 18 INE ML CRUEL 173 1 16 19 Rd 174 1 16 20 MB TCP Input dee or eek aeri 175 1 16 21 Ecce c 176 1 16 22 CR 177 1 16 23 MB TCP Wr 2COUS cE 180 1 16 24 MB TCEP Wr Hold Res nre ene eren Te aene vos eo stagna 181 1 16 25 MB TCP Rd Hold Regs ceti netten eie haste sotuencvsatvce ee RE ne Ra nee de eine de kaia ee Tae eve aacra 182 1 16 26 MB Wr Single 184 1 16 27 MB Wr Single err cte RU ago Pere E eR VER ERR E RV 185 1 16 28 uU 186 1 16 29 MB Swap DWord ER 189 1 16 30 MB Swap DWOFd2 tte cede tote tne rte ere Esto deceat retos e aee to 190 1 16 31 MB Swap WOTA 191 2 PLC Browser Commiahds aieo te tense E eate tee ep ods Page tee Vole Sue ad 192 UNS 193 ADEUIecE
83. ents The buffer must provide 6 bytes of space e g be of the type ARRAY 0 5 OF BYTE 60 Target CoDeSys Reference Manual 1 3 13 RtosGetMsg FUNCTION RtosGetMsg INT VAR_INPUT msgID UINT pMsg DWORD END_VAR Gets a message from a specified message exchange Returns immediately if no message is available Return Value Returns 0 on success otherwise error code Input Parameters Number of the message exchange as returned by RtosCreateMsg in structure MSG pMsg Pointer to a 12 byte buffer in which the message will be stored The format of the data can be defined by the application program Comments This function returns immediately with code 28 if no message is available When more than one message is available at the message exchange the oldest FIFO order message from the highest priority message queue will be reported Related Topics RtosSendMsg 61 Target CoDeSys Reference Manual 1 3 14 RtosGetRebootReason FUNCTION RtosGetRebootReason BYTE VAR_INPUT dummy BYTE END_VAR Returns the reason why the controller rebooted Return Value Returns 0 if reboot reason is unknown 3 if controller was rebooted by the watchdog or 4 if the controller rebooted due to power failure Input Parameters dummy Not used Comments This function relies on the retain mechanism which is per default active to save data in case of power failure So this function can only be used if the c
84. ere the IP address is to be stored as a null terminated string when reading the configuration or where the IP address will be read from when setting the configuration pSubString Output parameter pointer to a 16 byte memory area where the subnet mask is to be stored as a null terminated string when reading the configuration or where the subnet mask address will be read from when setting the configuration pGatewayString Output parameter pointer to a 16 byte memory area where the gateway address is to be stored as a null terminated string when reading the configuration or where the gateway address will be read from when setting the configuration Comments This function is useful if you want to set the IP configuration from the PLC application itself e g using a graphical operator device However in most cases the IP configuration will be edited using the PLC Configuration dialog in the programming system The strings are null terminated ASCII strings in dotted decimal notation e g 192 168 10 3 Any of the parameters can be set to 0 if the respective value is not to be set read After setting the configuration the ethernet interface will automatically be reconfigured Important This function writes to the CHIP INI file on the controller s flash disk and is not reentrant Do not use this function in different tasks or programs or in combination with other commands writing to the CHIP INI Related Topics RtosDhcpUse 65 Target CoDeSys Ref
85. erence Manual 1 3 18 RtosReboot FUNCTION RtosReboot BYTE VAR_INPUT dummy BYTE END_VAR Reboots the controller Return Value This function never returns Input Parameters dummy Not used Comments While rebooting the controller stops and does not respond any more Do not reboot the controller if this could cause danger for human beings creatures or material assets 66 Target CoDeSys Reference Manual 1 3 19 RtosSendMsg FUNCTION RtosSendMsg INT VAR_INPUT msgID UINT prio INT pMsg POINTER to BYTE END_VAR Sends a message to the message exchange Return Value Returns 0 on success otherwise error code Input Parameters Number of the message exchange as returned RtosCreateMsg in structure MSG prio Priority 0 3 where 0 is highest 3 is lowest priority pMsg Pointer to 12 bytes of data which shall be sent to the message exchange The format of the data can be defined by the application program Comments Messages will be reported in message priority order and from each priority queue in FIFO order Related Topics RtosGetMsg 67 1 3 20 RtosServers FUNCTION RtosServers BYTE VAR_INPUT server BYTE stop BYTE END VAR Starts Stops the RTOS system servers Return Value Returns always 0 Input Parameters server 0 1 telnet 2 web server stop 0 start server 1 stop server Target CoDeSys Reference Manual 68 Target CoDeSy
86. ethod of flow control Member RS485_FLOWCTRL_OFF 0 no flow control RS485_FLOWCTRL_XONXOFF_SEND 1 XONXOFF on transmit watch for XOFF while sending RS485_FLOWCTRL_RTSCTS 2 CTS on transmit RTS on receive RS485_FLOWCTRL_XONXOFF_RECV 8 XONXOFF on receive send XOFF when buffer nearly full RS485_FLOWCTRL_XONXOFF_SEND_RECV 9 XONXOFF used on both Tx and Rx 127 Target CoDeSys Reference Manual 1 14 3 RS485 MODE TYPE RS485_MODE TYPE RS485_MODE RS485 MODE LOWACTIVE 0 RS485 MODE HIGHACTIVE 1 RS485 DISABLE 2 END TYPE This type enumerates the desired method Member RS485 MODE LOWACTIVE 0 Tx Enable low active RS485 MODE HIGHACTIVE 1 Tx Enable high active RS485 DISABLE 2 Disable RS485 Mode NOTE normally this parameter must be set to RS485_MODE_HIGHACTIVE 128 Target CoDeSys Reference Manual 1 14 4 TYPE RS485 PARITY TYPE RS485_PARITY TYPE RS485_PARITY RS485_PARITY_NO 0 RS485 PARITY ODD 1 RS485 PARITY EVEN 2 RS485 PARITY MARK 3 RS485 PARITY SPACE 4 END_TYPE This type enumerates the desired parity setting of a serial port Member RS485_PARITY_NO 0 no parity RS485_PARITY_ODD 1 odd parity RS485_PARITY_EVEN 2 even parity RS485_PARITY_MARK 3 mark parity RS485_PARITY_SPACE 4 space parity 129 Target CoDeSys Reference Manual 1 14 5 TYPE RS485 PORTS TYPE RS485_PORTS TYPE RS485_PORTS 548
87. exchange It is used with the message exchange functions from the RTOS library like RtosCreateMsg RtosDeleteMsg RtosSendMsg RtosGetMsg RtosFindMsg Member msgID filled by RtosCreateMsg function 0 name1 name2 name3 X mb0 number of envelopes priority O high mb1 number of envelopes priority 1 mb2 number of envelopes priority 2 mb3 number of envelopes priority 3 low 49 Target CoDeSys Reference Manual 1 3 2 RtosCreateMsg FUNCTION RtosCreateMsg INT VAR_INPUT pMsgEx POINTER to MSG_EX END_VAR This function creates a message exchange You must call this function before the message exchange mechanism can be used RtosCreateMsg fills in the msglD member of the MSG EX structure This ID number of the message exchange will be used by other functions to access the message exchange Additionally you can provide a unique 4 character tag to identify the message exchange when using the RtosFindMsg function Return Value Returns 0 in case of success otherwise the error code from the operating system Input Parameters pMsgEx Pointer to a MSG EX structure Related Topics RtosDeleteMsg RtosFindMsg 50 Target CoDeSys Reference Manual 1 3 3 RtosDeleteMsg FUNCTION RtosDeleteMsg INT VAR_INPUT msgID UINT END_VAR This function deletes a message exchange that is no longer used Return Value Returns 0 in case of success otherwise an error code Input Parame
88. ffers extended functionality for serial communication via the RS485 protocol Especially for controlling an RS485 transceiver because here the transmitter may only be active while data is actually sent The available port numbers are enumerated in RS485 PORTS This library offers the following functions and data types TYPE RS485 BREAK TYPE RS485 FLOWCTRL TYPE RS485 MODE TYPE RS485 PARITY TYPE RS485 PORTS Rs485ComClose Rs485ComOpen Rs485FlushOutput Rs485GetStatus Rs485IsByteAvailable Rs485Purgelnput Rs485PurgeOutput Rs485ReceiveBlock Rs485ReceiveByte Rs485SendBlock Rs485SendBreak Rs485SendByte Rs485SetFlowcontrol Rs485SetMode 125 Target CoDeSys Reference Manual 1 14 1 TYPE RS485 BREAK TYPE RS485_BREAK TYPE RS485_BREAK RS485_BREAK_LONG 1 RS485 BREAK SHORT 2 RS485 BREAK EXTRALONG 3 END TYPE This type enumerates the desired length of a break pulse Member RS485 BREAK LONG 1 long break Duration 1 character RS485 BREAK SHORT 2 short break Duration 2 characters RS485 BREAK EXTRALONG 3 extra long break Duration 3 characters 126 Target CoDeSys Reference Manual 1 14 2 TYPE RS485 FLOWCTRL TYPE RS485_FLOWCTRL RS485_FLOWCTRL RS485 FLOWCTRL OFF 0 RS485 FLOWCTRL XONXOFF SEND 1 RS485 FLOWCTRL RTSCTS 2 RS485 FLOWCTRL 8 RS485 FLOWCTRL XONXOFF SEND RECV 9 END_TYPE This type enumerates the desired m
89. hernet interface must be reinitialized using the IPETH command Command Syntax gateway XXX XXX XXX XXX Example gateway 192 168 1 1 Related Topics IP command IPETH command NETMASK command 197 Target CoDeSys Reference Manual 2 6 GETDATETIME The GETDATETIME command displays the current Date and Time of controller Command Syntax getdatetime Related Topics SETDATETIME command 198 Target CoDeSys Reference Manual 2 7 IP The IP command sets the IP address of the controller s ethernet interface After setting the IP configuration the ethernet interface must be reinitialized using the IPETH command Command Syntax ip XXX XXX XXX XXX Example ip 192 168 1 101 Related Topics GATEWAY command IPETH command NETMASK command 199 Target CoDeSys Reference Manual 2 8 IPCFG The IPCFG command displays the current IP configuration of the controller For each network interface the device name IP address subnet mask and related information are displayed Command Syntax ipcfg 200 Target CoDeSys Reference Manual 2 9 IPETH The IPETH command reconfigures the ethernet interface after the IP configuration has been changed using the IP NETMASK GATEWAY or DHCP command If DHCP is enabled IPETH also obtains a new IP configuration from the DHCP Server Command Syntax ipeth Related Topics DHCP command GATEWAY command IP command NETMASK command 201 Target CoDeSys Reference Manual 2 10
90. hese dummy functions return a neutral value e g nothing received for SysComRecv Sending successfull for The following libraries are available The RS485 Serial library rs485 lib The SysLibCom library SysLibCom lib SysLibSockets library SysLibSockets lib The RTOS functions library rtos lib The SysLibEvent library SysLibEvent lib The SysLibCallback library SysLibCallback lib The SysLibDir library SysLibDir lib The SysLibPlcCtrl library SysLibPlcCtrl lib The SysLibStr library SysLibStr lib The FRAM library FRAM The RTC library RTC Lib lib The MODEM library MODEM Lib lib The TCPIP library TCPIP Lib lib The MySQL library MySQL Lib lib The MODBUS library MODBUS Lib lib RS485 Expansion library RS485 Lib lib Target CoDeSys Reference Manual 1 1 The SysLibCom library SysLibCom lib The implementation of the SysLibCom lib on the CoDeSys Platform includes the standard CoDeSys SysLibCom functions For help on these functions is referenced to the standard SysLibCom documentation Thereby some limitations should be taken into account which are described below This chapter also describes the additional functions to the standard CoDeSys SysLibCom library Comments The ports COM1 to COM3 are physical ports Refer to the user manual of specific target for the availability and type of interface RS485 RS232
91. into the bit 16 0000 OFF 16 FFOO ON Comments The function writes the status of single bit of memory Coil into a specific slave using the MODBUS RTU protocol This is based on MB_RTU_Req_Rsp generic communication function for which operates as an interface with the specific command code Slave_Add parameter selects the specific slave on serial bus Address parameter is the bit address to write Value parameter indicates the status to be written into the bit A value of 16 0000 forces the bit in the OFF state while the value 16 FFOO force the bit ON The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command Related Topics MB RTU Rd Coils MB RTU Wr Coils 165 Target CoDeSys Reference Manual 1 16 14 MB RTU Wr Single Reg FUNCTION MB RTU Wr Single Reg UINT VAR INPUT Slave Add BYTE Address WORD Value WORD END VAR Executes the MODBUS RTU function code 6 Write Single Register Return Value 0 success 146 replay with address not valid 149 replay with value not valid Input Parameters Slave Add Slave address valid 1 247 Adaress Address of word to be write Value Value to write into the word Comments The function writes the value of single word of memory Holding Register into a specific slave using the MODBUS RTU protocol This is based on
92. is still active If Keepalive En is enabled and the connection is inactive for a time equal to Keepalive Time 170 Target CoDeSys Reference Manual begins sending periodic TCP packets with no data Probes with a repetition time equal to Keepalive_Intv After Keepalive_Retry maximum attempts if no answer is received from the connected device the connection is automatically closed The Rsp_Timeout parameter sets the maximum waiting time in ms for the response from the server The function returns 0 if executed correctly In this case the value returned on the Socket variable must be saved for use it in all other client functions as a handle of the specific connection In case of error the function returns a value gt 0 that encodes the error Related Topics MB TCP Disconnect 171 Target CoDeSys Reference Manual 1 16 17 MB_TCP_Disconnect FUNCTION MB_TCP_Disconnect UINT VAR_INPUT Socket INT END_VAR Disconnect MODBUS TCP IP client from a specific server Return Value 0 success gt 200 error code according to the coding adopted by the TCP IP stack Input Parameters Socket Socket descriptor handle used by the connection Comments This function disconnects the MODBUS TCP IP client from the server This function must be called at the end of the MODBUS session If Socket parameter value is 1 all previously opened connection instances will be closed If executed correctly returns 0 otherwise it returns the corre
93. ith address not valid 149 replay with value not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Address Address of bit to be write Value State to write into the bit 16 0000 OFF 16 FFOO ON Comments The function writes the status of single bit of memory Coil into a specific server slave using the MODBUS TCP IP protocol This is based on Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific connection on which execute the request Slave Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet Address parameter is the bit address to write Value parameter indicates the status to be written into the bit A value of 1640000 forces the bit in the OFF state while the value 16 FFOO force the bit ON The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB TCP Req Rsp function to which are added those of the specific command Related Topics MB TCP Rd Coils MB TCP Wr Coils 184 Target CoDeSys Reference Manual 1 16 27 MB_TCP_Wr_Single_Reg FUNCTION MB TCP Wr Single Reg UINT VAR INPUT Socket INT Slave Add BYTE Address WORD Value WORD END VAR Executes the MODBUS TCP IP function code 6 Write Single Register Return
94. l to Data Len Quantity 8 where if remainder gt 0 then Data Len Data Len 1 The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB TCP Req Rsp function to which are added those of the specific command Related Topics MB TCP Wr Coils MB TCP Wr Single Coil 173 Target CoDeSys Reference Manual 1 16 19 MB TCP Rd Hold Regs FUNCTION MB TCP Rd Hold Regs UINT VAR INPUT Socket INT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS TCP IP function code 3 Read Holding Registers Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Address Address of first word to be read Quantity Number of words to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more words of memory Holding Registers from a specific server slave using the MODBUS TCP IP protocol This is based on MB TCP Req Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific connection on which execute the request Slave Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet
95. m a specific server slave using the MODBUS TCP IP protocol This is based on MB TCP Req Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific connection on which execute the request Slave Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet Address parameter is the starting bit address to read Quantity parameter indicates the number of bits to be read Data parameter is the pointer of the buffer in which receive the values of the bits The LSB of the first byte of the buffer contains the addressed bit The amount of bytes placed in the receive buffer is equal to Data Len Quantity 8 where if remainder gt 0 then Data Len Data Len 1 The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB TCP Rsp function to which are added those of the specific command Related Topics MB TCP Rd Input Regs 176 Target CoDeSys Reference Manual 1 16 22 MB TCP Req Rsp FUNCTION MB TCP Req Rsp UINT VAR INPUT Socket INT Slave Add BYTE Fun Code BYTE Data DWORD Req Len WORD Rsp Data DWORD Rsp Len WORD END VAR Executes a complete MODBUS TCP IP request tx and response rx with a connected server Return Value success slave has received a not valid function code slave has received a no
96. n Return Value Number of the received bytes Input Parameters diSocket Socket descriptor of the established connection pbyBuffer Pointer to buffer of type BYTE where the received data should be stored diBufferSize Size of the buffer diFlags Flags must be equal to null 40 Target CoDeSys Reference Manual 1 2 25 SysSockRecvFrom FUNCTION SysSockRecvFrom DINT VAR_INPUT diSocket DINT pbyBuffer POINTER to BYTE diBufferSize DINT diFlags DINT pSockAddr POINTER to SOCKADRR diSockAddrSize DINT END VAR Receives a UDP datagram from another UDP station NOTE pSockAddr sin family must be set to SOCKET AF prior to call Return Value Number of the received bytes Input Parameters diSocket Socket descriptor pbyBuffer Pointer to buffer of type BYTE where the datagram should be stored diBufferSize Size of the buffer diFlags Flags must be equal to null Pointer to SOCKADDRESS struct where the source address and port of the sender should be stored diSockAdarSize Size of the SOCKADDRESS struct in bytes 41 Target CoDeSys Reference Manual 1 2 26 SysSockSelect FUNCTION SysSockSelect DINT VAR_INPUT diWidth DINT fdRead POINTER to SOCKET FD SET fdWrite POINTER to SOCKET FD SET fdExcept POINTER to SOCKET FD SET ptvTimeout POINTER to SOCKET TIMEVAL END VAR Determine status of one or more sockets Return Value 0 timeout 0 numbe
97. n Protocol Specification downloadable at http www modbus ida org tech php In the following example one input word and one output word are refreshed for the slave at address 1 PROGRAM MB_RTU VAR MB_RTU_Initialized BOOL FALSE Req Buf ARRAY 0 10 OF BYTE Rsp Buf ARRAY 0 10 OF BYTE Input Reg WORD Output Reg WORD END VAR Initialize MODBUS communication IF NOT MB RTU Initialized THEN MB RTU Init COM2 19200 PARITY EVEN 100 MB RTU Initialized TRUE END IF Read one input word at address 0 from Slave 1 Buf 0 Req Buf 1 0 Req Buf 2 Req Buf 3 1 IF MB Rsp 1 4 ADR Req Buf 4 ADR Rsp Buf 3 THEN Input Reg 256 Rsp Buf 1 Rsp Buf 2 END IF Write one output word at address 1 to Slave 1 Req Buf 0 Req Buf 1 1 Req Buf 2 Output Reg 256 Req Buf 3 Output Reg MOD 256 MB RTU Req Rsp 1 6 ADR Req Buf 4 ADR Rsp Buf 4 To read the input word is used the function code 4 followed by 4 bytes of data two for the start address of the object and two for the amount of words to read The expected response consists of 3 bytes of data The first is a input bytes count in this case 2 because is required 1 word while the remaining 2 bytes are for the input word requested To write the output word is used the function code 6 followed by 4 bytes two for the start address of the object and two for the value
98. nds a UDP datagram to another UDP station NOTE pSockAddr sin family must be set to SOCKET AF prior to call Return Value Number of transfered bytes Input Parameters diSocket Socket descriptor pbyBuffer Pointer to buffer of type BYTE which should be sent diBufferSize Size of the data to send in bytes diFlags Flags must be equal to null Points to SOCKADDRESS struct which contains the destination address and port diSockAdarSize Size of the SOCKADDRESS struct in bytes 44 Target CoDeSys Reference Manual 1 2 29 SysSockSetlPAddress This function is not implemented in this version of the Release NOTE A call to this function returns always zero 45 Target CoDeSys Reference Manual 1 2 30 SysSockSetOption FUNCTION SysSockSetOption BOOL VAR_INPUT diSocket DINT diLevel DINT diOption DINT pOptionValue POINTER dwOptionValueLength DWORD END VAR Controls option settings for specified Socket Return Value TRUE success FALSE error Input Parameters diSocket Socket descriptor diLevel Protocol level diOption Option which should be set pOptionValue Pointer to a variable containing the option value dwOptionValueLength Length in Bytes of the option value Comments For the supported options see function SysSockGetOption 46 1 2 31 SysSockShutdown FUNCTION SysSockShutdown BOOL VAR_INPUT diSocket DINT diHow DINT END_VAR
99. nication function for which operates as an interface with the specific command code Slave_Add parameter selects the specific slave on serial bus Address parameter is the starting word address to read Quantity parameter indicates the number of words to be read Data parameter is the pointer of the buffer in which receive the values of the words The amount of bytes placed in the receive buffer is equal to Data_Len 2 Quantity The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB_RTU_Req_Rsp function to which are added those of the specific command Related Topics MB RTU Wr Hold Regs MB RTU Wr Single Reg 156 Target CoDeSys Reference Manual 1 16 7 MB_RTU_Rd_Input_Regs FUNCTION MB_RTU_Rd_Input_Regs UINT VAR_INPUT Slave_Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS RTU function code 4 Read Input Registers Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Slave Add Slave address valid 1 247 Address Address of first word to be read Quantity Number of words to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more words of input Input Registers from a specific slave using the MODBUS RTU protocol This is based on MB_RTU_Req_Rsp generic communication func
100. notation while the double words contained in the MODBUS protocol data packets are defined with Big endian notation The implementation of custom MODBUS commands with the MB RTU Req Rsp function may require the use of conversion between the two formats The insertion and estraction of a double word variable related to a data buffer of type ARRAY OF BYTE require such conversion function Related Topics MB Swap Dword MB Swap Word 190 Target CoDeSys Reference Manual 1 16 31 MB Swap Word FUNCTION MB Swap Word WORD VAR INPUT Value WORD END VAR Big endian Little endian conversion for the bytes of a WORD Return Value Word value with swapped bytes Input Parameters Value Value of the word with the bytes to be swapped Comments The function performs the conversion from the Big endian to the Little endian notation and vice versa for a variable of type WORD The word returned by the function contains the same bytes of the word passed as a parameter but in reverse order The PLC processor uses the Little endian notation while the words contained in the MODBUS protocol data packets are defined with Big endian notation The implementation of custom MODBUS commands with the Rsp function may require the use of conversion between the two formats The insertion and estraction of a word variable related to a data buffer of type ARRAY OF BYTE require such conversion function In the case of the standard MODBUS commands
101. nput Parameters Value Value of the double word with the bytes to be swapped Comments The function performs the conversion from the Big endian to the Little endian notation and vice versa for a variable of type DWORD The double word returned by the function contains the same bytes of the double word passed as a parameter but in reverse order The PLC processor uses the Little endian notation while the double words contained in the MODBUS protocol data packets are defined with Big endian notation The implementation of custom MODBUS commands with the MB RTU Req Rsp function may require the use of conversion between the two formats The insertion and estraction of a double word variable related to a data buffer of type ARRAY OF BYTE require such conversion function Related Topics MB Swap Dword2 MB Swap Word 189 Target CoDeSys Reference Manual 1 16 30 MB_Swap_Dword2 FUNCTION MB_Swap_Dword2 DWORD VAR_INPUT Value DWORD END VAR Big endian Little endian conversion for the words of a DWORD Return Value Double word value with swapped words Input Parameters Value Value of the double word with the words to be swapped Comments The function performs the conversion from the Big endian to the Little endian notation and vice versa for a variable of type DWORD The double word returned by the function contains the same words of the double word passed as a parameter but in reverse order The PLC processor uses the Little endian
102. ode Socket parameter is the handle of the specific connection on which execute the request Slave Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet Wr Address parameter is the starting word address to write Wr Quantity parameter indicates the number of words to be write Wr Data parameter is the pointer of the buffer containing the values of the words to be written The number of bytes in the buffer to be sent must be equal to Wr Data Len 2 Wr Quantity 182 Target CoDeSys Reference Manual Rd_Address parameter is the starting word address to read Rd_Quantity parameter indicates the number of words to be read Rd_Data parameter is the pointer of the buffer in which receive the values of the words The amount of bytes placed in the receive buffer is equal to Rd Data Len 2 Rd Quantity The function returns O if it executes without error otherwise it returns the error code The error codes are those of the MB TCP Req Rsp function to which are added those of the specific command Related Topics MB TCP Rd Hold Regs MB TCP Wr Hold Regs 183 Target CoDeSys Reference Manual 1 16 26 MB TCP Wr Single Coil FUNCTION MB TCP Wr Single Coil UINT VAR INPUT Socket INT Slave Add BYTE Address WORD Value WORD END VAR Executes the MODBUS TCP IP function code 5 Write Single Coil Return Value 0 success 145 Value parameter not valid 146 replay w
103. ommand code Slave_Add parameter selects the specific slave on serial bus Address parameter is the starting bit address to read Quantity parameter indicates the number of bits to be read Data parameter is the pointer of the buffer in which receive the values of the bits The LSB of the first byte of the buffer contains the addressed bit The amount of bytes placed in the receive buffer is equal to Data_Len Quantity 8 where if remainder gt 0 then Data_Len Data_Len 1 The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command Related Topics MB Rd Input Regs 158 Target CoDeSys Reference Manual 1 16 9 MB RTU Req Rsp FUNCTION MB RTU Req Rsp UINT VAR INPUT Slave Add BYTE Fun Code BYTE Req Data DWORD Req Len WORD Rsp Data DWORD Rsp Len WORD END VAR Executes a complete MODBUS RTU request tx and response rx on RS485 RS232 for expansion communication Return Value success slave has received a not valid function code slave has received a not valid object address slave has received a not valid object data non recoverable error during execution of the slave function response to prevent a master receive timeout while slave performs a long operation 6 slave is busy in the execution of required function 130 timeout during master r
104. ontroller supports retain variables 62 Target CoDeSys Reference Manual 1 3 15 RtosGetVersion FUNCTION RtosGetVersion DWORD VAR_INPUT dummy BYTE END_VAR Returns the version of the operating system Return Value High byte of the low word more significant digit of the version number Low byte of the low word less significant digit of the version number If the least significant bit of the high word is set this is a beta version of the operating system Input Parameters dummy Not used Related Topics RtosGetVersionString RtosGetBootstrapVersion 63 Target CoDeSys Reference Manual 1 3 16 RtosGetVersionString FUNCTION RtosGetVersionString BYTE VAR_INPUT pBuf POINTER to BYTE len INT END_VAR Returns the version of the operating system as a string Return Value Returns always 0 Input Parameters pBuf Pointer to buffer where the version string will be stored len Size of buffer at pBuf including space for terminating null character Related Topics RtosGetVersion RtosGetBootstrapVersion 64 Target CoDeSys Reference Manual 1 3 17 Rtoslpconfig FUNCTION Rtoslpconfig BYTE VAR_INPUT set BYTE plpString POINTER to STRING pSubString POINTER to STRING pGatewayString POINTER to STRING END VAR Sets or reads the controller s IP configuration Input Parameters set 0 to read 1 to set configuration plpString Output parameter pointer to a 16 byte memory area wh
105. ot be used simultaneously For a complete management of all the capabilities of the modem it s recommend the use of the GMO1 PPP SMS Call function block which also includes several other features 87 Target CoDeSys Reference Manual 1 11 1 DYNDNS STATUS TYPE DYNDNS_STATUS TYPE DYNDNS STATUS DYNDNS STANDBY 0 DYNDNS UPDATING 1 DYNDNS UPDATED 2 DYNDNS FAILED 3 DYNDNS RETRY WAIT 4 DYNDNS STANDBY END TYPE This type enumerates the current status of Dynamic DNS Client Member DYNDNS STANDBY 0 Service is waiting for activation DYNDNS UPDATING 1 Updating request in progress DYNDNS UPDATED 2 IP address is updated on the server DYNDNS FAILED 3 Update on the server failed DYNDNS RETRY WAIT 4 Waiting before retry 88 Target CoDeSys Reference Manual 1 11 2 MODEM_CHAR_SET TYPE MODEM_CHAR_SET TYPE MODEM CHAR SET MODEM CHAR SET ASCII MODEM CHAR SET GSM 1 MODEM CHAR SET UCS2 2 3 0 MODEM_CHAR_SET_UTF8 MODEM CHAR SET 8859 1 MODEM CHAR SET ASCII END TYPE 4 This type enumerates the current character set for SMS Member MODEM CHAR SET ASCII 0 ASCII characters 0x00 0x7F MODEM CHAR SET GSM 1 GSM default alphabet GSM 03 38 subclause 6 2 1 MODEM CHAR SET UCS2 2 Unicode ISO IEC 10646 32 MODEM CHAR SET 8 3 Unicode 8 bit ISO 10646 transformation format MODEM CHAR SET 8859 1 4 Latin 1 ISO 8859 1 89
106. ot valid 146 replay with address not valid 148 replay with quantity not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Address Address of first bit to be write Quantity Number of bits to be write Data Pointer of data buffer for writing Comments The function writes the status of one or more bits of memory Coils into a specific server slave using the MODBUS TCP IP protocol This is based on MB_TCP_Req_Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific connection on which execute the request Slave_Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet Address parameter is the starting bit address to write Quantity parameter indicates the number of bits to be write Data parameter is the pointer of the buffer containing the values of the bits to be written The LSB of the first byte of the buffer contains the status to write into the addressed bit The number of bytes in the buffer to be sent must be equal to Data_Len Quantity 8 where if remainder gt 0 then Data Len Data Len 1 The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB TCP Req Rsp function to which are added those of the specific command Related Topics MB TCP Rd Coils
107. r of sockets for which a specified event has occurred Input Parameters diWidth Number of elements of the fd array field in the structure SOCKET FD SET fdRead Pointer to structure defining the socket set from which the read status should be checked fdWrite Pointer to structure defining the socket set from which the write status should be checked fdExcept Pointer to structure defining the socket set from which the Error status should be checked ptvTimeout Pointer to structure containing the maximum time to wait for a result Comments For any of the pointers to SOCKET_FD_SET a NULL Pointer is allowed when this group is not relevant 42 Target CoDeSys Reference Manual 1 2 27 SysSockSend FUNCTION SysSockSend DINT VAR_INPUT diSocket DINT pbyBuffer POINTER to BYTE diBufferSize DINT diFlags DINT END VAR Sends some data to an established TCP connection Return Value 1 error else success number of bytes sent Input Parameters diSocket Socket descriptor of the established connection pbyBuffer Pointer to buffer of type BYTE which should be sent diBufferSize Size of the data which should be sent in bytes diFlags Flags must be equal to null 43 Target CoDeSys Reference Manual 1 2 28 SysSockSendTo FUNCTION SysSockSendTo DINT VAR_INPUT diSocket DINT pbyBuffer POINTER to BYTE diBufferSize DINT diFlags DINT pSockAddr POINTER to SOCKADDR diSockAddrSize DINT END VAR Se
108. rnal Variables State Current status of the state graph of the function block Listen_Socket Descriptor number of listen socket Accepted_Socket List of socket descriptor number of accepted connections Highest_Socket Maximum descriptor number of accepted connections Socket_Flags List of socket flags of accepted connections Comments This function block installs a permanent server service with MODBUS TCP IP protocol The function block once activated with the Start signal initializes the connection and then enter into a state of service activity In the active state the block awaits the arrival of a command frame from MODBUS client When the frame is received it is checked and if the command is correct for the specific server the response is transmitted To deactivate the service the Start signal must be forced FALSE Port parameter identifies the TCP port used for connection Normally the 502 port is used for MODBUS TCP IP A server can accept up to a maximum of 8 concurrent connections The Keepalive parameters set the feature of sending dummy messages Probes in order to check whether the connection with the counterpart client peer is still active If Keepalive_En is enabled and the connection is inactive for a time equal to Keepalive_Time begins sending periodic TCP packets with no data Probes with a repetition time equal to Keepalive_Intv After Keepalive_Retry maximum attempts if no answer is received from the connected device
109. ructions The occurrence of the exception makes the execution of the following intruction arguable so the IEC project will be stopped automaticly on the end of the current cycle By registering an event handler it is possible to execute any IEC code Bevor you restart your program you have to reset it Only when the exception EVENT_EXCPT_ETHLINKLOST occurs you can restart your program without a reset All runtime errors are listed in the CoDeSys task configuration dialog The following exceptions runtime errors could be generated by the CoDeSys RTS EVE EVE EVE EVE EVE EVE EVE EVE T EXCPT DIVIDEBYZERO T EXCPT FPU DIVIDEBYZERO EXCPT FPU INVALID OPERATION T EXCPT NETWORKERROR T EXCPT HARDWAREERROR T EXCPT OUTOFMEMORY T EXCPT ILLEGAL INSTRUCTION T EXCPT KERNELERROR T EXCPT ETHLINKLOST Division by zero on integer datatypes Division by zero on floating point datatypes Floatingpoint operations with invalid input value e g radical from 1 Fatal network TCP IP error mostly an memory problem Fatal hardware error e g flash defect ethernet controller defect Not enough memory available Unknown processor instruction Internal kernel error Ethernet link lost 210
110. s CALL SENDED 31 Called device has answered to outgoing call CALL SEND ERROR 32 Error while sending outgoing call CALL RECEIVING 33 Incoming call in progress CALL TERMINATED 34 Call has been terminated by caller called hang up MODEM SIGNAL READING 40 Updating the field strength of the radio network 93 Target CoDeSys Reference Manual 1 11 6 DynDNS Client FUNCTION BLOCK DynDNS Client VAR INPUT Start BOOL Server Url STRING 80 User STRING 20 Password STRING 20 Hostname STRING 50 END VAR VAR OUTPUT Updated BOOL Status DYNDNS STATUS Last IP STRING 15 END VAR VAR State INT END_VAR Function block of Dynamic DNS client for updating the IP address on Dynamic DNS server Input Variables Start Activation signal If TRUE continuously checks if an IP update is required Server Url Url of Dynamic DNS service For dyndns com is members dyndns org nic update User Username of the account for the service of Dynamic DNS server Password Password of the account for the service of Dynamic DNS server Hostname Address of the connected device Example myplc dyndns org Output Variables Updated Result of the latest update Status Current status of the update Last IP Last IP address registered into Dynamic DNS server Internal Variables State Current status of the state graph for the function block Comments 94 Target CoDeSys Reference Manual This function block is m
111. s Reference Manual 1 3 21 RtosSetiniEntry FUNCTION RtosSetlniEntry INT VAR INPUT pSection POINTER to STRING pltemname POINTER to STRING pltemtext POINTER to STRING END VAR Writes an entry to the configuration file CHIP INI on the controller s flash disk Return Value 0 ok 1 invalid string length Input Parameters pSection Pointer to string holding the section max 40 characters pltemname Pointer to string holding the name of the desired entry max 40 characters pltemtext Pointer to string holding the text of the entry to be written max 128 characters Comments The functions RtosGetlniEntry and RtosSetlniEntry are not reentrant Do not use these in different tasks or in combination with other functions or commands which write to CHIP INI e g the DHCP or IP configuration functions Related Topics RtosGetlniEntry RtosGetlniEntryEx RtosSetlniEntryEx 69 Target CoDeSys Reference Manual 1 3 22 RtosSetiniEntryEx FUNCTION RtosSetlniEntryEx INT VAR_INPUT pFilename POINTER to STRING pSection POINTER to STRING pltemname POINTER to STRING pltemtext POINTER to STRING END VAR Writes an entry to a specified configuration file on the controller s flash disk Return Value 0 ok 1 invalid string length Input Parameters pFilename Pointer to string holding the configuration file name max 80 characters pSection Pointer to string holding the section max 40 characters pl
112. sponding TCP IP error code Related Topics MB TCP Connect 172 Target CoDeSys Reference Manual 1 16 18 MB_TCP_Rd_Coils FUNCTION MB TCP Rd Coils UINT VAR INPUT Socket INT Slave Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS TCP IP function code 1 Read Coils Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Socket Socket descriptor handle used by the connection Slave Add Slave address valid 0 255 Address Address of first bit to be read Quantity Number of bits to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more bits of memory Coils from a specific server slave using the MODBUS TCP IP protocol This is based on MB TCP Req Rsp generic communication function for which operates as an interface with the specific command code Socket parameter is the handle of the specific connection on which execute the request Slave Add parameter select the specific slave on serial bus if the server is a gateway to a RTU subnet Address parameter is the starting bit address to read Quantity parameter indicates the number of bits to be read Data parameter is the pointer of the buffer in which receive the values of the bits The LSB of the first byte of the buffer contains the addressed bit The amount of bytes placed in the receive buffer is equa
113. sponse the database connection is closed Related Topics MySQL Connect Set 117 Target CoDeSys Reference Manual 1 13 4 MySQL_Fetch_Row FUNCTION MySQL_Fetch_Row STRING VAR_INPUT Row STRING END_VAR Extracts a row from the query result set Return Value The same string pointer passed as parameter Input Parameters Row Pointer of string where to copy the row readed Comments The database queries such as SELECT SHOW DESCRIBE EXPLAIN returns a result set consisting of whole rows table records that satisfy the condition of the query The query function saves the entire result set into a memory buffer from where you can sequentially extract individual rows by MySQL_Fetch_Row function calls Each fetched row is copied into the string pointed by the Row parameter passed to the function and contains all the columns fields of the record separated by semicolons plus space All fields of string type are delimited by single quotes apostrophes If the row is not available returns the empty string Related Topics MySQL Data Seek 118 Target CoDeSys Reference Manual 1 13 5 MySQL_Field_Len FUNCTION MySQL_Field_Len UINT VAR_INPUT Field UINT END VAR Reads the length of a field of the database table Return Value Length of the field in the table Input Parameters Field Number of field for which read the length Comments The function allows to know the length of a specific field of the table following
114. st be reinitialized using the IPETH command Command Syntax ancp x where x is either 0 DHCP off or 1 DHCP on Example ncp 1 Related Topics GATEWAY command IP command IPETH command NETMASK command 193 Target CoDeSys Reference Manual 2 2 DNSNAME Change the current value of DNS NAME 1 2 entry into CHIP INI file DNS server is a service to resolve the IP address value from a registered domain name NOTE two name setting is available 1 and 2 Command Syntax dnsname n XXX XXX XXX XXX Example dnsname 1 8 8 8 8 194 Target CoDeSys Reference Manual 2 3 FTPPASSWORD Change the current value of FTP PASSWORD0 1 entry into CHIP INI file User name and password registration protects access to FTP connection NOTE two user setting is available 0 and 1 Command Syntax ftppassword n password Example ftppassword 0 ftp_password0 Related Topics FTPUSER command 195 Target CoDeSys Reference Manual 2 4 FTPUSER Change the current value of FTP USERO 1 entry into CHIP INI file User name and password registration protects access to FTP connection NOTE two user setting is available 0 and 1 Command Syntax ftpuser n user name Example tpuser 0 ftp user0 Related Topics FTPPASSWORD command 196 Target CoDeSys Reference Manual 2 5 GATEWAY The GATEWAY command sets the address of the standard gateway of the ethernet interface After setting the IP configuration the et
115. state with a minimum processing time For this reason the function block must be inserted into a POU of the IEC program updated by a dedicated task When the SMS service is activated the Ready output becomes TRUE and from this moment should be considered the execution of other parts of the POU By setting the Start signal to FALSE shall start a procedure for disabling the modem connection and shutdown If the Sim Pin configuration parameter is not explicitly defined in the function block the value in the CHIP INI configuration file is used and if not available in that file it uses the disabled value The function block returns the current state of the service with one of the values defined by the MODEM STATUS type Status 0 Modem is OFF in standby mode Status 1 Initialization of modem connection Status 4 Modem connected to the service Status 7 Deinitialization of the modem Status 20 SMS sending in progress Status 21 SMS sent successfully Status 22 Error while sending the SMS Status 23 SMS getting in progress Status 24 Received and getted an SMS Status 25 SMS available in reception When this function block is in the state of the activated service it awaits the request of a command to send SMS or extract a received SMS The SMS Send Start input signal forces the graph of the block in the state of sending the SMS according to the previously prepared data The result of the operation is indicated by the value of
116. t valid object address slave has received a not valid object data non recoverable error during execution of the slave function response to prevent a master receive timeout while slave performs a long operation 6 slave is busy in the execution of required function 130 timeout during master reception 133 bad slave address in replay 134 bad function code in replay 136 bad number of bytes received 138 bad MBAP header in replay gt 200 error code according to the coding adopted by the TCP IP stack aorwon oOo Input Parameters Socket Socket descriptor handle used by the connection Slave_Add Slave address valid 0 255 Fun_Code MODBUS function code Req_Data Pointer to request data buffer Req_Len Number of request data bytes Rsp_Data Pointer to response data buffer Rsp_Len Number of response data bytes aspected Comments This function execute a complete MODBUS TCP IP communication sequence with a server on the network Socket parameter is the handle of the specific connection on which execute the request Slave_Add parameter selects the specific ID of a slave connected on a subnet over serial bus This is used in the case of complex networks realized with a gateway that convert between Modbus TCP IP and RTU to address a specific slave within the subnet The 177 Target CoDeSys Reference Manual values 0 247 are normally assigned to a slave while the value 255 is used for the direct communication with
117. te device answers the call the status of the graph goes to Call SENDED If the called device hangs up the call or does not answer or is busy the state after the transition to the CALL TERMINATED value return to MODEM CONNECTED To terminate the outgoing call by the caller the Call Hang Up input signal must be activated Both Call Send Phone and Call Hang Up variables must be activated for at least one cycle and then reforced to inactive value FALSE Finally in the state of service activated also some specific modem functions can be executed forcing a command code in the Command input variable The Command Data input variable can supply also an optional data string specific for the command type Any information replayed by the modem is shown in the Command Replay output variable For example the MODEM SIGNAL READ command code allows the updating of Signal output value that indicates the signal strength of the radio network NOTE all the configuration parameters of the modem not explicitly defined in the function block are taken from the CHIP INI file Related Topics MODEM CHAR SET MODEM COMMAND MODEM DATA SERVICE MODEM STATUS 102 Target CoDeSys Reference Manual 1 11 9 GM01 SMS FUNCTION BLOCK GMO1 SMS VAR INPUT Start BOOL Sim Pin STRING 12 Char Set MODEM CHAR SET SMS Send Start BOOL SMS Send Phone STRING 20 SMS Send Text STRING 160 SMS Get Start BOOL END VAR VAR OUTPUT Ready BOOL Status M
118. temname Pointer to string holding the name of the desired entry max 40 characters pltemtext Pointer to string holding the text of the entry to be written max 128 characters Comments The functions RtosGetlniEntryEx and RtosSetlniEntryEx are not reentrant Do not use these in different tasks or in combination with other functions or commands which write to the configuration file Related Topics RtosGetlniEntry RtosGetlniEntryEx RtosSetlniEntry 70 Target CoDeSys Reference Manual 1 4 The SysLibEvent library SysLibEvent lib Here is a list of all the functions this library offers SysEventCreate SysEventDelete SysEventSet SysEventWait 71 Target CoDeSys Reference Manual 1 4 1 SysEventCreate FUNCTION SysEventCreate DWORD VAR_INPUT pName POINTER to STRING END_VAR Creates a new event with given name Return Value 16 FFFFFFFF error else success handle to new event which should be created Input Parameters pName Pointer to STRING containing the name of the event 72 Target CoDeSys Reference Manual 1 4 2 SysEventDelete FUNCTION SysEventDelete BOOL VAR_INPUT dwHandle DWORD END_VAR Deletes an event Return Value TRUE success FALSE error Input Parameters dwHandle Handle to event which should be deleted 73 1 4 3 SysEventSet FUNCTION SysEventSet BOOL VAR_INPUT dwHandle DWORD END_VAR Sets an event Return Value TRUE success event is set
119. ters Number of the message exchange as returned RtosCreateMsg in structure MSG Related Topics RtosCreateMsg 51 Target CoDeSys Reference Manual 1 3 4 RtosDhcpUse FUNCTION RtosDhcpUse BYTE VAR_INPUT onOffRead BYTE END_VAR Switches DHCP usage on off or determines wether DHCP usage is on off Return Value 0 DHCP is off 1 DHCP is on Input Parameters onOffRead 0 set DHCP off 1 set DHCP on 2 read DHCP usage Related Topics Rtoslpconfig 52 Target CoDeSys Reference Manual 1 3 5 RtosFindMsg FUNCTION RtosFindMsg INT VAR_INPUT pID POINTER to UINT pName POINTER to STRING END_VAR Finds the ID of a message exchange by the 4 character name Return Value Returns 0 on success otherwise error code Input Parameters Pointer to a UINT into which the ID of the message exchange will be stored pName Pointer to 4 bytes containing the name of the message exchange as defined in the MSG EX structure before calling RtosCreateMsg Related Topics RtosCreateMsg 53 Target CoDeSys Reference Manual 1 3 6 RtosGetBootstrapVersion FUNCTION RtosGetBootstrapVersion WORD VAR_INPUT dummy BYTE END_VAR Returns the version of the processor s bootstrap loader Return Value The bootstrap loader version is returned in one WORD where the high byte is the more significant digit the low byte is the less significant digit Input Parameters dummy Not used
120. the Status output variable Then the SMS Send Start signal must be put back inactive to return in the idle state waiting for a new command The SMS Get Start input signal force the graph of the block in the state of the received SMS extraction The Status output variable indicates the availability or not of an SMS in reception and the data of a new SMS are available in the respective output variables Then the SMS Get Start signal must be put back inactive to return in the idle state waiting for a new command To receive more incoming SMS the SMS Get Start signal must be activated periodically checking the reception via the Status output value The Signal output indicates the field strength of the radio network NOTE SMS management is useable as an alternative to other types of services like permanent PPP connection Related Topics MODEM CHAR SET 104 Target CoDeSys Reference Manual MODEM STATUS 105 Target CoDeSys Reference Manual 1 12 The TCPIP library TCPIP_Lib lib This library offers the functions for the TCPIP applications Here is a list of all the functions this library offers HTTP_Get HTTP Post SendMail SNTP DateTime 106 Target CoDeSys Reference Manual 1 12 1 HTTP Get FUNCTION HTTP Get INT VAR INPUT Request STRING Result STRING Result Max Len NT DNS STRING END VAR Sends HTTP GET request and receive the result page Return Value 0 success 1 4 DNS client error 201 265
121. the execution of a query that returns a result set The length is determined at creation of the field in the table and also defines the memory used to store values Related Topics MySQL Num Fields MySQL Field Name 119 Target CoDeSys Reference Manual 1 13 6 MySQL Field Name FUNCTION MySQL Field Name STRING VAR INPUT Name STRING Field UINT END VAR Reads the name of a database table field Return Value The same string pointer passed as parameter Input Parameters Name Pointer of string where to copy the name readed Field Number of field for which read the name Comments This feature allows you to read the name associated with one of the fields columns of the table following the execution of a query that returns a result set The parameter Field indicates the position of the column between 0 and Num Fields 1 where Num Fields is the value returned by MySQL Num Fields The field name is copied to the string pointed by the Name parameter passed to the function If the name is not available returns the empty string Related Topics MySQL Num Fields MySQL Field Len 120 Target CoDeSys Reference Manual 1 13 7 MySQL Num Fields FUNCTION MySQL Num Fields UINT Reads the current number of fields after a query execution Return Value Number of fields in the table related to the query Input Parameters None Comments This function allows you to read the number of fields columns available in the t
122. tion file not found otherwise number of characters read Input Parameters pFilename Pointer to string holding the configuration file name max 80 characters pSection Pointer to string holding the section pltemname Pointer to string holding the name of the desired entry pltemtext Pointer to string in which the text of the desired entry will be copied must be max 1en 1 size len Maximum lenghth of the target string at pltemtext not including terminating null character Comments The functions RtosGetlniEntryEx and RtosSetlniEntryEx are not reentrant Do not use these in different tasks or in combination with other functions or commands which write to the configuration file Related Topics RtosGetlniEntry RtosSetlniEntry RtosSetlniEntryEx 58 Target CoDeSys Reference Manual 1 3 11 RtosGetLinkstate FUNCTION RtosGetLinkstate WORD VAR_INPUT dummy BYTE END_VAR Returns the link state of the controller s ethernet interface Return Value bit 0 1 link ok 0 no link bit 2 1 initialization of the ethernet device failed Input Parameters dummy Not used Related Topics RtosGetMacAddress 59 Target CoDeSys Reference Manual 1 3 12 RtosGetMacAddress FUNCTION RtosGetMacAddress BYTE VAR INPUT pBuf POINTER to BYTE END VAR Returns the MAC address of the controller s ethernet interface Return Value Returns always 0 Input Parameters pBuf Pointer to buffer for MAC address Comm
123. tion for which operates as an interface with the specific command code Slave_Add parameter selects the specific slave on serial bus Address parameter is the starting word address to read Quantity parameter indicates the number of words to be read Data parameter is the pointer of the buffer in which receive the values of the words The amount of bytes placed in the receive buffer is equal to Data_Len 2 Quantity The function returns 0 if it executes without error otherwise it returns the error code The error codes are those of the MB RTU Req Rsp function to which are added those of the specific command Related Topics MB RTU Rd Inputs 157 Target CoDeSys Reference Manual 1 16 8 MB_RTU_Rd_Inputs FUNCTION MB_RTU_Rd_Inputs UINT VAR_INPUT Slave_Add BYTE Address WORD Quantity WORD Data DWORD END VAR Executes the MODBUS RTU function code 2 Read Discrete Inputs Return Value 0 success 144 Quantity parameter not valid 147 replay with byte counter value not valid Input Parameters Slave Add Slave address valid 1 247 Address Address of first bit to be read Quantity Number of bits to be read Data Pointer of data buffer for reading Comments The function reads the status of one or more bits of input Discrete Inputs from a specific slave using the MODBUS RTU protocol This is based on MB_RTU_Req_Rsp generic communication function for which operates as an interface with the specific c
124. to the administration pages Example Err Code HTTP Get www mysite com page php pari 123 amp par2 456 Result 500 107 Target CoDeSys Reference Manual Related Topics HTTP Post 108 Target CoDeSys Reference Manual 1 12 2 HTTP_Post FUNCTION HTTP_Post INT VAR_INPUT Request STRING Query STRING Result STRING Result Max Len INT DNS STRING END VAR Sends HTTP POST request and receive the result page Return Value 0 success 1 4 DNS client error 201 265 TCP IP functions error 1 2 4 8 16 SSL functions error Input Parameters Request URL of the requested resource max 400 characters Query String with the parameters list max 2000 characters Result String to receive the response max 4000 characters Result_Max_Len Max number of characters to receive DNS Specific DNS server address Comments This function sends a request to a web server using an URL with POST method and returns all the string including header of the page The Request parameter is the string containing the request with the form Username Password Host Port Path Username Password send optional authorization fields Host address of the server that has the resource Port select a port other than the default 80 Path full path to the server resource Query parameter is the string containing the parameters Query parameters to send 1 2
125. tween nonblocking and blocking mode Returns 0 on success and 1 on error O Parameter Pointer to DINT which specifies if the socket should be switched in blocking or in nonblocking mode 0 gt Blocking mode lt gt 0 gt Nonblocking mode By default every socket is in blocking mode so all functions are blocking This means a socket function does not return until an expected result can be returned So the calling task pauses until the function returns E g the SysSockAccept function does not return until a client establishes a connection to the socket Or the SysSockRecv function does not return until some data is available in the receive buffer of the socket Using the SOCKET FIONBIO command a socket and so its functions can be switched into the non blocking mode Using the return values of the socket functions you can decide if the function call was successful or if an error has occured If an error has occured you can use the function SysSockGetOption to read the error code With the error code you can see if a real error has occured or the function would block If the function would block you have to call that function again until it would not block anymore Example in ST IF NOT ConnectionIsEstablished THEN bRet SysSockConnect sd ADR addr sizeof addr IF bRet FALSE THEN diError 6 dwErrorSize sizeof diError bRet SysSockGetOption sd SOCKET_SOL SOCKET_ERROR ADR diError ADR diErrorSize IF bRet FA
126. ured Query Language protocol A detailed documentation can be found at the following link http www mysgl com Most of Web hosting provider offers a service for the MySQL database In this way you can access directly to the database using various tools provided in the control panel of the service There are also several tools program running on your PC to access and manage a remote MySQL database One of these is http www heidisgl com which is a powerful and free tool to create and interact with a local or remote database In addition there are various tools for the direct installation of a MySQL database on your server or PC as hrefz http www apachefriends org en xampp html http www wampserver com en download php These tools installed a local server allow both the running of PHP scripts and the MySQL database management as it happens with the external Web hosting services The MySQL library consists of CoDeSys functions that access using the HTTP client to a PHP server for the execution of a script as interface with MySQL For this you need to pre install the MySQL folder containing the PHP code on a server that can also be the same that runs the MySQL database The PHP code triggered by the library functions performs a specific queries on the database and returns data in response Later other library functions can access to the data received by the query Here is a list of all the functions this library offers My
127. used TimeZone parameter identifies the geographical zone for example 1 for Rome This offset is added to the UTC Coordinated Universal Time returned by NTP server Daylight_Save enable the sum of one hour to take account of daylight saving This enabling is diversified for every country so its management request the knowledge of the specific situation With the value 0 of the parameter does not add one hour winter while with the value 1 is added one hour summer The values above 1 encoding zones for the automatic calculation of daylight saving Currently it is implemented the management of value 2 relative to Europe The resultant value of date and time is finally forced into the Real Time Clock device of PLC NOTE by enabling the automatic NTP synchronization with the appropriate configuration parameters of CHIP INI file see NTP section of the configuration Web interface a single NTP synchronization is executed every time the PLC power supply is started Successive NTP synchronizations with CHIP INI default parameters can be then triggered inside IEC program calling the function with null input values SNTP_DateTime 0 0 Example Result SNTP DateTime 62 206 250 163 1 TRUE 113 Target CoDeSys Reference Manual 1 13 The MySQL library MySQL Lib lib This library offers the functions for the management of the MySQL databases MySQL is one of the world s most used database and its data access is based on SQL Struct
128. ut Tx Delay UINT END VAR Initializes the RS485 type A expansion communication Return Value Always TRUE Input Parameters Port Serial port number default to COM2 2 Baudrate Speed of communication default to 115200 bits s Timeout Maximum wait for data reception default to 2ms Tx Delay Bytes spacing during transmission default to 0 Comments Use this function to initialize the RS485 type A communication with expansion slaves This function is not necessary in the case of communications with default parameter values Related Topics 5485 Tx 147 Target CoDeSys Reference Manual 1 15 3 RS485 Tx Rx A FUNCTION RS485 Tx Rx A UINT VAR INPUT Add Cmd BYTE Tx Num UINT Rx IO DWORD Swap USINT END VAR Executes the RS485 type A expansion communication Return Value 0 success 200 bad parameter 201 serial initialization error 202 slave has received a bad checksum 203 master has received a bad checksum 204 timeout during master reception Input Parameters Add Cmd Header byte with formatted slave address and command Tx Num Number of bytes for output area Num Number of bytes for input area IO Ptr Pointer to output input area buffer Swap Swap bytes of word 2 or dword 4 Comments This function executes a complete sequence of RS485 type A communication with expansion slaves Type A communication works as follows The value
129. ut Regs MB TCP Rd Inputs MB TCP Req Rsp MB TCP Wr Coils MB TCP Wr Hold Regs MB TCP Wr Rd Hold Regs MB TCP Wr Single Coil MB TCP Wr Single Reg MB TCP Server MB Swap Dword MB Swap Dword2 MB Swap Word 149 Target CoDeSys Reference Manual 1 16 1 MB_RTU_PARITY TYPE MB_RTU_PARITY TYPE MB RTU PARITY PARITY NO 0 PARITY ODD 1 PARITY EVEN 2 PARITY NO 1S 3 END TYPE This type enumerates the desired parity setting of a serial port Member PARITY NO 0 no parity 2 stop bits PARITY ODD 1 odd parity 1 stop bit PARITY EVEN 2 even parity 1 stop bit PARITY NO 15 3 no parity 1 stop bit NOTE In the case of No parity the protocol specification requires the presence of two stop bits However for compatibility with other systems that do not comply with this standard is also available No parity mode with only one stop bit Below is an extract of the official specific of MODBUS RTU protocol 150 Target CoDeSys Reference Manual 2 5 1 RTU Transmission Mode When devices communicate on a MODBUS serial line using the RTU Remote Terminal Unit mode each 8 bit byte in a message contains two 4 bit hexadecimal characters The main advantage of this mode is that its greater character density allows better data throughput than ASCII mode for the same baud rate Each message must be transmitted in a continuous stream of characters The format 11 bits
130. ver NOTE pSockAddr sin family must be set to SOCKET AF prior to call Return Value TRUE success FALSE error Input Parameters diSocket Socket descriptor Pointer to a SOCKADDRESS struct which contains the address and the port of the TCP server diSockAdarSize Size of the SOCKADDRESS struct in bytes 23 Target CoDeSys Reference Manual 1 2 11 SysSockCreate FUNCTION SysSockCreate DINT VAR_INPUT diAddressFamiliy DINT diType DINT diProtocol DINT END VAR Opens a new socket for UDP or TCP communication Return Value 1 error gt 0 success new socket descriptor Input Parameters diAddressFamiliy Address family SOCKET_AF_INET supported only diType Socket type SOCKET_STREAM for TCP SOCKET_DGRAM for UDP diProtocol Protocol type SOCKET_IPPROTO_IP supported only 24 Target CoDeSys Reference Manual 1 2 12 SysSockGetHostByName FUNCTION SysSockGetHostByName DWORD VAR_INPUT pHostName POINTER to STRING END_VAR Get the name of the host Return Value SOCKET_INADDR_NONE error 16 FFFFFFFF else success valid hostaddress Input Parameters pHostName Pointer to variable of type STRING containing the hostname 25 Target CoDeSys Reference Manual 1 2 13 SysSockGetHostName FUNCTION SysSockGetHostName BOOL VAR_INPUT pHostName POINTER to STRING diNameLength DINT END VAR Get the name of the host Return Value TRUE success
131. with the specific Host is allowed only when the value of IP changes For this while maintaining the function block permanently enabled it will check continuously the variation of the current IP compared to the value previously stored Only in case of variation will provide a new request to the server to update its IP For each parameter not explicitly defined in the function block it uses the value in the CHIP INI configuration file and if not available in that file it uses a fixed default value Server_Url members dyndns org nic update User myplc_user Password myplc_password Hostname myplc dyndns org myplc is the DEVICE NAME parameter value of CHIP INI file The function block returns the current status of the update with one of the values defined by the DYNDNS_STATUS type Status Service is waiting for activation Status 1 Updating request in progress Status 2 IP address is updated on the server Status 3 Update on the server failed Status 4 Waiting before retry The Last IP output indicates the value of the last IP address permanently saved in CHIP INI file Related Topics DYNDNS STATUS 95 Target CoDeSys Reference Manual 1 11 7 GMO1 PPP FUNCTION BLOCK GM01 PPP VAR INPUT Start BOOL Sim Pin STRING 12 Auth SINT User STRING 20 Password STRING 20 Connect String STRING 80 Dial STRING 20 Retry Seconds INT END VAR VAR OUTPUT Ready BOOL Status MODEM STATUS Signal

Download Pdf Manuals

image

Related Search

Related Contents

Elcometer 134S Chloride Ion Test Kit for Surfaces Data Sheet  ダウンロード  Radica Games Lighted Blackjack 74005 User's Manual  残存酸素計「パックマスター」 型式:RO-103  取扱説明書 - 日立の家電品  IT - Comestero  LabVIEW PID Control Toolset User Manual  9101 Zero Point Dry-Well    ICY BOX IB-223U3-B USB powered  

Copyright © All rights reserved.
Failed to retrieve file