发表于:2006-03-16 17:52:00
14楼
大虾帮忙看一下这段程序,帮忙分析一下结构,我是菜鸟
。多谢了。
Gather_00_log:
FUNCTION
Gather_00_log()
INT Gather_00_Rand;
M_00_GL_FLAG = 0;
M_00_MAIN_RAND = Rand(32767);
WHILE M_00_MAIN_RAND = 0 DO
M_00_MAIN_RAND = Rand(32767); END
TagWrite("S_00_MAIN_RAND",M_00_MAIN_RAND); Sleep(4);
Gather_00_Rand = TagRead("S_00_MAIN_RAND");
M_00_MAIN_CON = TagRead("S_00_MAIN_CON");
IF Gather_00_Rand = M_00_MAIN_RAND AND M_00_MAIN_CON = 3 THEN
TagWrite("S_00_MAIN_CON",2); Sleep(35);
WHILE BIAOZHI = 1 DO
Sleep(5);
END(如果BIAOZHI = 1说明有其它井怎在传输采集好的功图文件,所以一直等待到BIAOZHI = 0为止)
Tran_00_File();
CONVERT_00_File();
END
END
FUNCTION
Tran_00_File()
STRING Clear_Str;
BIAOZHI = 1;
IF D_COMPUTER_STIME = 1 THEN
Clear_Str = "^"c:\SIXNET Tools\Programs\sxlogview.exe^" ^"E:\工程文件\sixnet\S19_1900.6PJ^" -clear -Device=Ethernet -IPaddr=141.0.0.17 -Transfer=^"Trans_S_1900^"";
ELSE
Clear_Str = "^"c:\SIXNET Tools\Programs\sxlogview.exe^" ^"E:\工程文件\sixnet\S19_1900.6PJ^" -clear -Device=Ethernet -IPaddr=141.0.0.17 -Transfer=^"Trans_C_1900^"";
END
Exec(Clear_Str,6);
Sleep(120);
TagWrite("S_00_MAIN_RAND",-1);
TagWrite("S_00_MAIN_CON",0);
BIAOZHI = 0;
END
FUNCTION
CONVERT_00_File()STRING Log_File_Name,Read_File_Str,Start_Data,Start_Time,Mid_Data,Mid_Time,Write_File_Str;
INT HFile_Sxstatus,RECORD_SIZE,End_Flag,Start_Ms,Mid_Ms,Start_Time_Ms,Read_Str_length,
Mid_Time_Ms,Period_Sec,i_for;
REAL k_00,w_00,t_00,Mid_WeiYi_00;
IF D_COMPUTER_STIME = 1 THEN
Log_File_Name = "D:\DATA\LOG\LOG_1900_S.csv";
ELSE
Log_File_Name = "D:\DATA\LOG\LOG_1900_C.csv";
END
ErrSet(1);
HFile_Sxstatus = FileOpen(Log_File_Name,"r");
IF HFile_Sxstatus <> -1 THEN
Read_File_Str = FileReadLn(HFile_Sxstatus);
Read_File_Str = FileReadLn(HFile_Sxstatus);
Read_File_Str = FileReadLn(HFile_Sxstatus);
Read_File_Str = FileReadLn(HFile_Sxstatus);
End_Flag = FileEOF(HFile_Sxstatus);
RECORD_SIZE = 1;
Start_Data = StrLeft(Read_File_Str,10);
Start_Time = StrMid(Read_File_Str,11,8);
Start_Ms = StrToInt(StrMid(Read_File_Str,20,3));
Start_Time_Ms = StrToDate(StrMid(Start_Data,0,4)+"-"+StrMid(Start_Data,5,2)+"-"+StrMid(Start_Data,8,2)) + StrToTime(Start_Time);
Start_Time_Ms = Start_Time_Ms * 1000 + Start_Ms;
DL_TIME_ARRAY_00[0] = Start_Time_Ms;
Read_Str_length = StrSearch(20,Read_File_Str,",");
PT_ZAI_ARRAY_00[0] = StrToReal(StrMid(Read_File_Str,Read_Str_length + 1,5))*150/32767;
WHILE End_Flag <> 1 DO
Read_File_Str = FileReadLn(HFile_Sxstatus);
End_Flag = FileEOF(HFile_Sxstatus);
Mid_Data = StrLeft(Read_File_Str,10);
Mid_Time = StrMid(Read_File_Str,11,8);
Mid_Ms = StrToInt(StrMid(Read_File_Str,20,3));
Mid_Time_Ms = StrToDate(StrMid(Mid_Data,0,4)+"-"+StrMid(Mid_Data,5,2)+"-"+StrMid(Mid_Data,8,2)) + StrToTime(Mid_Time);
Mid_Time_Ms = Mid_Time_Ms * 1000 + Mid_Ms;
IF Mid_Time_Ms - Start_Time_Ms > 60000 THEN
RECORD_SIZE = 0;
Start_Time_Ms = Mid_Time_Ms;
Start_Data = Mid_Data;
Start_Time = Mid_Time;
END
DL_TIME_ARRAY_00[RECORD_SIZE] = Mid_Time_Ms;
Read_Str_length = StrSearch(20,Read_File_Str,",");
PT_ZAI_ARRAY_00[RECORD_SIZE] = StrToReal(StrMid(Read_File_Str,Read_Str_length + 1,5))*150/32767;
IF End_Flag = 1 THEN
Period_Sec = Mid_Time_Ms - Start_Time_Ms;
END
RECORD_SIZE = RECORD_SIZE + 1;
END
FileClose(HFile_Sxstatus);
ErrSet(0);
END
Log_File_Name = "D:\DATA\LOG_1900\" + StrMid(Start_Data,0,4) + "\LOG_1900 " + StrMid(Start_Data,0,4) + "-" + StrMid(Start_Data,5,2)
+ "-" + StrMid(Start_Data,8,2) + " " + StrLeft(Start_Time,2) + "h" + StrMid(Start_Time,3,2) + "m.csv";
ErrSet(1);
HFile_Sxstatus = FileOpen(Log_File_Name,"A");
FileClose(HFile_Sxstatus);
HFile_Sxstatus = FileOpen(Log_File_Name,"W");
FileWriteLn(HFile_Sxstatus,"ms of Period:");
FileWriteLn(HFile_Sxstatus,IntToStr(Period_Sec));
FileWriteLn(HFile_Sxstatus,"Size of Record:");
FileWriteLn(HFile_Sxstatus,IntToStr(RECORD_SIZE));
FileWriteLn(HFile_Sxstatus,"WeiYi,PT_ZAI");
FileWriteLn(HFile_Sxstatus,RealToStr(D_00_CC,5,3) + "," + RealToStr(PT_ZAI_ARRAY_00[0],5,2));
k_00 = D_00_QB/D_00_LG;
w_00 = (2*Pi())/Period_Sec;
FOR i_for = 1 TO RECORD_SIZE - 1 DO
t_00 = DL_TIME_ARRAY_00[i_for] - Start_Time_Ms;
Mid_WeiYi_00 = (D_00_CC/2)*(1+Cos(w_00*t_00)-(1/k_00)*(1-Sqrt(1-Pow(k_00,2)*Pow(Sin(w_00*t_00),2))));
FileWriteLn(HFile_Sxstatus,RealToStr(Mid_WeiYi_00,5,3) + "," + RealToStr(PT_ZAI_ARRAY_00[i_for],5,2));
END
FileClose(HFile_Sxstatus);
ErrSet(0);
END