Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

FileRename with Multiple TableFile and a rTime(X) marker


Benjamin.vial Apr 16, 2019 02:31 PM

Hi,

I can't succeed to make a program doing a relatively simple thing :

Record TableFile every X time (in real life 24 hours, in my test 1 minute) and make a Table File, then rename this Table file with a specific format that contain a time maker.

Here is my code : 

'CR1000

'Declare Variables and Units
Const QL = 90 'queue buffer size - 1 fichier / jour donc 90 jours de buffer
Public Outstat As Boolean
Const LoggerID="AVP" 

Public rTime(9)
Alias rTime(1) = Year 'assign the alias Year to rTime(1)
Alias rTime(9) = Day_of_Year 'assign the alias Day_of_Year to rTime(9)

Public BattV
Pubbyelic PTemp_C
Public T107_C_1
Public T107_C_2
Public T107_C_3
Public T107_C_4
Public T107_C_5
Public T107_C_6
Public T107_C_7
Public SR50A(2)
Public TCDT
Public DBTCDT
Public BP_kPa
Public Rain_mm
Public WS_ms
Public WindDir
Public LCount
Public DiffV(9)
Public Mult(9)={1,1,1,1,1,1,1,1,1}
Public Offs(9)={0,0,0,0,0,0,0,0,0}

Alias SR50A(1)=DT
Alias SR50A(2)=Q

Units BattV=Volts
Units PTemp_C=Deg C
Units T107_C_1=Deg C
Units T107_C_2=Deg C
Units T107_C_3=Deg C
Units T107_C_4=Deg C
Units T107_C_5=Deg C
Units T107_C_6=Deg C
Units T107_C_7=Deg C
Units BP_kPa=kPa
Units Rain_mm=mm
Units WS_ms=meters/second
Units WindDir=degrees
Units DiffV=mV

'Define Data Tables
DataTable(meteo,True,-1)
  RealTime( rTime )
	DataInterval(0,1,Min,10)
	Average(1,PTemp_C,FP2,False)
	Average(1,T107_C_1,FP2,False)
	Sample(1,DT,FP2)
	Sample(1,Q,FP2)
	Sample(1,TCDT,FP2)
	Sample(1,DBTCDT,FP2)
	Average(1,BP_kPa,FP2,False)
	Totalize(1,Rain_mm,FP2,False)
	Average(1,WS_ms,FP2,False)
	Maximum(1,WS_ms,FP2,False,True)
	WindVector(1,WS_ms,WindDir,FP2,False,10,0,0)
	FieldNames("WS_ms_S_WVT,WindDir_D1_WVT,WindDir_SD1_WVT")
  TableFile ("USR:meteo",8,-1,0,1,Min,Outstat,0)
  FileRename("USR:meteo0.dat","USR:"+Year+"_"+Day_of_Year+"_"+rTime(4)+"_"+rTime(5)+"_meteo_"+LoggerID+".dat")
EndTable

DataTable(hydro,True,-1)
  'RealTime( rTime )
	DataInterval(0,1,Min,10)
	Minimum(1,BattV,FP2,False,False)
	Average(1,T107_C_1,FP2,False)
	Average(1,T107_C_2,FP2,False)
	Average(1,T107_C_3,FP2,False)
	Average(1,T107_C_4,FP2,False)
	Average(1,T107_C_5,FP2,False)
	Average(1,T107_C_6,FP2,False)
	Average(1,T107_C_7,FP2,False)
	Average(1,DiffV(1),FP2,False)
	Average(1,DiffV(2),FP2,False)
	Average(1,DiffV(3),FP2,False)
	Average(1,DiffV(4),FP2,False)
	Average(1,DiffV(5),FP2,False)
	Average(1,DiffV(6),FP2,False)
	Average(1,DiffV(7),FP2,False)
	Average(1,DiffV(8),FP2,False)
	Average(1,DiffV(9),FP2,False)
  TableFile ("USR:hydro",8,-1,0,1,Min,Outstat,0)
  FileRename("USR:hydro0.dat","USR:"+Year+"_"+Day_of_Year+"_"+rTime(4)+"_"+rTime(5)+"_hydro_"+LoggerID+".dat")
EndTable

