Blame view
SanlienDataRecoder_01/Untitled1/POUs/PRG_DatFileCreat.TcPOU
9.69 KB
03a3ca636 初版 |
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
<?xml version="1.0" encoding="utf-8"?> <TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.11"> <POU Name="PRG_DatFileCreat" Id="{176c317a-1861-4b3c-96b5-e3f639fff030}" SpecialFunc="None"> <Declaration><![CDATA[PROGRAM PRG_DatFileCreat VAR iSeq : INT; iExceptionSeq : INT; fbGetSystemTime : NT_GetTime; i : INT; DatHeader : stDatHeader; (* Beware memory alignment *) DatAcqBlock : stAcquisitionBlock; pRequestData : POINTER TO BOOL; nCurRecodeNo : UDINT; sFileName : T_MaxString; fbFileOpen : FB_FileOpen; fbFileSeek : FB_FileSeek; fbFileWrite : FB_FileWrite; fbFileClose : FB_FileClose; nTxtParserLate : UDINT; (* Lag counter *) pPathPassThrough : POINTER TO T_MaxString; pStartParser : POINTER TO BOOL; END_VAR ]]></Declaration> <Implementation> <ST><![CDATA[pRequestData := ADR(MAIN.fbBufferAccess.bGetData); CASE iSeq OF 0: (* Check for bSamplingStart command start *) IF NOT(MAIN.fbBufferAccess.bFifoEmpty) THEN nCurRecodeNo := 0; iSeq := iSeq + 1; END_IF 1: (* Creat time serial file name *) fbGetSystemTime(NETID:= , START:= TRUE, TMOUT:= DEFAULT_ADS_TIMEOUT, BUSY=> , ERR=> , ERRID=> , TIMESTR=> ); IF NOT(fbGetSystemTime.BUSY) AND NOT(fbGetSystemTime.ERR) THEN (* iTemp := iTemp + 1; sFileName := USINT_TO_STRING(iTemp); sFileName := CONCAT (sFileName,'.dat'); *) sFileName := SYSTEMTIME_TO_STRING(fbGetSystemTime.TIMESTR); fbGetSystemTime(START:= FALSE); iSeq := iSeq + 1; ELSIF fbGetSystemTime.ERR THEN fbGetSystemTime(START:= FALSE); iExceptionSeq := iSeq; iSeq := 999; END_IF 2: (* fliter file name & creat further info *) FOR i := 1 TO len(sFileName) BY 1 DO IF F_ReplaceByString(sSource:= sFileName, sFindContent:= ':', sReplaceContent:='_' ) <> '' THEN (* Replace content to avoid involid file name *) sFileName := F_ReplaceByString(sSource:= sFileName, sFindContent:= ':', sReplaceContent:='_' ); ELSE EXIT; END_IF END_FOR sFileName := CONCAT (sFileName,'Node_'); sFileName := CONCAT (sFileName,INT_TO_STRING(MAIN.nAcuNodeId)); sFileName := CONCAT (sFileName,'.dat'); (* add bin file extension *) iSeq := iSeq + 1; 3: (* Creat file *) fbFileOpen.sPathName := CONCAT (sAccessPath, sFileName); fbFileOpen(sNetId:= sFileTargetNetId, (* Access target id *) sPathName:= , (* Access Path *) nMode:= FOPEN_MODEBINARY OR FOPEN_MODEWRITE, (* Binary Format & Write Mode & Overrite contents *) ePath:= PATH_GENERIC, bExecute:= TRUE, tTimeout:= DEFAULT_ADS_TIMEOUT, bBusy=> , bError=> , nErrId=> , hFile=> ); IF NOT(fbFileOpen.bBusy) AND NOT(fbFileOpen.bError) THEN fbFileOpen(bExecute:= FALSE); iSeq := iSeq + 1; ELSIF fbFileOpen.bError THEN fbFileOpen(bExecute:= FALSE); iExceptionSeq := iSeq; iSeq := 999; END_IF 4: (* Creat binary info header *) fbFileWrite(sNetId:= sFileTargetNetId, hFile:= fbFileOpen.hFile, pWriteBuff:= ADR(DatHeader), cbWriteLen:= SIZEOF(DatHeader), bExecute:= TRUE, tTimeout:= DEFAULT_ADS_TIMEOUT, bBusy=> , bError=> , nErrId=> , cbWrite=> ); IF NOT(fbFileWrite.bBusy) AND NOT(fbFileWrite.bError) THEN fbFileWrite(bExecute:= FALSE); iSeq := iSeq + 1; ELSIF fbFileWrite.bError THEN fbFileWrite(bExecute:= FALSE); iExceptionSeq := iSeq; iSeq := 999; END_IF 5: (* seek to cyclic record position *) fbFileSeek(sNetId:= sFileTargetNetId, hFile:= fbFileOpen.hFile, nSeekPos:= SIZEOF(DatHeader), (* Seek to record start position *) eOrigin:= SEEK_SET, bExecute:= , tTimeout:= DEFAULT_ADS_TIMEOUT, bBusy=> , bError=> , nErrId=> ); IF NOT(fbFileSeek.bBusy) AND NOT(fbFileSeek.bError) THEN fbFileSeek(bExecute:= FALSE); iSeq := 10; ELSIF fbFileSeek.bError THEN fbFileSeek(bExecute:= FALSE); iExceptionSeq := iSeq; iSeq := 999; END_IF 10: (* Check Data exist *) IF NOT(MAIN.fbBufferAccess.bFifoEmpty) THEN pRequestData^ := TRUE; (* request get data from buffer to DatAcqBlock *) iSeq := iSeq + 1; END_IF 11: fbFileWrite(sNetId:= sFileTargetNetId, hFile:= fbFileOpen.hFile, pWriteBuff:= ADR(DatAcqBlock), cbWriteLen:= SIZEOF(DatAcqBlock), bExecute:= TRUE, tTimeout:= DEFAULT_ADS_TIMEOUT, bBusy=> , bError=> , nErrId=> , cbWrite=> ); IF NOT(fbFileWrite.bBusy) AND NOT(fbFileWrite.bError) THEN fbFileWrite(bExecute:= FALSE); iSeq := iSeq + 1; ELSIF fbFileWrite.bError THEN fbFileWrite(bExecute:= FALSE); iExceptionSeq := iSeq; iSeq := 999; END_IF 12: (* Seek to next block *) fbFileSeek(sNetId:= sFileTargetNetId, hFile:= fbFileOpen.hFile, nSeekPos:= fbFileSeek.nSeekPos + SIZEOF(DatAcqBlock), (* Seek to record start position *) eOrigin:= SEEK_SET, bExecute:= , tTimeout:= DEFAULT_ADS_TIMEOUT, bBusy=> , bError=> , nErrId=> ); IF NOT(fbFileSeek.bBusy) AND NOT(fbFileSeek.bError) THEN fbFileSeek(bExecute:= FALSE); iSeq := iSeq + 1; ELSIF fbFileSeek.bError THEN fbFileSeek(bExecute:= FALSE); iExceptionSeq := iSeq; iSeq := 999; END_IF 13: (* Check if the record times & length reached *) nCurRecodeNo := nCurRecodeNo + 1; IF nCurRecodeNo >= nRecordAcqBlockPerFile THEN iSeq := 20; (* FileClose & creat New file *) ELSE iSeq := 10; (* GobBack do further content write *) END_IF 20: (* File Close *) fbFileClose(sNetId:= sFileTargetNetId, hFile:= fbFileOpen.hFile, bExecute:= TRUE, tTimeout:= DEFAULT_ADS_TIMEOUT, bBusy=> , bError=> , nErrId=> ); IF NOT(fbFileClose.bBusy) AND NOT(fbFileClose.bError) THEN fbFileClose(bExecute:= FALSE); iSeq := iSeq + 1; ELSIF fbFileSeek.bError THEN fbFileClose(bExecute:= FALSE); iExceptionSeq := iSeq; iSeq := 999; END_IF 21: (* Option call bin to txt file parser process *) pStartParser := ADR (PRG_Slow.fbTxtParser.bExecute); IF PRG_Slow.fbTxtParser.bBusy THEN (* Parser process to slower then cyclic acquisition *) nTxtParserLate := nTxtParserLate + 1; ELSE pPathPassThrough := ADR(PRG_Slow.fbTxtParser.sFilePathSource); pPathPassThrough^ := fbFileOpen.sPathName; pPathPassThrough := ADR(PRG_Slow.fbTxtParser.sFilePathDestination); pPathPassThrough^ := F_ReplaceByString(fbFileOpen.sPathName,'.dat' , '.csv'); pStartParser^ := TRUE; iSeq := 0; END_IF END_CASE ]]></ST> </Implementation> <LineIds Name="PRG_DatFileCreat"> <LineId Id="27" Count="0" /> <LineId Id="10" Count="0" /> <LineId Id="43" Count="0" /> <LineId Id="46" Count="0" /> <LineId Id="51" Count="0" /> <LineId Id="229" Count="0" /> <LineId Id="104" Count="1" /> <LineId Id="60" Count="0" /> <LineId Id="62" Count="0" /> <LineId Id="64" Count="4" /> <LineId Id="61" Count="0" /> <LineId Id="69" Count="0" /> <LineId Id="260" Count="0" /> <LineId Id="298" Count="0" /> <LineId Id="261" Count="0" /> <LineId Id="257" Count="0" /> <LineId Id="262" Count="0" /> <LineId Id="300" Count="1" /> <LineId Id="109" Count="0" /> <LineId Id="114" Count="0" /> <LineId Id="77" Count="0" /> <LineId Id="82" Count="0" /> <LineId Id="75" Count="0" /> <LineId Id="83" Count="2" /> <LineId Id="55" Count="0" /> <LineId Id="293" Count="0" /> <LineId Id="316" Count="0" /> <LineId Id="318" Count="6" /> <LineId Id="329" Count="0" /> <LineId Id="331" Count="0" /> <LineId Id="328" Count="0" /> <LineId Id="297" Count="0" /> <LineId Id="87" Count="0" /> <LineId Id="112" Count="0" /> <LineId Id="110" Count="0" /> <LineId Id="90" Count="8" /> <LineId Id="89" Count="0" /> <LineId Id="120" Count="1" /> <LineId Id="123" Count="0" /> <LineId Id="129" Count="0" /> <LineId Id="126" Count="2" /> <LineId Id="130" Count="0" /> <LineId Id="124" Count="0" /> <LineId Id="122" Count="0" /> <LineId Id="56" Count="0" /> <LineId Id="136" Count="0" /> <LineId Id="138" Count="7" /> <LineId Id="132" Count="0" /> <LineId Id="147" Count="0" /> <LineId Id="133" Count="0" /> <LineId Id="148" Count="4" /> <LineId Id="134" Count="0" /> <LineId Id="58" Count="0" /> <LineId Id="57" Count="0" /> <LineId Id="156" Count="0" /> <LineId Id="162" Count="6" /> <LineId Id="157" Count="0" /> <LineId Id="176" Count="0" /> <LineId Id="169" Count="6" /> <LineId Id="48" Count="0" /> <LineId Id="177" Count="0" /> <LineId Id="49" Count="0" /> <LineId Id="179" Count="0" /> <LineId Id="206" Count="0" /> <LineId Id="208" Count="0" /> <LineId Id="207" Count="0" /> <LineId Id="182" Count="0" /> <LineId Id="188" Count="17" /> <LineId Id="187" Count="0" /> <LineId Id="183" Count="0" /> <LineId Id="209" Count="16" /> <LineId Id="116" Count="1" /> <LineId Id="263" Count="0" /> <LineId Id="118" Count="0" /> <LineId Id="230" Count="0" /> <LineId Id="232" Count="0" /> <LineId Id="234" Count="0" /> <LineId Id="231" Count="0" /> <LineId Id="236" Count="0" /> <LineId Id="115" Count="0" /> <LineId Id="237" Count="0" /> <LineId Id="243" Count="0" /> <LineId Id="245" Count="4" /> <LineId Id="238" Count="0" /> <LineId Id="242" Count="0" /> <LineId Id="250" Count="6" /> <LineId Id="239" Count="1" /> <LineId Id="372" Count="0" /> <LineId Id="354" Count="0" /> <LineId Id="361" Count="0" /> <LineId Id="370" Count="0" /> <LineId Id="375" Count="1" /> <LineId Id="381" Count="0" /> <LineId Id="383" Count="1" /> <LineId Id="378" Count="0" /> <LineId Id="373" Count="1" /> <LineId Id="364" Count="0" /> <LineId Id="47" Count="0" /> <LineId Id="44" Count="0" /> </LineIds> </POU> </TcPlcObject> |