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.

How to improve program runing?


fi Aug 25, 2014 11:33 AM

Hi,

It seems that the CrBasic program I use takes too much time to run (skipped scan and records). Involving the impossibility to send data with the slowsequence.

It is possible to see with part of is too long?

Here is the programme:

'________________________________________________________________________________________________________________________________________________________________________________
SequentialMode
'_________________________________________________________________________________________________________________________________________________________________________________
'DECLARATION DES VARIABLES ET CONSTANTES DE TRAVAIL
'_________________________________________________________________________________________________________________________________________________________________________________

'----------Paramtre de la centrale-----------

'temperature au bornier
Public Temp
Units Temp = deg_C

'niveau de tension
Public Batt
Units Batt = V

'Information temporelle
Public rTime(9)


'----------Capteurs sismiques----------

Public Geophone_1 ,Geophone_2,Geophone_3, Geophone_4
Units Geophone_1 ,Geophone_2, Geophone_3, Geophone_4 = mV

'seuil ( pleine echelle = 20 000 mV)
Const GeoLim1 = 500.
Const GeoLim2 = 500.
Const GeoLim3 = 500.
Const GeoLim4 = 500
'----------pluviometre----------
Public Pluie
Public Pluie15
Alias Pluie15 = Cumul_Pluie_15min
Public Pluie5a, Pluie5b, Pluie5c
Dim PluieCum
'Seuil de pluie 15 min. pour declenchement l'alarme et photo en mm/ 15 min. et envoi d un SMS
Public SeuilPluie15 = 3 'mm/15min
'Calibration du pluvio constructeur
Const CalibrePluvio = 0.254
Units Pluie = mm

'----------capteur de hauteur d'eau----------
Public Hauteur
Units Hauteur=mm


'---------mode evenement----------
Public Even As Boolean
Public NbEven
'----------Photo/Video-----------
Public video As Boolean
Public photo As Boolean

'----------Information concernant l'envoie de donnees sur le server ftp
Const FTPServerAddress = ""
Const FTPUserID = ""
Const FTPPassword = ""

Public FTPSuccess As Boolean = False, LastFileName As String * 32
Dim SendFTP As Boolean = False,OutStat As Boolean = False, DestinationFilename As String * 32

'_________________________________________________________________________________________________________________________________________________________________________________
'DECLARATION TABLES DE TRAVAIL ET DE SAUVEGARDE
'_________________________________________________________________________________________________________________________________________________________________________________

'----------Journal de bord----------


DataTable (Journal_Roubion,1,10000)
'Enregistrement toutes les 5 minutes; les valeurs manquees en 0
DataInterval(0,5,Min,0)
'Enregistrement sur la carte memoire
CardOut (0, -1)
TableFile("CRD:Journal_Roubion",8,2,0,10,Min,OutStat,LastFileName) 'creation d'un fichier destine au serveur ftp
'Pluie cumulee / 5min.
Totalize (1,Pluie,FP2,0)
Sample (1,Pluie15, FP2)
Maximum (1,Geophone_1,FP2,False,False)
Maximum (1,Geophone_2,FP2,False,False)
Maximum (1,Geophone_3,FP2,False,False)
Maximum (1,Geophone_4,FP2,False,False)
Sample(1,Temp,FP2)
Sample(1,Batt,FP2)
Sample (1,Hauteur,FP2)
Sample (1,NbEven,FP2)
Sample (1,Even,FP2)


EndTable

'----------Mode evenement----------
'si le mode evenement est activee ( Even=1) la sauvegarde a 2Hz commence en concervant la minute de donne precedent le flag ( et inversement pour l'arret)

DataTable (Evenement_Roubion,1,50000)
DataEvent (120,Even=true,Even=false,120)
DataInterval (0,500,mSec,0)
CardOut (0 ,-1)
Sample (1,Geophone_1,FP2)
Sample (1,Geophone_2,FP2)
Sample (1,Geophone_3,FP2)
Sample (1,Geophone_4,FP2)
Sample (1,Hauteur,FP2)
EndTable


'===================================================================================
'SUBROUTINES
'Initialisation de depart
Sub Initialisation (APluieCum ,APluie15 , APluie5b, APluie5c,ANbEven)
'Cumul des pluies
APluieCum = 0
'Cumul des pluies sur 15 min.
APluie15 = 0
APluie5b = 0
APluie5c = 0
'Nombre d'evenements
ANbEven=0

EndSub

'Cumul de la pluie sur 15 minutes pour le test d arret de la video et photo
Sub CumulPluie (APluieCum, APluie, APluie15, APluie5a, APluie5b, APluie5c)
APluieCum = APluieCum + APluie
If TimeIntoInterval(0,5,Min) Then
APluie5a = APluieCum
APluieCum = 0
APluie15 = APluie5a + APluie5b + APluie5c
APluie5c = APluie5b
APluie5b = APluie5a
EndIf
EndSub

'----------Subroutine de test du mode evenement ( Even=1)----------