DataTable(soh,True,-1)
  'RealTime( rTime )
	DataInterval(0,1,Min,10)
	Average(1,BattV,FP2,False)
	Maximum(1,BattV,FP2,False,False)
	Minimum(1,BattV,FP2,False,False)
	Average(1,PTemp_C,FP2,False)
	Maximum(1,PTemp_C,FP2,False,True)
  TableFile ("USR:soh",8,-1,0,1,Min,Outstat,0)
  FileRename("USR:soh0.dat","USR:"+Year+"_"+Day_of_Year+"_"+rTime(4)+"_"+rTime(5)+"_soh_"+LoggerID+".dat")
EndTable

'Main Program
BeginProg
  SetStatus("USRDriveSize",1000000) 'pour CR1000 uniquement
	'Main Scan
	Scan(10,Sec,1,0)
  		'Default Datalogger Battery Voltage measurement 'BattV'
		Battery(BattV)
		'Default Wiring Panel Temperature measurement 'PTemp_C'
		PanelTemp(PTemp_C,_60Hz)
		'107 Temperature Probe (CSL) measurement 'T107_C_1'
		Therm107(T107_C_1,1,1,1,0,_60Hz,1,0)
		'107 Temperature Probe (CSL) measurement 'T107_C_2'
		Therm107(T107_C_2,1,2,1,0,_60Hz,1,0)
		'107 Temperature Probe (CSL) measurement 'T107_C_3'
		Therm107(T107_C_3,1,3,1,0,_60Hz,1,0)
		'107 Temperature Probe (CSL) measurement 'T107_C_4'
		Therm107(T107_C_4,1,4,1,0,_60Hz,1,0)
		'107 Temperature Probe (CSL) measurement 'T107_C_5'
		Therm107(T107_C_5,1,5,2,0,_60Hz,1,0)
		'107 Temperature Probe (CSL) measurement 'T107_C_6'
		Therm107(T107_C_6,1,6,2,0,_60Hz,1,0)
		'107 Temperature Probe (CSL) measurement 'T107_C_7'
		Therm107(T107_C_7,1,7,2,0,_60Hz,1,0)
		'SR50A Sonic Ranging Sensor (SDI-12 Output) measurements 'DT', 'Q', 'TCDT', and 'DBTCDT'
		SDI12Recorder(SR50A(),7,"0","M1!",1,0)
		TCDT=DT*SQR((PTemp_C+273.15)/273.15)
		DBTCDT=1.60-TCDT
		'CS106 Barometric Pressure Sensor measurement 'BP_kPa'
		If TimeIntoInterval(59,60,Min) Then PortSet(3,1)
		If TimeIntoInterval(0,60,Min) Then
			VoltSE(BP_kPa,1,mV2500,10,1,0,_60Hz,0.240,591.7104)
			BP_kPa=BP_kPa*0.1
			PortSet(3,0)
		EndIf
		'52202/52203 Rain Gage (CSL) measurement 'Rain_mm'
		PulseCount(Rain_mm,1,1,2,0,0.1,0)
		'05103 Wind Speed & Direction Sensor (CSL) measurements 'WS_ms' and 'WindDir'
		PulseCount(WS_ms,1,2,1,1,0.098,0)
		BrHalf(WindDir,1,mV2500,11,2,1,2500,True,0,_60Hz,355,0)
		If WindDir>=360 Or WindDir<0 Then WindDir=0
		'Turn AM16/32 Multiplexer On
		PortSet(2,1)
		Delay(0,150,mSec)
		LCount=1
		SubScan(0,uSec,9)
			'Switch to next AM16/32 Multiplexer channel
			PulsePort(1,10000)
			'Generic Differential Voltage measurements 'DiffV()' on the AM16/32 Multiplexer
			VoltDiff(DiffV(LCount),1,mV250,7,True,0,_60Hz,Mult(LCount),Offs(LCount))
			LCount=LCount+1
		NextSubScan
		'Turn AM16/32 Multiplexer Off
		PortSet(2,0)
		Delay(0,150,mSec)
		'Call Data Tables and Store Data
		CallTable meteo
		CallTable hydro
		CallTable soh
	NextScan
	SlowSequence
	  Scan (10,Sec,3,0)
	  NetworkTimeProtocol ("51.255.197.148",0,100) 'ntp.pool...
    RealTime(rTime)
