Προς το περιεχόμενο

Προτεινόμενες αναρτήσεις

Δημοσ.

Καλημέρα και καλώς σας βρήκα.

Έχω αναλάβει μία εργασία για συγχρονισμό η/υ μέσω gps. Διαβάζω το χρόνο από το δορυφόρο από την πρόταση GLL


        private void ProcessGLL(object[] parameters)
        {
            try
            {
                if (parameters[5].ToString() == "Valid")
                {
                    if (NewFix != null)
                    {
                        NewFix((DateTime)parameters[4],
                            new GeographicDimension((double)parameters[0], (Cardinals)Enum.Parse(typeof(Cardinals), (string)parameters[1])),
                            new GeographicDimension((double)parameters[2], (Cardinals)Enum.Parse(typeof(Cardinals), (string)parameters[3])));
                    }
                }
            }
            catch
            {
                //
            }
        }
        public delegate void NewFixHandler(DateTime fixTime, GeographicDimension latitude, GeographicDimension longitude);
        public NewFixHandler NewFix;

και τον εμφανίζω στο timeLabel

        private void gpsReceiver_NewFix(DateTime fixTime, GeographicDimension latitude, GeographicDimension longitude)
        {
            InvokeUpdateLocs(timeLabel, fixTime.ToLongTimeString());
            InvokeUpdateLocs(locationLabel, string.Format("{0}, {1}", latitude, longitude));
        }

Γνωρίζει κάποιος πως μπορώ να θέσω αυτόν τον χρόνο στον υπολογιστή? Ευχαριστώ εκ των προτέρων.

Δημοσ.

Το WIN32 API θα πρέπει να χρησιμοποιήσεις και η SetSystemTime είναι αυτή που θες. 

 

Όμως θα πρέπει να ρυθμίσεις την εφαρμογή ώστε να περάσει το UAC διαφορετικά θα βγάλει μήνυμα ασφάλειας. 

Δημοσ.

Σε ευχαριστώ Apoll για την απάντηση σου.Πρόσθεσα τα dll


namespace NMEATester
{
    public partial class MainForm : Form
    {

        [DllImport("coredll.dll")]
        private extern static void GetSystemTime(ref DateTime SystemTime);

        [DllImport("kernel32.dll")]
        public extern static uint SetSystemTime(ref DateTime SystemTime);


και την SetSystemTime


        private void gpsReceiver_NewFix(DateTime utcTime, GeographicDimension latitude, GeographicDimension longitude)
        {
            InvokeUpdateLocs(timeLabel, utcTime.ToLongTimeString());
            InvokeUpdateLocs(locationLabel, string.Format("{0}, {1}", latitude, longitude));
            InvokeUpdateLocs(lbl11, utcTime.ToLongTimeString());
            SetSystemTime(ref utcTime);
        }

χωρίς αποτέλεσμα δυστυχώς. Μάλλον κάπου κάνω λάθος που δε το καταλαβαίνω. Προσπάθησα να αντιγράψω τη λογική από αυτόν τον κώδικα που τρέχει μια χαρά.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace SystemDateTime
{
    class Class1
    {    /// <summary> This structure represents a date and time. </summary>
        public struct SYSTEMTIME
        {
            public ushort wYear, wMonth, wDayOfWeek, wDay,
               wHour, wMinute, wSecond, wMilliseconds;
        }

        /// <summary>
        /// This function retrieves the current system date
        /// and time expressed in Coordinated Universal Time (UTC).
        /// </summary>
        /// <param name="lpSystemTime">[out] Pointer to a SYSTEMTIME structure to
        /// receive the current system date and time.</param>
        [DllImport("kernel32.dll")]
        public extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

        /// <summary>
        /// This function sets the current system date
        /// and time expressed in Coordinated Universal Time (UTC).
        /// </summary>
        /// <param name="lpSystemTime">[in] Pointer to a SYSTEMTIME structure that
        /// contains the current system date and time.</param>
        [DllImport("kernel32.dll")]
        public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);

        static void Main()
        {
            Console.WriteLine(DateTime.Now.ToString());
            SYSTEMTIME st = new SYSTEMTIME();
            GetSystemTime(ref st);
            Console.WriteLine("Adding 1 hour...");
            st.wHour = (ushort)(st.wHour + 1 % 24);
            if (SetSystemTime(ref st) == 0)
                Console.WriteLine("FAILURE: SetSystemTime failed");
            Console.WriteLine(DateTime.Now.ToString());
            Console.WriteLine("Setting time back...");
            st.wHour = (ushort)(st.wHour - 1 % 24);
            SetSystemTime(ref st);
            Console.WriteLine(DateTime.Now.ToString());
            Console.WriteLine("Press Enter to exit");
            Console.Read();
        }
    }
}
Δημοσ.

Εσύ περνάς DateTime στις Get/Set SystemTime  και όχι την SYSTEMTIME struct.

 

Χρειάζεσαι μια μετατροπή DateTime -- SYSTEMTIME (αντιγραφή τα πεδια) και μετα περνας την struct στην SetSystemTime

 

To "coredll.dll" ειναι για windows mobile συσκευες. Βαλε "kernel32.dll" και στην GetSystemTime.

 

Εννοείται ότι πρεπει να δηλώσεις την SYSTEMTIME struct.

  • Like 1

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...