Can i put a delay in my script

i am using a history log i found on here and need to have some sort of a delay in the script.
it executes to fast and the tag does not refresh in the time that it logs the file.

WRITE_DI1:

DIStatus$ = “” //REM - Because I will be saying open/closed instead of 0/1 I need a string to track this.
IF(DI_1_MEM@ = 0) THEN
DIStatus$ = “DGITAL INPUT OFF”
ELSE
DIStatus$ = “DIGITAL INPUT ON”
ENDIF
//REM - Now below we will verify if the file exists on first cycle. If it doesn’t we will create the file and write the header. If it does exist we will just append the tag data.
SETSYS PRG, “RESUMENEXT”, 1
CLOSE 1 REM - Close the file just in case.
OPEN “file:/usr/DI_1_TEST.csv” FOR BINARY INPUT AS 1
ErrorReturned = GETSYS PRG, “LSTERR”
IF(ErrorReturned = 33) THEN
CLOSE 1
OPEN “file:/usr/DI_1_TEST.csv” FOR BINARY OUTPUT AS 1
PUT 1, “Time,TagName,TIME RAN (MIN),COUNTS (ON)”
PUT 1, CHR$(13)+ CHR$(10)
PUT 1, Time$ +","+ DIStatus$ +","+ STR$ DI_1_TIME@ +","+ STR$ DI_1_COUNT@ +","+ CHR$(13)+ CHR$(10)
CLOSE 1
ELSE

CLOSE 1
OPEN "file:/usr/DI_1_TEST.csv" FOR BINARY APPEND AS 1

PUT 1, Time$ +","+ DIStatus$ +","+ STR$ DI_1_TIME@ +","+ STR$ DI_1_COUNT@ +","+ CHR$(13)+ CHR$(10)

CLOSE 1

ENDIF
END

How long do you need the delay to be?

I needed a 500ms delay because my script was running to fast for the variable update.
I fixed my problem simply by putting in a delayed off coil parallel to my coil controlling the time log, once my input shut off the 500ms delay off i put in my ccw program fixed the problem.
I should have went to bed way earlier than I did, the problem was fixed after 30 min of looking at it this morning.

Thank you for the quick response!!!

1 Like

Welcome!

Let us know if you have any other questions

would you be able to show me how I could use a delay or wait with ONCHANGE?
kind of vague question on my end so here is an example.
int:
bitchange… goto…

lable:
wait 1 , “if(val=0) then”


endif
end

the program guide for this says i can only have 4 wait commands but i could not get them to work for me last night. My programming background is using the Arduino and proccessing, I am new to this however this site has helped me very much!

the next task i need is to send data to a client each night from my logs, however the data i want to send has to be just for that day. not sure how to go about doing this.

I would probably do it without the wait command just because I’ve run into issues in the past and that there’s the limit on only having 4 of them. I’d recommend using a timer similar to the example seen below

delay example.txt (442 Bytes)

THIS TIMER WORKS HOWEVER HOW CAN I GOTO MY LABLE

Function timeroff()
GOTO “WRITE_DI1” //*** this does not find the label should this be written differently******
Print"Function was executed after a 5 second delay" //In this section you can perform the actual delayed function
Tset 1,0 //Turns the timer back off afterwards
Endfn

my goto does not run, is my syntax wrong?

Can you send the full code in a text file and I’ll try and debug it?

int:

Tset 1,0 //Initialize the timer and turn it off
Onchange “EW_1”, “@delaytest()”
Ontimer 1, “@timeroff()”

Function delaytest()
Tset 1,5 //In this example once the function is started, it will create a 5 second delay
Print"timer started"
Endfn

Function timeroff()
GOTO “WRITE_DI1”
Print"Function was executed after a 5 second delay" //In this section you can perform the actual delayed function
Tset 1,0 //Turns the timer back off afterwards
Endfn

end

WRITE_DI1:

DIStatus$ = “” //REM - Because I will be saying open/closed instead of 0/1 I need a string to track this.
IF(DI_1_MEM@ = 0) THEN
DIStatus$ = “DGITAL INPUT OFF”
ELSE
DIStatus$ = “DIGITAL INPUT ON”
ENDIF
//REM - Now below we will verify if the file exists on first cycle. If it doesn’t we will create the file and write the header. If it does exist we will just append the tag data.
SETSYS PRG, “RESUMENEXT”, 1
CLOSE 1 REM - Close the file just in case.
OPEN “file:/usr/DI_1_TEST.csv” FOR BINARY INPUT AS 1
ErrorReturned = GETSYS PRG, “LSTERR”
IF(ErrorReturned = 33) THEN
CLOSE 1
OPEN “file:/usr/DI_1_TEST.csv” FOR BINARY OUTPUT AS 1
PUT 1, “Time,TagName,TIME RAN (MIN),COUNTS (ON)”
PUT 1, CHR$(13)+ CHR$(10)
PUT 1, Time$ +","+ DIStatus$ +","+ STR$ DI_1_TIME@ +","+ STR$ DI_1_COUNT@ +","+ CHR$(13)+ CHR$(10)
CLOSE 1
ELSE

CLOSE 1
 OPEN "file:/usr/DI_1_TEST.csv" FOR BINARY APPEND AS 1

PUT 1, Time$ +","+ DIStatus$ +","+ STR$ DI_1_TIME@ +","+ STR$ DI_1_COUNT@ +","+ CHR$(13)+ CHR$(10)

CLOSE 1

ENDIF
END

Can you send it as a backup.tar file from ebuddy with the support files included?

MOVED TO STAFF NOTE (36.5 KB)

I sent a reply with the backup file but I do not think its uploaded properly.

If it did you will see used “//” to omit the code I added, when I was testing the code I omitted, the ONCHANGE “EW_1”, “GOTO WRITE_DI1” in the INT section.

Hmm it might be easier if I take a look at this on teamviewer

Is there a number I can call you at as well?

Whoops wrong teamviewer link:

teamview is up and running, should i put my phone number here in the forum?

I’ll edit it so it can only be seen by hms internal

CELL PHONE IS
(Hidden)

The program was working till I deleted the user file now I get the following error
IO Error (33)62 : OPEN 'file:/usr/DI_1_TEST.csv" FOR BINARY INPUT AS 1
all other log files work fine

What do you mean when you say that you deleted the user file?

I have my script working to log the tags I want to log. For testing I have erased the file using ERASE “/usr/DI_1_TEST.csv” this has erased my DI_1_TEST.CSV file, this is what i wanted however now I am getting the IO Error(33) and its not creating the .csv file for me.