1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | This project is for the ASCII Art Ladder It converts PLCOpenXML files of ladder POUs exported from CODESYS into a beautiful ASCII Art It will initially use: CODESYS Ladder Editor CODESYS PLCOpenXML Export CODESYS Scripting Engine / IronPython Python XML Some new ASCII Ladder format defined in this project Step 1: User will create the ladder in CODESYS Ladder Editor. User will compile the ladder without any errors. Step 2: User will export just one single ladder routine to PLCOpenXML Step 3: User will run the PLCOpenXMLLadderToASCIILADDER.py script, with the correct arguments Step 4: The script will look for a declaration header as plain text and save this Step 5: The script will read every subelement of <LD>. Ones it can't understand will be put in an exceptions tag Step 6: The script will arrange all of the ladder elements into rows and columns. This new element array will also list branches in down / in up / out down / out up Step 7: The script will write each row and column to a text file in ASCII Art Ladder format Step 8: The script will list all truncated names, and complete all truncated EXECUTE blocks Example File Output: //This is a rung comment (*Also a rung comment*) (**Mabe a nicer * Way to do multiline comments *) (** supported features: * 001 ‘Network’ * 002 ‘Box’ * 002 ‘Assignment’ * (003 FB, 003 FN) ‘Box with EN/ENO’ * 002 ‘Input’ * 005 ‘Label’ * 005 ‘Contact’ * 005 ‘Coil’ * 005 Negated Contant * 006 Branches (note, branches always close!) * 007 Set coil * 007 Reset coil * 008 short circuit evaluation (SCE) (Toggle Parallel Mode) (I dislike this enough I make you use extended ascii) * 008 Negation (I dislike this enough I make you use extended ascii) * 009 Jump * 010 Return * 011 Network Comment State * 012 FBD/LD/IL Element ‘Execute’ * 013 Names are too long (abreviation section) * I think that's everything actually. *) (** Declaration Section: * Exact copy of the declaration section, with some indentation * Note any indentation that is the same for each line will be removed *) {Declaration} PROGRAM POU VAR END_VAR {/Declaration} (** Abbreviation Section: * Sure it can get confusing. Maybe later can alter it so not fixed width ladder * For importing, it is OK to change the abbrevioations however you please * Rules: Generally if too long: * take first three letters and last three and add a ~0 through ~9 * If more than 10 have same first three and same last three, the 11th becomes ~~10 * If there is one or more points in the variable name, shorten the first three and but the point before the ~ *) {Abbreviaitons} Nam~0GHT := NameEIGHT; Nam~1GHT := NameONE_HUNDRED_AND_EIGHT; Nam~2GHT := NameI_CANT_WEIGHT; F_C~0ate := F_Calculate; FB.~0ate := FB_Timer.Calculate; {/Abbreviations} (** Execution Section: * If the execution block is too big to fit, * either width ways or column ways, write it's Execution here. * Note any indentation that is the same for each line will be removed *) {Executions} {~1} thisvariable := actuallyToolong; REsult := Function(); //I added a comment //If line too long it gets truncated // >6 line, ~ bottom right IF TRUE THEN DoSomethingCool; END_IF; {/~1} {/Executions} {Ladder} 001 ||. . . . . . || || || ||------------------------------------------------------------|| || || 002 ||. . . ________ . || || NameEIGH | F_Name | NameEIGH || ||----] [------------------------Input_01|--------------( )---|| || Variable==In_out01| || || =InOut2 | || || Variable--Input2 | || || =InOut3 | || || | Out01--Variable || || | Out02--Variable || || |________| || || || 003 ||. . . ________ . || || NameEIGH NameEIGH Instance--FB_Name8| NameEIGH || ||----] [-------] [--------------EN ENO---------------( )---|| || -Input01 | || || | Out01- || || =In_out01| || || =Inout2 | || || |________| || || || 004 ||. . . ________ . || || NameEIGH | F_Name | NameEIGH || ||----] [------------------------EN ENO---------------( )---|| || Variable--Input01 | || || | Out01--Variable || || Variable==In_out01| || || Variable==Inout2 | || || |________| || || || 005 ||. . . . . . || myLabel || NameEIGH NameEIGH NameEIGH || ||----] [-------]/[-------------------------------------( )---|| || || 006 ||. . . . . . || || NameEIGH NameEIGH NameEIGH || ||+---] [--++---] [------------+------------------------( )---|| ||| || | || ||| || . | || |||NameEIGH||NameEIGH NameEIGH| || ||+---] [--++---] [-------]/[--+ || || || 007 ||. . . . . . || || NameEIGH NameEIGH NameEIGH || ||----------------------------------(R)-------(S)---+---(S)--+|| || | ||| || | ||| || |NameEIGH||| || +---(R)--+|| || || 008 ||. . . . . . || || NameEIGH ASCII181 NameEIGH || ||----] [---╬---] [--------------------------------╬----( )---|| || ║ ║ || || ║ . ________ ║ || || ║ASCII206 Instance--FB_Name8| ║ || || ╬---] [--------------EN ENO----------╬ || || NegInVarø-Input01 | || || | Out01-øASCII155 || || =In_out01| || || =Inout2 | || || |________| || || || 009 ||. . . . . . || || myLabel || ||----------------------------------------------------<JUMP>--|| || || 010 ||. . . . . . || || || ||---------------------------------------------------<RETURN>-|| || || 011 ||##. . . . . . || ||## NameEIGH || ||##----] [--------------------------------------------<RETURN>-|| ||## || 012 ||. . . __________________________ . || || NameEIGH | Execute ~1 | || ||----] [---------------EN ENO------------|| || |thisvariable := actuallyT~| || || |REsult := Function(); | || || |//I added a comment | || || |//If line too long it get~| || || |// >6 line, ~ bottom right| || || |IF TRUE THEN | || || |_________________________~| || || || 013 ||. . . ________ . || || FB.~0ate Nam~1GHT |F_C~0ate| Nam~2GHT || ||----] [---+---] [--------------EN ENO----------+----( )---|| || | NegInVarø-Input01 | | || || | | Out01-øASCII155| || || | =In_out01| | || || | =Inout2 | | || || | |________| | || || | . ________ | || || |Nam~0GHT Instance--FB_Timer| | || || +---] [--------------EN ENO----------+ || || NegInVarø-Input01 | || || | Out01-øASCII155 || || =In_out01| || || =Inout2 | || || |________| || || || {/Ladder} |