'    Call Rename
  EndSequence
  NextScan 
EndProg

 

I tried to put the "FileRename" function in a sub sequence, a slowsequence in the main, didn't works neither.

Something I miss ?

Thanks,

bye.


JDavis Apr 17, 2019 03:50 PM

Use the OutStat within your scan to trigger when to rename the file. Use a string variable in TableFile for the last file name. Use that as the old file name in FileRename.

 The code should go in your scan.

  If OutStat Then
      FileRename(LastFileName,"USR:"+Year+"_"+Day_of_Year+"_"+rTime(4)+"_"+rTime(5)+"_soh_"+LoggerID+".dat")
    EndIf

 


Benjamin.vial Apr 18, 2019 07:38 AM

Hi,

yes, perfect, it's working now.

I make 3 lastFileName (1, 2 and 3) and 3 Outstat (same) variables, for my 3 tablefile, I m' not sure that was the better way but at least, it works !

Thanks JDavis.


Benjamin.vial Nov 12, 2019 02:09 PM

Hi,

well, I have take back this program for another campbell : CR310.

It's work but only for the fisrt file created. After the files just get a number to increment (file2.dat, file3.dat, etc.).

Here is my code :

 

'Declare Variables and Units
Public BattV
Public PTemp_C
Public HalfBr

Const LoggerID="HAR2"
Public Outstat1 As Boolean
Public Outstat2 As Boolean

Public LastFileName1 As String * 20
Public LastFileName2 As String * 20


Public rTime(9)

Units BattV=Volts
Units PTemp_C=Deg C
Units HalfBr=mV/mV

'Define Data Tables
DataTable(extenso,True,-1)
	DataInterval(0,1,Min,10)
	Average(1,BattV,FP2,False)
	Average(1,HalfBr,FP2,False)
	StdDev(1,HalfBr,FP2,False)
	TableFile ("CPU:exten",8,-1,0,10,min,Outstat1,LastFileName1)
EndTable

DataTable(soh,True,-1)
	DataInterval(0,1,Min,10)
	Minimum(1,BattV,FP2,False,False)
	Minimum(1,PTemp_C,FP2,False,False)
	TableFile ("CPU:soh",8,-1,0,10,min,Outstat2,LastFileName2)
EndTable

'Main Program
BeginProg
	'Main Scan
	Scan(10,Sec,1,0)
		'Default CR300 Datalogger Battery Voltage measurement 'BattV'
		Battery(BattV)
		'Default CR300 Datalogger Processor Temperature measurement 'PTemp_C'
		PanelTemp(PTemp_C,4000)
		'Generic Half Bridge measurements 'HalfBr'
		BrHalf(HalfBr,1,mV2500,1,VX1,1,2500,False,500,50,1,0)
		'Call Data Tables and Store Data
		CallTable extenso
		CallTable soh
		If Outstat1 Then
        FileRename(LastFileName1,"CPU:"+rTime(1)+"_"+rTime(9)+"_"+rTime(4)+"_"+rTime(5)+"_extenso_"+LoggerID+".dat")
      EndIf
    If Outstat2 Then
        FileRename(LastFileName2,"CPU:"+rTime(1)+"_"+rTime(9)+"_"+rTime(4)+"_"+rTime(5)+"_soh_"+LoggerID+".dat")
      EndIf
	NextScan
	SlowSequence
	  Scan (10,Sec,3,0)
	  NetworkTimeProtocol ("51.255.197.148",0,100) 'ntp.pool...
	  RealTime(rTime)
  EndSequence
	NextScan
EndProg

 

Where am I wrong ?

Again, I have put a record every 10 minutes, but on the field it will be 24 Hr.

Bye.


Benjamin.vial Nov 13, 2019 01:37 PM

Little add :

If I delete data file with Device Configuration Utility in the CR3100, the next file is well created, and the next one, wrong.

I can't figure what's wrong in the prog.


Benjamin.vial Nov 13, 2019 01:58 PM

Well, I have find. Very sneaky, it's three line before the end's program : I close the slowsequence before nextscan.

Just to invert this two lines, and it's work.

Sometimes ...


andreadale Sep 23, 2021 09:14 AM

hello, there is any way to send the renamed file via mail as attachment??

Log in or register to post/reply in the forum.