Home

C language function

image

Contents

1. read the value of PSW 300 and PSW 301 as the float format DWORD PSW 300 dwValue assign one double words to PSW 300 and PSW 301 2 5 2 PSB operation functions GetPSBStatus PSB No obtain the value of PSB SetPSB PSB No PSB 1 ResetPSB PSB No PSB 0 Example PSB 301 PSB 300 if GetPSBStatus 300 SetPSB 301 else 6 19 ResetPSB 301 2 6 Notice 1 When input API function make sure the function name is together with and no space between them Dialog and tip box will pop up by doing this 2 Capital and small letter is distinguished for the code 3 It cannot assign initial value to the global variables defined in the public function The default value of global variables is 0 4 When define the variables the type must be the same to the data source 5 The performance function name must be English and cannot be the same with others 6 Press F7 to compile the program 7 When declare the variables global or local variables don t declare the array whose space larger than 128 bytes It can use special space allocation function 8 Cannot call malloc free directly but please use Malloc Free first letter is capital 9 The execution environment of performance function is multi tasking The execution mode of performance function parallel execution sequential execution Sequential execution The task which calls the performance function enables to do the next o
2. G D 0 0 T Read PLC 1 XINJE XC RE VPE WORD amp a 1 2 3 4 5 6 T if a b 8 max a min b 9 else 10 max b min a 11 if max lt c 12 max c 13 if min c 15 minse 15 16 17 18 rite HMI LOCAL MCH O TYPE PSU 390 0 TYPE WORD max Write HMI_LOCAL_MCH TYPE_PSW 301 0 TYPE_WORD min 6 Press F7 to compile the C function If the program is correct it will show below window Ti xi A us 4 3Make the HMI program 1 Put 3 digital input buttons on the screen Set the address to DO D2 and D4 2 Put 2 digital display buttons on the screen Make the address to PSW300 and PSW301 3 Put 1 function button on the screen to call the Funcl 12 19 2 Call Function 4 The final screen 5 Download the HMI program to the TH465 Connect PLC with the TH465 power on Input any value in a b c Click Func button the max and min value will show on the screen 13 19 Appendix 1 System tips WORD a b c g 4 Read PLC 1 XINJE XC BIT M 0 0 TYPE BIT amp b Read the value of MO to b Read PLC 1 XINJE XC REG D 2 0 TYPE WORD amp b Read the value of D2 to b Reads PLC 1 XINJE XC REGS D 10 4 g Read the value of D10 D13 to g Read HMI LOCAL MCH 0 TYPE PSB 300 0 TYPE BIT amp a Read the value of PSB300 to a Read HMI LOCAL MCH 0 TYPE PSW 300 0 TYPE WORD amp b Read the value of PSW300 to b Reads HMI LOCAL MCH 0 TYPE PFW 300 4 g
3. ze se s se se se ae se zde sle sle se se akk ze ze se sle sle se SE se ze se akk sle ak ole ze sl sle se se sle sle sk se akk sle se se akk he ze sle sle sle s ske se ie 28 LLLLLLLLLLLLLLLLLLLLLLLLLI Function Enter Leave signal control ensure the communication is synchronization mode Use together with send and receive LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLELILEL NH He ak se se ze se oe se ske sk se akk sle s s ske ske sk akk 2 akk sk void Enter BYTE ComID void Leave BYTE ComlID FR k hg zde ze se se se se se ae ak zde se sle se ae akk ze ze se sle se se SE se ae se sle sle ak sle zde se sle se se sle ske se se akk sle se se akk sle ze sle sle sle ak ske se sei LLLLLLLLLLLLLLLLLLLLLLLLLI Function send data of serial port comID serial port DOWNLOAD 0 PLC 1 SndBuf sending buffer the type is byte Len sending data length count as byte Return value TRUE FALSE successful failed FR k he ze ze se sle se se sle ae ak zde se sle akk ae akk ze ze se sle sle se SE se ze se akk sle ak ole ze sle sle se se sle sle se se sle sle akk se ske sle ze sle sle se ak ske se sie ACE ak ske ak se se sese se akk ske akk sk se sle s s s ske akk ske sle sle 2 sk BOOL Send BYTE ComID BYTE SndBuf WORD Len FR AR A ag hg zde ze se ae ak se ak ae ak se sle sle se ae akk ze ze se sle se ak SE se ze se akk sle ak ze sle sle se se akk akk sk se akk sle se se akk he ze 2 sle se ak ske se ie 28 16 19 ze s
4. OL Write int comID int stalD int objType int addl int add2 int dataType DWORD dwValue Example BOOL bValue FALSE WORD wValue 0 Read PLC 1 XINJE XC BIT M 0 0 TYPE BIT amp bValue read the bit Read PLC 1 XINJE XC REG D 0 0 TYPE WORD amp wvValue read D 0 Read HMI LOCAL MCH 0 TYPE PFW 300 0 TYPE WORD amp w Value read PF W 300 Write HMI LOCAL MCH 0 TYPE PFW 300 0 TYPE WORD wValue write PFW 300 15 19 FR AR k hg ze ze se s se se se ae ak zde sle sle se ae sle ze ze se sle sle ak SE se ze se sle sle ak sle ze sle sle se se sle sle hee akk sle se se ske he ze sle sle sle ske se ski LLLLLLLLLLLLLLLLLLLLLLLLLI Function read and write register array comID serial port HMI LOCAL MCH 1 DOWNLOAD 0 PLC 1 staID station number objType register address type add1 register address regs register quantity pRegs value buffer the length must be match to the read amp write register array return value TRUE FALSE successful failed LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLELELE Fk s ak ske He se ae ze se s se sle sk se akk sle s s ske ske sk akk 2 ske sk BOOL Reads int comID int stalD int objType int addl int regs void pRegs BOOL Writes int comID int stalD int objType int addl int regs void pRegs Example WORD waArray 10 Reads PLC 1 XINJE XC REGS D 0 10 wArray Writes PLC 1 XINJE XC REGS D 0 10 wArray PE A ig hg ze
5. Read the value of PFW300 PFW303 to array g Write PLC 1 XINJE XC BIT M 0 0 TYPE BIT 0 Set OFF MO Write PLC 1 XINJE XC REG D 50 0 TYPE WORD a Write the value of a to D50 Writes PLC 1 XINJE XC REGS D 20 4 g write the value of array g to D20 D23 Write HMI LOCAL MCH 0 TYPE PSB 300 0 TYPE BIT 1 Set ON PSB300 Write HMI LOCAL MCH 0 TYPE PSW 300 0 TYPE WORD max write the value of max to PSW300 Writes HMI_ LOCAL MCH 0 TYPE PFW 300 4 g write the value of array g to PFW300 PFW303 14 19 Appendix 2 API functions Take XC as an example FR AR k he ze ze se se s se se ae ak zde se se se se sle ze ze se sle sle se SE se ze se akk sle ak ole ze ak sle se se akk akk sk oe sle sle se se ske sle ze sle sle sle ske se ie 28 LLLLLLLLLLLLLLLLLLLLLLLLLI Function read and write register for bit and register comID serial port HMI LOCAL MCH 1 DOWNLOAD 0 PLC 1 staID station number objType register address type addl add2 register address dataType TYPE BIT lt 1 occupy byte TYPE BYTE 2 occupy 1 byte TYPE WORD 3 occupy 2 bytes TYPE DWORD 4 occupy 4 bytes pValue value buffer the length must match to dataTyp return value TRUE FALSE successful failed LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLILE Fk ak ak He se ae ze se s se ske SE se akk sle se s ske ske sk eee BOOL Read int comID int stalD int objType int addl int add2 int dataType void pValue BO
6. Version 100 Description compare 3 values Author OK Cancel 9 19 3 Click Funcl to edit the C function File Edit View Part Tool Window Help Dc kl 5ES5 AK OS OR EN ER 5 BP my mg si Efi Project o BOKE KOK KE K P PO ES 4 2 Edit the C function 1 Define the character according to the C writing rules WORD a b c max min Define the value type according to the data source type 2 Collect the value to C function Read PLC 1 XINJE XC REG D 0 0 TYPE WORD amp a send the value of DO to a Read PLC 1 XINJE XC REG D 2 0 TYPE WORD amp b send the value of D2 to b Read PLC 1 XINJE XC REG D 4 0 TYPE WORD amp c send the value of D4 to c When you input Read it will pop up below window 10 19 Unit type the operation object type select register Station input the PLC station No Object input the object address DO Data type word Notes for details tips please refer to appendix 3 Edit the compare program if a gt b max a min b else max b min a if max lt c max c if min gt c min c 4 Send the result to the HMI Write HMI LOCAL MCH 0 TYPE PSW 300 0 TYPE WORD max write max value to PSW300 Write HMI LOCAL MCH 0 TYPE PSW 301 0 TYPE WORD min write min value to PSW301 5 The Funcl program 11 19 WORD a b c max min Read PLC 1 XINJE_XC_REG_D 4 0 TYPE_WORD amp Read PLC 1 XINJE_XC_REG_D 2 0 TYPE_WORD amp b
7. ak ske ak se akk ze se oe se sie sk se zde se s s ske ske sk eee Function receive the data of serial port comiD serial port DOWNLOAD 0 PLC 1 RevBuf receiving buffer the type is byte Len receiving data length count as byte Timeout receiving timeout time 0 always waiting Unit ms TimeOutByte receiving timeout time of bytes set to 6 Return value received data length count as byte PE A Ee ze ze ak ae s se ak ae ak zde sl sle se ae akk ze ze se sle sle se SE se ae se akk sle ak AC ze sle sle se se sle ole sk se akk sle se se akk he ze sle sle sle ske ske ie 28 Fk s ak se ak se se ze se se se ske akk se ae sle s s akk ske akk ske sle sle sko sk WORD Receive BYTE ComID BYTE RcvBuf WORD Len WORD TimeOut BYTE TimeOutBytes Exp BYTE byArray 10 10x00 Enter PLC apply the serial port Send PLC byArray 10 Receive PLC byArray 10 0 6 Leave PLC release the serial port FR A a he ze ze se se s se se ae ak zde ak sle se akk ze ze se sle sle ak akk ae ae se ak sle ak zde sl sle se se sle sle se se akk sle se se ske sle ze sle sle sle ske se ski LLLLLLLLLELLLLLLLLLLLLLLLLI Function Malloc Free instead of malloc free Note please release the applied space in time LLELEILLLLLLLLLLLLELLLLLLLLLELLLZELLLLLLLLZLLLLELLLLELLLLLLRZELLLSZEZLLLE AK He ak se ae ze sd oe se ae se se akk se se s ske ske sk akk 2 2 sk PE Ee se zde ze se s s se se ae se zde sle sle se se sle ze ze se sle
8. eouchWin C language function User s manual Xinje Electronic Co Ltd Catalog TIBIFOGUG PIDE eda dei latuit veto ade ba heran si totas ee vise nieto tarte lu 3 2 6 ETEA O e nbi ci ee reed ne Gode nate ond E hor UR S 3 2 1 Funet OAS ei et uet OOo SEN Ete une DURS 3 24 sol Public lO NSi ea os oie be e Db fes etu 3 2 1 2 Performance functions a o oec Does bove E EORR TERR EH sobe 4 2 2 Predefined value TVDEz annes desierit ta telo nas eite o kebaba 4 2 3 Predefined value tables sso esee a ird 4 PAX Constant a Te 4 2 90 Serial DEL onse vao Soon ud tct tesi aov muero ete 4 2 5 3o Internal registers coe oe t OE ER ERE DEA 5 22A Value TEN GU eot tret a e EO fot 5 pa Mie CT RENS 5 2 5 Direct operation for HMI internal registers 6 291 PSW TE SISTE rana echa epa dex a t tabe bede 6 2 5 2 PSB operation functions oe ee chis pe ERE ER REG 6 2 AN OU CG PTT P 7 DRA DDIICHTOTI s o ae aea ae eaa ao halen cia Mua salle 8 Sub PULDOSC aia ae n ei med A E E 8 3 2 NIC ai E E E T 8 3 3 Reference manua lisien E EA DOUG 8 SA OEDS aona O A IT 8 d Make the POJE CI a NS A a a a S a 9 Al Make UE OMAN AA oe te e Su SN td 9 42 Edt the C functione RR OUR A le seeders 10 4 3 Make the HMI prosta ses ret eot ore e Cree p edes 12 Appendix T System tipsi cas eps rite Doer bino tide SUD UHR o A CER RS 14 Appendix ZAPI TUNEL ORIS nanesi nena as eki ed px aaa or Manto Eu ud 15 Ap
9. le 2 3 1 Constant TRUE used to BOOL FALSE NULL 0 used to pointer initialization 2 3 2 Serial port HMI LOCAL MCH 1 DOWNLOAD 0 PLC 1 4 19 2 3 3 Internal registers TYPE PSB 0 1 TYPE PSW TYPE PFW 2 TYPE PRW 3 TYPE PHW 4 TYPE PUW 5 TYPE PCW 6 2 3 4 Value length TYPE NONE 0 TYPE BIT bit TYPE BYTE 2 byte TYPE WORD 3 word TYPE DWORD 4 double words TYPE REGS 5 register group TYPE BYTE 3 6 2 4 Macro 1 Max a b Example Max 3 4 4 2 Min a b Example Min 3 4 3 3 Combine two bytes in one word MAKEWORD Ib hb Example MAKEWORD 0x01 0x02 0x0201 4 combine two words in one double words MAKELONG Iw hw Example MAKELONG 0x01 0x02 0x00020001 5 Obtain the low byte of one word LOBYTE w Example LOBYTE 0x0201 0x01 5 19 6 Obtain the high byte of one word HIBYTE w Example HIBYTE 0x0201 0x02 7 Obtain the low word of one double words LOWORD I Example LOWORD 0x00020001 0x0001 8 Obtain the high word of one double words HIWORDG Example HIWORD 0x00020001 0x0002 2 5 Direct operation for HMI internal registers 2 5 1 PSW registers PSW registers can be operated directly the type is unsigned short WORD Example PSW 300 PSW 300 as the word DWORD dwValue DWORD PSW 300 assign the value of PSW 300 and PSW 301 to one double words float fValue float PSW 300
10. led they are related to heap 2 The assert functions in assert h cannot be called 3 The stream functions in stdio h cannot be called only the functions for string sscanf sprint can be used normally 4 The heap functions in stdlib h cannot be called but they can be instead by API functions Xinje Electronic Co Ltd eouchWin 4th Floor Building 7 Orignality Industry park Liyuan Development Zone Wuxi City Jiangsu Province 214072 Tel 510 85134136 Fax 510 85111290 www xinje com 19 19
11. ote the locked area access manage for global variables make the locked area as small as possible Suitable case the task lock is needed when there are many performance functions need access for one global variable FKK K K K K K K K K K K 3K FK K 3K FK K K 3K 3K K 3K FK FK K K FK K 3K 3K FK FK FK FK FK FK FK K K 3K FK FK K FK FK K K FK FK K 3K FK K OO RO K 3K Fk s ak ake akk ae ak ze se s se ae akk se zde sle s s ak a ak eee void Unlock void void Lock void FE AR Ee ze ze se s s se ak ae ak se se e se ae akk akk ze se sle sle ak akk se akk se akk sle ak A ze sle sle akk se akk akk se se akk sle akk se akk sle ze sle sle sle ak ske ske ie 28 FKK K K K K K K K K K K K K K K K K K K K K K K K Function Delay ms delay time unit ms the max delay time OxFFFF delay precision delay precision TP series except TPA61 T and OP series are 10ms TPA61 T and TH series are 5ms FKK K K K K K K K K K 2K 3K FK K 3K FK K K 3K 3K K 3K FK FK K K FK K K 3K FK FK FK FK FK FK FK K K 3K FK FK K RO K 3K 3K FK K 3K 3K K K K KO K 3K Fk ak ak ae ak se ak ze se oe akk ae akk se ate sle se s akk a sk eee void Delay UINT ms Example Delay 1000 delay 1s 18 19 Appendix 3 The calling limit for C function This chapter will introduce the restricted library functions Most C functions can be used normally except heap functions However the following functions are limited when using 1 The functions in alloca h cannot be cal
12. pendix 3 The calling limit for C funetion 19 2 19 1 Introduction C language function is added in the Touchwin software v2 C 6 and higher version With this new function TH and TP series HMI can realize more complicated operations We will explain the C function programming rules with simple examples 2 C function 2 1 Functions The C function writing mode is the same as C language C functions include public functions and performance functions 2 1 1 Public functions Public functions support basic call for performance functions It needs to write function prototype parameters and return value are allowed Example DWORD Crc BYTE pBytes int Length DWORD dwCrc 0 return dwCrc j Call performance functions in public functions void CallFunction Funcl 3 19 2 1 2 Performance functions Performance functions no return value no parameters It no needs to write function prototype only has to specify the function name direct write the function body Performance functions can be called through the function button and function field in Touchwin software Example BYTE byArray 10 DWORD dwCrc 0 dwCrc Cre byArray 10 call public function 2 2 Predefined value type UINT unsigned int 32bits 4 bytes same as DWORD DWORD unsigned long WORD unsigned short BYTE unsigned char BOOL unsigned char 2 3 Predefined value tab
13. peration after the performance function execution is finished So performance function must have suitable exit condition Parallel execution The task which calls the performance function will build new task to execute the function The task will do the next operation 10 Use carefully as the multi task system has task lock 7 19 3 Application 3 1 Purpose Get 3 integral from the PLC show the min and max ones on the screen 3 2 Device This project needs the following devices 1 TH series HMI TH465 MT 1pcs 2 XC series PLC XC3 24R E 1pcs 3 Software Touchwin version 2 c 6 and higher 4 Cables USB download cable Ipes PLC cable 1pcs PC 3 3 Reference manual 1 XC series PLC manual instruction part and hardware part 2 TH series HMI manual 3 4 Steps Set value in PLC register DO D2 D4 via the HMI Send the value of DO D2 D4 to the HMI Call the C function to compare the three values Show the max value in PSW300 the min value in PSW301 dose 8 19 4 Make the project 4 1 Make C function 1 Open Touchwin V2 C 6 software right click Function Insert TouchWin for TH Edit Tool Project Screeni File Edit View Part Tool Window Help D n teen ALM OOO Beer es meld eo Hajeeii Fe Es FE El lle 100 lll o v ix El f Project cl Screen m tB TEN Import 2 Input necessary information in below window then click OK Function E x Name Funct
14. sle se sk oe ze se akk sle ak ole ze sle sle se se sle sle se se akk sle se se akk sle ze sle sle sle ske se ie 28 LLLLLLLLLLLLLLLLLLLLLLLLLI Function apply heap space Size apply the space size bytes Return the applied space address NULL means the application is failed 2K ok ok of 2k ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ACE He ak se ae ze sd oe se ske akk se akk sle s s ske ske sk akk 2 ske sk void Malloc UINT size FR A Ee zde ze se sle ak se ak ae ak z se se se ae ak ze ze se sle sle se SE se ze se akk sle ak AC ze sle sle se se akk ak sk oe akk sle se se akk sie ze se sle se ak ske se ie 28 2K ok ok 2k of ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok Function release heap space pBuffer the space ready to release FKK K K K K K K K K K K 3K FK K 3K K K K 3K FK K 3K FK FK K K K K oe 3K FK FK FK FK FK FK FK se K 3K FK FK K FK K K 3K 3K FK 3K sie ske K K K K K 3K Fk ake ak ae ak se ak ze sd s se ae akk se ze se s s ak a sk eee void Free void pBuffer Example BYTE pBuffer Malloc 10 Free pBuffer 17 19 FR A i he ze ze se se s se ak ae ak se se sle se ae akk ze ze se sle sle se SE se ze se sle sle ak ae ae sle sle se se sle sle sk oe akk sle akk se ske sle ze se sle se ske ske 2g 28 LLLLLLLLLLLLLLLLLLLLLLLLLI Function Lock UnLock task lock use them in pairs N

Download Pdf Manuals

image

Related Search

Related Contents

Kenwood KMD-D400 Car Stereo System User Manual  Mini Thermal Receipt Printer  User Manual User Manual      Hitachi L100 Welding System User Manual  Échelle de douleur neuropathique, questionnaire DN 4  IT Istruzioni d `uso EN Instructions for use FR Notice d  RD 12A - Wacker Neuson  Hampton Bay CBW1703/3BRZ Installation Guide  

Copyright © All rights reserved.
Failed to retrieve file