Menu

read and write timer

2017-08-17
2017-08-17
  • awi1369 jimbo

    awi1369 jimbo - 2017-08-17

    Hello
    how can read value of timer?sharp7-s300
    can you give me example for T1

     
  • Jiri Marek

    Jiri Marek - 2017-08-18

    I use this:

    if (Box_date_type1.Text == text_s5time)
    {
        byte[] Buffer = new byte[2];
        int Result;
        int hod = 0;
        int min = 0;
        int sec = 0;
        int msec = 0;
    
        Result = Client.DBRead(Convert.ToInt16(txt_DB_number1.Text), Convert.ToInt16(txt_address1.Text), 2, Buffer);
    
        int result = 0;
        foreach (byte bcd in Buffer)
        {
        result *= 100;
        result += (10 * (bcd >> 4));
        result += bcd & 0xf;
        }
    
        string result_string = result.ToString();
    
        if (result_string.Length < 4) //less than 9,9sec
        {
        sec = result / 100;
        msec = result % 100;
        msec = msec * 10;
    
        txt_read1.Text = "DB" + txt_DB_number1.Text + ".DBW" + txt_address1.Text + " = " + sec.ToString() + "s" + msec.ToString() + "ms";
        }
    
        else if (result_string.Length == 4) //10 sec and more
        {
        if (result_string[0] == '1') //from 10sec to 99,9sec (1min 39s 900ms)
        {
            result_string = result_string.Substring(1);
            min = Convert.ToInt16(result_string) / 600;
            sec = Convert.ToInt16(result_string) % 600;
            msec = (sec % 10) * 100;
            sec = sec / 10;
    
            txt_read1.Text = "DB" + txt_DB_number1.Text + ".DBW" + txt_address1.Text + " = " + min.ToString() + "m" + sec.ToString() + "s" + msec.ToString() + "ms";
        }
    
        else if (result_string[0] == '2') //from 1min40s900ms to 16min39s
        {
            result_string = result_string.Substring(1);
            min = Convert.ToInt16(result_string) / 60;
            sec = Convert.ToInt16(result_string) % 60;
            txt_read1.Text = "DB" + txt_DB_number1.Text + ".DBW" + txt_address1.Text + " = " + min.ToString() + "m" + sec.ToString() + "s";
        }
    
        else if (result_string[0] == '3') //from 16min40s to 2h46m30s
        {
            result_string = result_string.Substring(1);
            hod = Convert.ToInt16(result_string) / 360;
            min = (Convert.ToInt16(result_string) % 360) / 6;
            sec = ((Convert.ToInt16(result_string) % 360) % 6) * 10;
            txt_read1.Text = "DB" + txt_DB_number1.Text + ".DBW" + txt_address1.Text + " = " + hod.ToString() + "h" + min.ToString() + "m" + sec.ToString() + "s";
        }
        }
    
    }
    
     
  • awi1369 jimbo

    awi1369 jimbo - 2017-08-18

    i want use TMRead

     

Log in to post a comment.