Ejemplo n.º 1
0
        void monitoringLog(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            cbOnLogReceived = new API.OnLogReceived(RealtimeLogReceived);
            Console.WriteLine("Trying to activate log monitoring.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_StartMonitoringLog(sdkContext, deviceID, cbOnLogReceived);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }

            Console.WriteLine("Press ESC to stop log monitoring.");
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Thread.Sleep(100);
            }

            Console.WriteLine("Trying to deactivate log monitoring.");
            result = (BS2ErrorCode)API.BS2_StopMonitoringLog(sdkContext, deviceID);
            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }

            cbOnLogReceived = null;
        }
Ejemplo n.º 2
0
        void monitoringLog(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            Console.WriteLine("Do you want to display the temperature in the real-time log? [y/n]");
            if (Util.IsYes())
            {
                monitoringLogEx(sdkContext, deviceID, isMasterDevice);
                return;
            }

            cbOnLogReceivedEx = null;
            cbOnLogReceived   = new API.OnLogReceived(RealtimeLogReceived);
            Console.WriteLine("Trying to activate log monitoring.");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_StartMonitoringLog(sdkContext, deviceID, cbOnLogReceived);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }

            Console.WriteLine("Press ESC to stop log monitoring.");
            while (Console.ReadKey(true).Key != ConsoleKey.Escape)
            {
                Thread.Sleep(100);
            }

            Console.WriteLine("Trying to deactivate log monitoring.");
            result = (BS2ErrorCode)API.BS2_StopMonitoringLog(sdkContext, deviceID);
            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }

            cbOnLogReceived = null;
        }
Ejemplo n.º 3
0
        void getLog(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            const UInt32 defaultLogPageSize = 1024;
            Type         structureType      = typeof(BS2Event);
            int          structSize         = Marshal.SizeOf(structureType);
            bool         getAllLog          = false;
            UInt32       lastEventId        = 0;
            UInt32       amount;
            IntPtr       outEventLogObjs = IntPtr.Zero;
            UInt32       outNumEventLogs = 0;

            cbOnLogReceived = new API.OnLogReceived(NormalLogReceived);

            Console.WriteLine("What is the ID of the last log which you have? [0: None]");
            Console.Write(">>>> ");
            lastEventId = Util.GetInput((UInt32)0);
            Console.WriteLine("How many logs do you want to get? [0: All]");
            Console.Write(">>>> ");
            amount = Util.GetInput((UInt32)0);

            if (amount == 0)
            {
                getAllLog = true;
                amount    = defaultLogPageSize;
            }

            do
            {
                outEventLogObjs = IntPtr.Zero;
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetLog(sdkContext, deviceID, lastEventId, amount, out outEventLogObjs, out outNumEventLogs);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                    break;
                }

                if (outNumEventLogs > 0)
                {
                    IntPtr curEventLogObjs = outEventLogObjs;
                    for (UInt32 idx = 0; idx < outNumEventLogs; idx++)
                    {
                        BS2Event eventLog = (BS2Event)Marshal.PtrToStructure(curEventLogObjs, structureType);
                        Console.WriteLine(Util.GetLogMsg(eventLog));
                        curEventLogObjs += structSize;
                        lastEventId      = eventLog.id;
                    }

                    API.BS2_ReleaseObject(outEventLogObjs);
                }

                if (outNumEventLogs < defaultLogPageSize)
                {
                    break;
                }
            }while (getAllLog);
        }
Ejemplo n.º 4
0
        void getLogBlob(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            const UInt32 defaultLogPageSize = 1024;
            Type         structureType      = typeof(BS2EventBlob);
            int          structSize         = Marshal.SizeOf(structureType);
            bool         getAllLog          = false;
            UInt32       lastEventId        = 0;
            UInt32       amount;
            IntPtr       outEventLogObjs = IntPtr.Zero;
            UInt32       outNumEventLogs = 0;

            cbOnLogReceived = new API.OnLogReceived(NormalLogReceived);

            Console.WriteLine("What is the ID of the last log which you have? [0: None]");
            Console.Write(">>>> ");
            lastEventId = Util.GetInput((UInt32)0);
            Console.WriteLine("How many logs do you want to get? [0: All]");
            Console.Write(">>>> ");
            amount = Util.GetInput((UInt32)0);

            if (amount == 0)
            {
                getAllLog = true;
                amount    = defaultLogPageSize;
            }

            do
            {
                outEventLogObjs = IntPtr.Zero;
                BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetLogBlob(sdkContext, deviceID, (ushort)BS2EventMaskEnum.ALL, lastEventId, amount, out outEventLogObjs, out outNumEventLogs);
                if (result != BS2ErrorCode.BS_SDK_SUCCESS)
                {
                    Console.WriteLine("Got error({0}).", result);
                    break;
                }

                if (outNumEventLogs > 0)
                {
                    IntPtr curEventLogObjs = outEventLogObjs;
                    for (UInt32 idx = 0; idx < outNumEventLogs; idx++)
                    {
                        BS2EventBlob eventLog = (BS2EventBlob)Marshal.PtrToStructure(curEventLogObjs, structureType);


                        DateTime eventTime = Util.ConvertFromUnixTimestamp(eventLog.info.dateTime);

                        byte[] userID = new byte[BS2Environment.BS2_USER_ID_SIZE];
                        Array.Clear(userID, 0, BS2Environment.BS2_USER_ID_SIZE);
                        Array.Copy(eventLog.objectID, userID, userID.Length);

                        Console.WriteLine("Got log(idx[{0}], timestamp[{1}], event id[{2}], userID[{3}], jobcode[{4}])."
                                          , idx
                                          , eventTime.ToString("yyyy-MM-dd HH:mm:ss")
                                          , eventLog.id
                                          , System.Text.Encoding.ASCII.GetString(userID).TrimEnd('\0')
                                          , eventLog.jobCode);


                        curEventLogObjs += structSize;
                        lastEventId      = eventLog.id;
                    }

                    API.BS2_ReleaseObject(outEventLogObjs);
                }

                if (outNumEventLogs < defaultLogPageSize)
                {
                    break;
                }
            }while (getAllLog);
        }