Sub TestEven (AGeophone_1,AGeophone_2,AGeophone_3,AGeolim1,AGeolim2, AGeolim3, APluie15, ASeuilPluie15,AEven,ANbEven)


If (APluie15>ASeuilPluie15) OR ((APluie15>0) AND ((AGeophone_1> AGeolim1)OR (AGeophone_2>AGeolim2) OR (AGeophone_3>AGeolim3) )) Then
AEven=true

EndIf

If (TimeIntoInterval (0,5,Min)) AND (AGeophone_1<AGeolim2) AND (AGeophone_2<AGeolim2) AND (AGeophone_3<AGeolim3) Then
AEven=false
ANbEven=ANbEven+1
EndIf

EndSub


'----------Subroutine de la prise de video en mode evenement et de prise de la photo journaliere----------

Sub PhotoVideo (AEven, APhoto, Avideo, arTime)
APhoto=0
Avideo=0

If (AEven = 0) AND TimeIntoInterval(12,24,Hr) Then
APhoto = 1
PortSet (2,1 )
Delay (1,200,mSec)
PortSet (2,0)
EndIf

If (AEven=1) AND (ArTime>=4) AND (ArTime<=19) Then
Avideo=1
PortSet (3,1 )
Delay (1,200,mSec)
PortSet (3,0)
EndIf

EndSub

'=====================================================================================
'Programme principal
BeginProg

'Reset des pulses en relancant le programme
PulseCountReset

'Chargement des parametres d initialisation
Call Initialisation (PluieCum ,Pluie15 , Pluie5b, Pluie5c,NbEven)

'Scrutation toutes les 500 msecondes
Scan (500,mSec,0,0)

'----------Verificatioin de l'etat general de la centrale-----------
'Alume une led toutes les 10s pour attester du bon fonctionnement de la centrale
PortSet(8,0)
If TimeIntoInterval(0,10,Sec)
PortSet(8,1)
EndIf

Battery (Batt)
PanelTemp (Temp,250)
RealTime (rTime)

'----------Mesure des voies pours les differents capteurs----------

'pluviometre
PulseCount(Pluie,1,1,2,0,CalibrePluvio,0)

'geophones
VoltDiff (Geophone_1,1,mV2500,1,True,0,0,1,0)
VoltDiff (Geophone_2,1,mV2500,2,True,0,0,1,0)
VoltDiff (Geophone_3,1,mV2500,3,True,0,0,1,0)
VoltDiff (Geophone_3,1,mV2500,3,True,0,0,1,0)
'capteur de hauteur
VoltDiff (Hauteur,1,mV2500,4,True ,0,250,1.0,0)


'----------Appel de la suroutine du calcul de pluie cumulee sur 15min----------
Call CumulPluie (PluieCum, Pluie, Pluie15,Pluie5a, Pluie5b, Pluie5c)

'----------Appel de la suroutine du mode evenement et de prise video----------
Call TestEven (Geophone_1,Geophone_2,Geophone_3,GeoLim1,GeoLim2, GeoLim3, Pluie15, SeuilPluie15,Even,NbEven)
Call PhotoVideo (Even, photo, video, rTime)

'----------Appel des tables de donnees----------
CallTable Journal_Roubion
CallTable Evenement_Roubion

If OutStat Then
SendFTP = True
EndIf

NextScan

'---------- Utilisation d'un scan plus lent et independent permettant un envoie de donnees transparent pour le reste du soft----------


SlowSequence

Do
If SendFTP Then

SW12 (1 )
Delay (1,30,Sec)

DestinationFilename = Right(LastFileName,Len(LastFileName)-4)
FTPSuccess = FTPClient(FTPServerAddress, FTPUserID, FTPPassword, LastFileName,"/JournalRoubion/" & DestinationFilename, 2)
SendFTP = False

'Sequence pour eteindre proprement le modem
' SerialOpen (ComRS232,115200,0,0,100)
'SerialOut (ComRS232,"+++","OK"+CHR(13),1,150)
'SerialOut (ComRS232,"AT+CFUN=0"+CHR(13),"OK"+CHR(13),1,300)
'Delay to allow deregistration
'Delay (0,2,sec)
'SerialClose(ComRS232)

SW12 (0)

EndIf

Loop

EndProg


EndProg


Dana Aug 25, 2014 04:47 PM

The program is compiling in SequentialMode (even if you removed your forced SequentialMode at the top of the program), rather than the datalogger running its measurement tasks and processing tasks concurrently (pipelinemode). Given this and the 30 second delay in the SlowSequence, you will certainly see skipped scans given the Scan interval of the main program.

Measurement and control instructions within subroutines or called conditionally will force the program to compile in sequential mode. Your program has PortSet and other control instructions in both a Subroutine and an If statement. There are some ways to program around this in some instances, such as taking the PortSet out of the conditional statement and setting a variable that controls the port instead, while the PortSet itself is in the main body of the program. Or, use WriteIO. Note, however, that there are ramifications to both of these approaches, since the control will be handled by the Processing task. Processing tasks can lag behind several scans when running in Pipeline mode.

Dana W.

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