/// <summary>
 /// Initializes scanner from communication port to serial port by providing locker configuration.
 /// </summary>
 /// <returns>
 ///  Publish scanning value to MQTT Broker
 /// </returns>
 public static void InitializeScanner(ComPortsHealthCheck comPortsHealthCheck, AppSettings lockerConfiguration, Func <string, string> dataProcessFunc)
 {
     if (comPortsHealthCheck.IsScannernPortAvailable)
     {
         SerialInterface          controllerModule = lockerConfiguration.Microcontroller.Scanner;
         SerialPortControlService scanner          = new SerialPortControlService(new SerialPortResource(controllerModule.Port, controllerModule.Baudrate, controllerModule.DataBits, 500, 500));
         scanner.SetReadToPublishHandler(controllerModule, dataProcessFunc);
         scanner.Begin();
         Log.Information("[HCM][Communication Port Control Service][Initialize Scanner]" + "[Scanner Port : " + controllerModule.Port + "]");
     }
 }
Exemple #2
0
        /// <summary>
        /// Test comport in list.
        /// </summary>
        public static ComPortsHealthCheck ComPortTest(AppSettings lockerConfiguration)
        {
            try
            {
                var comPorts = new ComPortsHealthCheck();
                if (lockerConfiguration == null)
                {
                    return(comPorts);
                }
                comPorts.IsLockPortAvailable      = Check(lockerConfiguration.Microcontroller.LockControl);
                comPorts.IsDetectionPortAvailable = Check(lockerConfiguration.Microcontroller.ObjectDetection);
                comPorts.IsScannernPortAvailable  = Check(lockerConfiguration.Microcontroller.Scanner);

                Log.Debug("[HCM][Locker Helper][Com Port Test]" + "[Com Port Health : " + JsonSerializer.Serialize(comPorts) + "]");
                return(comPorts);
            }
            catch (Exception)
            {
                throw;
            }
        }
 /// <summary>
 ///   Initialization information for locker configuration including Microcontroller board, Serial port and Communication port.
 ///</summary>
 public LockerManager(string configurationFilePath)
 {
     LockerConfiguration = LockerHelper.GetConfiguration(configurationFilePath);
     PortsHealthCheck    = LockerHelper.ComPortTest(LockerConfiguration);
     Log.Information("[HCM][Locker Manager][Initiated][Service initiated with scanner and logging.]");
 }