public static void SendReadTimeRequest(byte SlaveAddr, SerialDataProvider SerialPort, Action <bool, ushort[]> DataRecieved, TimeConfig CurrentConfig)
 {
     if (CurrentConfig.TimeFormat == TimeFormats.STMFormat)
     {
         SerialPort.GetData(SlaveAddr, CurrentConfig.STMProcAddr1, 4, DataRecieved);
     }
     else if (CurrentConfig.TimeFormat == TimeFormats.ADSPFormat)
     {
         SerialPort.GetData(SlaveAddr, CurrentConfig.ReadAddr, 7, DataRecieved);
     }
     else if (CurrentConfig.TimeFormat == TimeFormats.RTCFormat)
     {
         SerialPort.GetData(SlaveAddr, CurrentConfig.ReadAddr, 4, DataRecieved);
     }
 }
        public static void SendSetTimeRequest(byte SlaveAddr, SerialDataProvider SerialPort, TimeConfig CurrentConfig, int Hour, int Min, int Sec, int Day, int Month, int Year)
        {
            if (CurrentConfig.TimeFormat == TimeFormats.STMFormat)
            {
                ushort[] paramRTU = new ushort[4];
                paramRTU[0] = (ushort)(((Month.ToBCD() & 0x1F) << 8) | (Day.ToBCD() & 0x3F));
                paramRTU[1] = (ushort)Year.ToBCD();
                paramRTU[2] = (ushort)(((Min.ToBCD() & 0xFF) << 8) | (Sec.ToBCD() & 0xFF));
                paramRTU[3] = (ushort)(Hour.ToBCD() | 0x0100);
                SerialPort.SetData(SlaveAddr, CurrentConfig.STMProcAddr1_1, null, paramRTU);
            }
            else if (CurrentConfig.TimeFormat == TimeFormats.ADSPFormat)
            {
                ushort[] paramRTU = new ushort[3];
                paramRTU[0] = Sec.ToBCD();
                paramRTU[1] = Min.ToBCD();
                paramRTU[2] = Hour.ToBCD();
                SerialPort.SetData(SlaveAddr, CurrentConfig.SetAddr, null, paramRTU);

                paramRTU[0] = Day.ToBCD();
                paramRTU[1] = Month.ToBCD();
                paramRTU[2] = Year.ToBCD();
                SerialPort.SetData(SlaveAddr, (ushort)(CurrentConfig.SetAddr + 4), null, paramRTU);

                SerialPort.SetData(SlaveAddr, CurrentConfig.AddrSetTime, null, 1);
            }
            if (CurrentConfig.TimeFormat == TimeFormats.RTCFormat)
            {
                ushort[] paramRTU = new ushort[4];
                paramRTU[0] = (ushort)(((Month.ToBCD() & 0x1F) << 8) | (Day.ToBCD() & 0x3F));
                paramRTU[1] = (ushort)Year.ToBCD();
                paramRTU[2] = (ushort)(((Min.ToBCD() & 0x7F) << 8) | (Sec.ToBCD() & 0x7F));
                paramRTU[3] = (ushort)(Hour.ToBCD() & 0x3F);
                SerialPort.SetData(SlaveAddr, CurrentConfig.SetAddr, null, paramRTU);
            }
        }