RobotStudio event

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.
«1

Comments

  • The older function is CTime:

    VAR string time;
    time := CTime();
    Lee Justice
  • 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.
    Lee Justice
  • You won't get day of the week, but you can also use CDate to fetch the current date.
    Lee Justice
  • 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.
    Lee Justice
  • 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.
    Lee Justice
  • 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.
    Lee Justice
  • 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);
    Lee Justice
  • Thanks.
    Now its running with out stopp :-)
    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
    Lee Justice
  • MANY, MANY thanks to you!!! 
    I'll test that next week.

    I want to divide the day into 3 parts, if its possible?

    00:00 to 07:00,
    7:00 to 15:30,
    15:30 to 24:00.
  • Yes.  IF (nHour > 0) AND (nHour < 7) THEN
      Do something
    ELSEIF (nHour > 7) AND (nHour < 15) THEN
      Do something else
    ELSEIF more of the same...
      Do something else
    ENDIF

    But for the 30 minutes part you will need to read in the minutes and add that too.
    Lee Justice
  • YOU have helped me so, so much.

    I have no robot to test now but, is this right?

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

    time := CTime();
    stHour:=StrPart(time,1,2);
    stMinute:=StrPart(time,1,2);
    bOk:=StrToVal(stHour,nHour);
    bOk:=StrToVal(stHour,nMinute);

    IF (nHour > 0) AND (nHour < 7) THEN
      Do something
    ELSEIF (nHour > 7) AND (nHour >15,nMinute<30) THEN
      Do something else
    ELSEIF more of the same...
      Do something else
    ENDIF
  • stMinute:=StrPart(time,1,2);
    Change to:
    stMinute:=StrPart(time,4,2);
    bOk:=StrToVal(stHour,nMinute);
    Change to:
    bOk:=StrToVal(stMinute,nMinute);
    ELSEIF (nHour > 7) AND (nHour >15,nMinute<30) THEN
    Change to:
    ELSEIF (nHour > 7) AND (nHour >15) AND (nMinute<30) THEN
    Lee Justice
  • I go on vacation next week, so even you get free from me :-)
    But I will test this, week 9 and will tell you how it is going.
  • Hi again.

    This line may not be OK.

    ELSEIF (nHour > 7) AND (nHour >15) AND (nMinute<30) THEN

    No error message, but nothing happens.

    When I only white with whole hours it works.
    ELSEIF (nHour > 7) AND (nHour >15) THEN
  • I see now that this logic is a bit funny:
    ELSEIF (nHour > 7) AND (nHour >15) AND (nMinute<30) THEN

    If nHour > 15 then of course it is greater than 7.  Might just simplify to:

    IF (nHour = 15) AND (nMinute < 30) THEN
    Lee Justice
  • Sbj
    Sbj
    edited February 2020


  • Hi.

    Now it works just as I had imagined.

    (except weekdays).

    But I am more than satisfied.

    Thank you so much again !!!

  • You are welcome.  :)
    Lee Justice
  • Hi.
    Thanks for all help I got from you in "GetTime with S4".
    Now it works and the robot doesn't stop (good), so I've tested many different times, etc., but can't find the solution
    The times I want is:
    
    0:24 -> 6:48
    TPWrite "1";
    6:48 -> 15:42 TPWrite "2";
    15:42 -> 0:24 TPWrite "3";
    Know that there are several errors, but can not find the right one. Please, can you find a solution for me, below?
      IF (nHour >= 0) AND (nMinute > 24) AND (nHour = 6) AND (nMinute < 48) THEN 
       TPWrite "1";
       
       ELSEIF (nHour >= 6) AND (nMinute >= 48) AND (nHour < 16) AND (nMinute < 42) THEN
       TPWrite "2";
           
       ELSE
       TPWrite "3";
     ENDIF
    Kindly.