How to read the bit of switch of PLC in C# application

denesh neupane 121 Reputation points

i am working on read and write the Mitsubishi PLC via C# application i need to read the date and time of plc and display in the datagridview in application. If i store a date example Year,Month and Day in D111,D112,D113 then i read the date sucessfully but the problem is year is stored in D111,Month and Day are store in switch D112 Bit 0-7 and Bit 8-15. if i read D111 and D112 then the date will be displayed like 2022/0309 but i need 2022/03/09 . how can i read the bits 0-7 and 8-15 separately .

 int count;
            plc.GetDevice("D22", out count);
            int result;
            plc.GetDevice("D22", out result);
            int read_;
            plc.GetDevice("D22", out read_);
            int read1;
            plc.GetDevice("D22", out read1);
            int year;
            plc.GetDevice("D220", out year);
            int month;
            plc.GetDevice("D221", out month);
            int day;
            plc.GetDevice("D222", out day);
            int hour;
            plc.GetDevice("D223", out hour);
            int minute;
            plc.GetDevice("D224", out minute);
            int second;
            plc.GetDevice("D225", out second);
            SqlCommand cmd;

            cmd = new SqlCommand("insert into [Table](date,time,count,tool,up,down) values(@date,@time,@count,@tool,@up,@down)", con);


                cmd.Parameters.AddWithValue("@date", year.ToString() + "/" + month.ToString() + "/" + day.ToString());
                cmd.Parameters.AddWithValue("@time", hour.ToString() + ":" + minute.ToString() + ":" + second.ToString());
                cmd.Parameters.AddWithValue("@count", count.ToString());
                cmd.Parameters.AddWithValue("@tool", read1.ToString());
                cmd.Parameters.AddWithValue("@up", result.ToString());
                cmd.Parameters.AddWithValue("@down", read_.ToString());
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,380 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful