GetTime with S4

Hi folks.

I wonder if it is possible to use gettime on s4, to write a message (TP …) on the pendant at a certain time?

I can’t find that command on the pendant, but it might be written offline?

Kindly.

The older function is CTime:

VAR string time;
time := CTime();

Thank you, maybe you can find the solution for me in this example?

weekday := GetTime(\WDay);
hour := GetTime(\Hour);

IF weekday < 6 AND hour >6 AND hour < 16 THEN
TPWrite “Day shift”;
ELSE
TPWrite “Evening shift”;
ENDIF

So the returned value of CTime is string. You will dissect the string with StrPart function and then use StrToVal function to change to numeric values with which you can make such an evaluation.

You won’t get day of the week, but you can also use CDate to fetch the current date.

Thanks, as you understand, I am beginner.
Now I read the manual to understand your answer.
So can you write an exemple that I can later modify at the right time?

VAR string time;
VAR string stHour;
VAR num nHour;
VAR bool bOk;

time := CTime();
stHour:=StrPart(time,1.2);
bOk:=StrToVal(stHour,nHour);

Then you can use the value written into nHour by the StrToVal function to determine “Day” or “Evening” shift.

Thanks again.

Will copy this and test it tomorrow when I come back to the work.

Maybe this will help you. Can modify as you would like. I don’t know if it will work on S4 though. This is done for IRC5;

Just add PROC “Details” wherever you want the TP to display this details.

MODULE Print_TP

    LOCAL CONST string Months_Name{12}:=["January","February","March","April","May","June","July","August","September","October","November","December"];
    LOCAL CONST string Months_Number{12}:=["01","02","03","04","05","06","07","08","09","10","11","12"];
    LOCAL PERS string sDayWeek:="";
    LOCAL PERS string sMonths:="";
    LOCAL PERS string sYear:="";
    LOCAL PERS string sTime:="";
    LOCAL VAR intnum intReadDateToday;
    LOCAL PERS bool bDetailsPrinted:=TRUE;
    LOCAL PERS num nTimeHour:=12;
    LOCAL PERS num nTimeMinute:=43;
    LOCAL PERS num nTimeSecond:=59;
    LOCAL PERS string sWeekday:="";

    PROC Details()
        WHILE bDetailsPrinted=FALSE DO
            nTimeHour:=GetTime(\Hour);
            nTimeMinute:=GetTime(\Min);
            nTimeSecond:=GetTime(\Sec);
            IF nTimeHour>06 OR nTimeHour<17 AND nTimeMinute=59 OR nTimeMinute<59 AND nTimeSecond=00 THEN
                IF bDetailsPrinted=FALSE THEN
                    TPErase;
                    TPWrite Weekday(sDayWeek);
                    TPWrite Month(sMonths);
                    TPWrite Year(sYear);
                    TPWrite Time(sTime);
                    TPWrite "Shift: Dayshift";
                    bDetailsPrinted:=TRUE;
                ENDIF
            ELSEIF nTimeHour>18 OR nTimeHour<05 AND nTimeMinute=59 OR nTimeMinute<59 AND nTimeSecond=00 THEN
                IF bDetailsPrinted=FALSE THEN
                    TPErase;
                    TPWrite Weekday(sDayWeek);
                    TPWrite Month(sMonths);
                    TPWrite Year(sYear);
                    TPWrite Time(sTime);
                    TPWrite "Shift: Nightshift";
                    bDetailsPrinted:=TRUE;
                ENDIF
            ENDIF
        ENDWHILE
    ENDPROC

    LOCAL FUNC string Weekday(String DayWeek)
        VAR num nWeekday;
        VAR string sDayWeek;
        nWeekday:=GetTime(\WDay);
        IF nWeekday=1 sDayWeek:=sWeekDays{1};
        IF nWeekday=2 sDayWeek:=sWeekDays{2};
        IF nWeekday=3 sDayWeek:=sWeekDays{3};
        IF nWeekday=4 sDayWeek:=sWeekDays{4};
        IF nWeekday=5 sDayWeek:=sWeekDays{5};
        IF nWeekday=6 sDayWeek:=sWeekDays{6};
        IF nWeekday=7 sDayWeek:=sWeekDays{7};
        RETURN "Weekday: "+sDayWeek;
    ENDFUNC

    LOCAL FUNC string Month(String Months)
        VAR string sMonths;
        VAR string sDate;
        VAR num nMonths;
        sDate:=CDate();
        Months:=StrPart(sDate,6,2);
        IF Months=Months_Number{1} Months:=Months_Name{1};
        IF Months=Months_Number{2} Months:=Months_Name{2};
        IF Months=Months_Number{3} Months:=Months_Name{3};
        IF Months=Months_Number{4} Months:=Months_Name{4};
        IF Months=Months_Number{5} Months:=Months_Name{5};
        IF Months=Months_Number{6} Months:=Months_Name{6};
        IF Months=Months_Number{7} Months:=Months_Name{7};
        IF Months=Months_Number{8} Months:=Months_Name{8};
        IF Months=Months_Number{9} Months:=Months_Name{9};
        IF Months=Months_Number{10} Months:=Months_Name{10};
        IF Months=Months_Number{11} Months:=Months_Name{11};
        IF Months=Months_Number{12} Months:=Months_Name{12};
        RETURN "Month: "+Months;
    ENDFUNC

    LOCAL FUNC string Year(String Year)
        VAR string sYear;
        VAR string sDate;
        VAR num nMonths;
        sDate:=CDate();
        sYear:=StrPart(sDate,1,4);
        RETURN "Year: "+sYear;
    ENDFUNC

    LOCAL FUNC string Time(String Time)
        VAR string sTime;
        sTime:=CTime();
        RETURN "Time: "+sTime;
    ENDFUNC
ENDMODULE

When I loaded the 7 lines that # lemster68 # sent, I got these errors

When I load only 7 lines from lemster68#, I get this on screen.

How about the screen that shows the code? These ones only show that there was an error.

I put it in one paintprogram.
But the stop comes before, in mainprog.
On the line:
LoadProg NORMAL_PROG, stNextProgNormal, stPathProgDir;

Try entering the code line by line using the pendant.

Now I have come further.

I get into paintprogram and there I get the error message:

Too few arguments in call to routine StrPart.

Hello,
A char is missing in lemster68 code. Should be:
stHour:=StrPart(time,1,.2);

Thanks.

After I have loaded hint from DenisFR, I have got error message:

Illegal value of argument for parameter.

The font is abit small for me to read well, but it looks like there may be a typo. A period instead of a comma: stHour:=StrPart(time,1,2);

Thanks.
Now its running with out stopp :slight_smile:
But do you have a solution on how to get the value out and use it in an IF instruction?
So the robot for ex:

PaintL P1, 500, z1,t_ref150\Wobj:=wobjcnv1;
PaintL P2, 500, z1,t_ref150\Wobj:=wobjcnv1;
PaintL P3, 500, z1,t_ref150\Wobj:=wobjcnv1;
PaintL P4, 500, z1,t_ref150\Wobj:=wobjcnv1;
PaintL P5, 500, z1,t_ref150\Wobj:=wobjcnv1;

The robot go from P1, P2 and P5 all time, and depending on the time of day, the robot should go to P3 in the day and P4 in the evening.

PaintL P1
PaintL P2
IF nHour < 16 THEN
PaintL P3
ELSE
PaintL P4
ENDIF
PaintL P5