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.

CR1000 program not writing file to USR drive


joshdr83 Jul 10, 2012 04:40 PM

Hi

In some iteration of this program, it has stopped writing files to the USR drive that can be either pushed or pulled via FTP - I can't seem to figure out what it the problem. The program is a bit long, sorry!

Any help is appreciated!

Thanks!

---------------------------------------------------------

'CR1000

'\\\\\\\\\\\\\\\\\\\\\\\\ Declare Variables and Units ///////////////////////////
Public BattV
Public GHR
Public Diffuse
Public DIR
Public UV
Public PTemp_C
Public box_temp

'FOR PIR
Public PIR_mV
Public Case_Res
Public ConstA
Public ConstB
Public ConstC
Public Ln_Res
Public bLn_res
Public Ln_res2
Public Ln_res3
Public case_temp
Public Power4
Public PIR_Bterm
Public PIR_Aterm
Public PIR_Watt

'Define public variables - these are temporary memory locations with names that can be accessed by the program
Public Outstat As Boolean, Sendit As Boolean, SentOK As Boolean, tries 'These variables control the ftp process
Public LastFileName As String * 30 'This is a variable, defined as a string, that will store the name of the last file created by the TableFile instruction
Public Newfilename As String *50 'holds the timestamped destination filename

'Define constants - these are values with names that can be accessed by the program, but cannot be changed
Const ServerIP = "no.IP" 'This is the address of the FTP server that you want to send files to
Const User = "junk" 'This is the user name needed to login to the FTP server
Const Password = "junk" 'This is the password needed to login to the FTP server
Const DestPath = "no/dir" 'This is the destination directory where the FTP'ed file will be saved on the FTP server

Units BattV=Volts
Units GHR=mV
Units Diffuse=mV
Units DIR=mV
Units UV=mV
Units PTemp_C=Deg C
Units box_temp=Deg C


'Define Data Tables
DataTable(Table1,True,-1)
DataInterval(0,1,Min,10)
'Every day at 2 am write a file of the last 24 hours data
TableFile ("USR:Onemin",8,-1,2,24,Hr,Outstat,LastFileName)
Average(1,BattV,FP2,False)
Average(1,GHR,FP2,False)
Average(1,Diffuse,FP2,False)
Average(1,DIR,FP2,False)
Average(1,UV,FP2,False)
Average(1,PTemp_C,FP2,False)
Average(1,box_temp,FP2,False)
Average(1, PIR_Watt, FP2, False)
EndTable

'\\\\\\\\\\\\\\\\\\\\\\\\\ SUBROUTINES //////////////////////////

Sub Subroutine1
' Equation to convert YSI 10 K thermistor resistance to temperature
' in degrees K
' 1/T = a + b(LnR) + c(LnR)^3
' Coefficients used in equation above
' a = 0.0010295 = ConstA
' b = 0.0002391 = ConstB
' c = 1.568E-7 = ConstC
' Calculate resistance from P5 instruction (Table 1, line 2)
Case_Res = 1000*(Case_Res/(1.0-Case_Res))
' Load constants a, b and c to input locations
' *** A term (From instruction P30 parameter 3)
ConstA = 0.0010295
ConstB = 0.0002391
ConstC = 1.568E-7
' *** Natural log of resistance (From instruction P40 parameter 2)
Ln_Res = LOG(Case_Res)
' Multiply constant B with Natural log of resistance
' Store result in "B term, bLn_res?
' *** B term (From instruction P36 parameter 3)
bLn_res = ConstB * Ln_Res
' Square natural log of resistance
' Natural log of resistance squared (From instruction P36 parameter 3)
Ln_res2 = Ln_Res * Ln_Res
' Cube natural log of resistance
' Natural log of resistance cubed (From instruction P36 parameter 3)
Ln_res3 = Ln_Res * Ln_res2
' Multiply constant C with natural log of resistance raised to the third power
' *** C term (From instruction P36 parameter 3)
Ln_res3 = ConstC * Ln_res3
' Add A term to B term natural log of resistance, store in location
' case_temp
case_temp = ConstA + bLn_res
' Add C term to A and B term, store in location case_temp
case_temp = case_temp + Ln_res3
' Kelvin
' *** Temp in degrees K (From instruction P42 parameter 2)
case_temp = 1 / case_temp
EndSub

Sub Subroutine2
' Apply case thermistor correction to PIR thermopile output
' Correction is PIR output in watts per meter squared plus
' 5.669E -8 multiplied by the case temperature raised to the fourth power.
' Load number 4 into input location Power4
Power4 = 4
' Raise temperature to the fourth power
case_temp = case_temp ^ Power4
' Load 5.669E -8 into PIR_Bterm
PIR_Bterm = 5.669E-8
' Multiply 5.669E -8 by Temp K raised to the fourth
' This is the PIR B term
PIR_Bterm = PIR_Bterm * case_temp
PIR_Watt = PIR_Aterm + PIR_Bterm
EndSub


