Exemple #1
0
        static void Main(string[] args)
        {
            int number_of_device = 10;
            var factory          = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "hello",
                                         durable: false,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    List <Chiller> Chillers = new List <Chiller>();

                    for (int i = 0; i < number_of_device; i++)
                    {
                        var number  = i + 1;
                        var chiller = new Chiller(number.ToString(), "Device" + number);
                        Chillers.Add(chiller);
                    }


                    while (true)
                    {
                        for (int i = 0; i < number_of_device; i++)
                        {
                            var ch = Chillers[i];
                            ch.SimulateData();
                            string output = JsonConvert.SerializeObject(ch);
                            var    body   = Encoding.UTF8.GetBytes(output);

                            channel.BasicPublish(exchange: "",
                                                 routingKey: "hello",
                                                 basicProperties: null,
                                                 body: body);
                            Console.WriteLine(" [x] Sent {0}", output);
                        }
                        Thread.Sleep(1000);
                    }
                }

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }
        //private DeviceDriver test = new DeviceDriver();

        public ChillerHardwareViewModel()
        {
            Title = "Chiller Hardware Module";

            //test.FindUsbDevice();

            Chiller = new Chiller();

            OpenDeviceCommand  = new DelegateCommand(OpenDeviceHandler);
            GetVersionCommand  = new DelegateCommand(GetVersionHandler);
            GetFeedbackCommand = new DelegateCommand(GetFeedbackHandler);
            CloseDeviceCommand = new DelegateCommand(CloseDeviceHandler);
            SetSetPointCommand = new DelegateCommand(SetSetPointHandler);

            SetPoint = 27.85;
        }
 private void CloseDeviceHandler()
 {
     Chiller.Close();
 }
 private void GetFeedbackHandler()
 {
     ChillerFeedback = Chiller.CMD_GET_FEEDBACK();
 }
 private void GetVersionHandler()
 {
     Version = Chiller.CMD_GET_VERSION();
 }
 private void OpenDeviceHandler()
 {
     Chiller.Open();
 }
 private void SetSetPointHandler()
 {
     Chiller.CMD_SET_SETPOINT(SetPoint);
 }