'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Main Program ///////////////////////////////////
BeginProg
SetStatus("UsrDriveSize","100000") 'Sets the USR drive size to 100k
Scan(1,Sec,1,0)
'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Generic Differential Voltage measurements GHR
VoltDiff(GHR,1,mV25,1,True,0,_60Hz,109.769,0)
'Generic Differential Voltage measurements Diffuse
VoltDiff(Diffuse,1,mV25,2,True,0,_60Hz,110.011,0)
'Generic Differential Voltage measurements Diffuse
VoltDiff(DIR,1,mV25,3,True,0,_60Hz,143.062,0)
'Take TUVR voltage difference and multiply by 5.848
VoltDiff(UV,1,mV250,4,True,0,_60Hz,5.848,0)
'Wiring Panel Temperature measurement PTemp_C
PanelTemp(PTemp_C,_60Hz)
'Type T (copper-constantan) Thermocouple measurements box_temp
TCDiff(box_temp,1,mV2_5C,5,TypeT,PTemp_C,True,0,_60Hz,1,0)
' Measure PIR thermopile
VoltDiff(PIR_mV, 1, mV2_5, 6, True, 0, 250, 1, 0)
BrHalf(Case_Res, 1, mV2500, 13, Vx1, 1, 2500, True, 0, 250, 1, 0)
' Apply eppley calibration to thermopile output
PIR_Aterm = PIR_mV * 263.158
' Call Subroutine 1, used to calculate case temperature
Subroutine1
' Call Subroutine 2, Used to correct thermopile output
Subroutine2
'Call Data Tables and Store Data
CallTable(Table1)

'The following line sets a second variable the code in the slow sequence can monitor
'Checking Outstat is risky as it will get reset at the next run of the main scan
If Outstat Then
Sendit = true
tries=0
Newfilename = DestPath & " " & Public.TimeStamp(4,0) 'A quick way of generating a timestamp
Newfilename=Replace(Newfilename,":","") 'Get rid of the colons - not allowed in filenames
Newfilename=Newfilename &".dat" 'add a fixed suffix
EndIf
NextScan


---------------------------------------------------------


GaryTRoberts Jul 10, 2012 09:05 PM

Just a couple of questions.
One, is your USR: drive full? TableFile can't write to a "drive" that is full. If the USR: space shows full but does not list any files, format it to get your space back.
What value is showing in OutStat?

* Last updated by: GaryTRoberts on 7/10/2012 @ 3:06 PM *


joshdr83 Jul 10, 2012 09:21 PM

The USR drive had 100kb free, I reformatted it with File Control. OutStat is false, that explains no file writing. I never really understood what OutStat was/did. I admit I got help writing the program.


joshdr83 Jul 10, 2012 09:31 PM

The problem seemed to start when I included the measurement (PIR) that required the subroutines btw.


GaryTRoberts Jul 10, 2012 09:46 PM

Just working through your code here on a CR1000 with OS 25 on it, I am getting an error that your USR drive might not be big enough.

Change the line:
SetStatus("UsrDriveSize","100000")
to
SetStatus("UsrDriveSize","200000")
and lets see what happens.


joshdr83 Jul 10, 2012 09:51 PM

Ok, did it. OutStat still reading false. I have OS 24, should I have 25?


joshdr83 Jul 10, 2012 09:54 PM

If so, where is it? All I see on the CS website is for OS 24.

I was told that with the next CR1000 OS release that the USR directory would be unnecessary as what I want to do is send a file everyday of the past 24 hours worth of data. I have a CR1000 and a NL120 btw.


GaryTRoberts Jul 10, 2012 10:01 PM

OS 24 should be good. We always recommend updating to the latest OS. 25 should be posted to the website later today.

OutStat will stay False until after 2AM tomorrow morning when the logger writes the file. Then it will update to True.

Lets let it run for a day. It should now write the file at 2 AM as programmed (with the USR drive space increase).

Let me know tomorrow morning if you don't see a file.


aps Jul 11, 2012 09:39 AM

The new operating systems are on the website now along with the revision history here: www.campbellsci.com/downloads
If you download and run the executables they will update your CRBasic editor help files too.

* Last updated by: aps on 7/14/2012 @ 2:20 AM *


joshdr83 Jul 11, 2012 03:07 PM

Gary - It did write the file, thanks for the help!

I think I will try the new route to avoid this extra step. I will let you know if I have trouble getting it to work, Thanks!

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