private static void Main(string[] args) { using (var busproController = new BusproController(Ip, Port)) { var antChannels = 6; var channelStatusBinaryString = "00001010"; var dict = new Dictionary <int, Channel.Status>(); var channelNo = 1; for (var i = channelStatusBinaryString.Length - 1; i >= 0; i--) { if (channelNo > antChannels) { break; } dict.Add(channelNo, (Channel.Status) int.Parse(channelStatusBinaryString[i].ToString())); channelNo++; } // listen to events for all commands across bus busproController.CommandReceived += BusproController_CommandReceived; // listen to broadcast commands across bus //busproController.BroadcastCommandReceived += BusproController_BroadcastCommandReceived; // sender/source address and devicetype busproController.SourceAddress = new DeviceAddress { DeviceId = SourceDeviceId, SubnetId = SourceSubnetId }; busproController.SourceDeviceType = SourceDeviceType; busproController.StartListen(); Console.WriteLine($"Gateway address set to {busproController.Address}:{busproController.Port}"); Console.WriteLine("Press enter to close...\n"); // add devices to controller //AddDevices(busproController); // return all devices in controller //var devices = busproController.Device; // get specific device from controller //var logic = busproController.GetDevice(new DeviceAddress { SubnetId = 1, DeviceId = 100 }); //Console.WriteLine(logic == null ? "Did not find Device\n" : "Found Device\n"); //logic.SendOperationCode()... //Thread.Sleep(10000); //TurnOffLightMediaroom(busproController); //QueryDlp(busproController); Console.ReadLine(); } }
internal Logic(BusproController controller, DeviceType deviceType, DeviceAddress deviceAddress) : base(controller, deviceType, deviceAddress) { }
private static void Main(string[] args) { using (var busproController = new BusproController(Ip, Port)) { busproController.ContentReceived += busproController_ContentReceived; busproController.DeviceDataContentReceived += busproController_ContentReceivedForDevice; busproController.SourceAddress = new DeviceAddress { DeviceId = SourceDeviceId, SubnetId = SourceSubnetId }; busproController.SourceDeviceType = SourceDeviceType; new Thread(() => { Thread.CurrentThread.IsBackground = true; while (true) { // Reads all data on bus busproController.ReadBus(); } }).Start(); Console.WriteLine("Press enter to close...\n"); ListenToDevice(busproController); //Thread.Sleep(10000); //TurnOffLightMediaroom(busproController); //QueryDlp(busproController); Console.ReadLine(); } //var cmd = "read"; //if (args.Length != 0) cmd = args[0]; //cmd = "write"; //switch (cmd) //{ // case "read": // using (var busproController = new BusproController.BusproController()) // { // busproController.ContentReceived += busproController_ContentReceived; // busproController.SourceAddress = new DeviceAddress { DeviceId = SourceDeviceId, SubnetId = SourceSubnetId }; // busproController.SourceDeviceType = SourceDeviceType; // StartThread(busproController); // Console.WriteLine("Press enter to close...\n"); // Thread.Sleep(5000); // TurnOffLightMediaroom(busproController); // Console.ReadLine(); // } // return; // case "write": // using (var busproController = new BusproController.BusproController(Ip, Port)) // { // busproController.SourceAddress = new DeviceAddress { DeviceId = SourceDeviceId, SubnetId = SourceSubnetId }; // busproController.SourceDeviceType = SourceDeviceType; // TurnOffLightMediaroom(busproController); // Console.WriteLine("Press enter to close...\n"); // Console.ReadLine(); // } // return; //} }
private static void ParseData(Command data) { if (data == null || !data.Success) { return; } var sb = new StringBuilder(""); var errorMessage = data.ErrorMessage; var success = data.Success; var b = data.AdditionalContent; var t = BusproController.ByteArrayToText(b); var sd = data.SourceAddress.DeviceId; var ss = data.SourceAddress.SubnetId; var td = data.TargetAddress.DeviceId; var ts = data.TargetAddress.SubnetId; var o = data.OperationCode; var oHex = data.OperationCodeHex; var dt = data.SourceDeviceType; var dtHex = data.SourceDeviceTypeHex; //sb.Append($"Success: \t\t{success}"); if (success) { sb.Append($"Operation code: \t{o} ({oHex})\n"); sb.Append($"Source device type: \t{dt} ({dtHex})\n"); sb.Append($"Address:\t\t{ss}.{sd} => {ts}.{td}\n"); sb.Append($"Address:\t\t{ParseDeviceName(ss, sd)} => {ParseDeviceName(ts, td)}\n"); sb.Append($"Additional content: \t{t}\n"); if (o == OperationCode.BroadcastSystemDateTime) { sb.Append($"Current time: \t\t{b[2]}/{b[1]}/{b[0]} {b[3]}:{b[4]}:{b[5]}\n"); } if (o == OperationCode.ReadFloorHeatingStatusResponse) { sb.Append($"Heat active: \t\t{b[2]}\n"); sb.Append($"Set temperature: \t{b[4]}\n"); sb.Append($"Current temperature: \t{b[1]}\n"); } if (o == OperationCode.BroadcastTemperature) { sb.Append($"Current temperatur: \t{b[1]}\n"); } if (o == OperationCode.SingleChannelControl) { sb.Append(Newtonsoft.Json.JsonConvert.SerializeObject(Parsing.ParseSingleChannelControl(data))); } if (o == OperationCode.SingleChannelControlResponse) { sb.Append(Newtonsoft.Json.JsonConvert.SerializeObject(Parsing.ParseSingleChannelControlResponse(data))); } } else { sb.Append($" ({errorMessage})"); } Console.WriteLine(sb.ToString()); Console.WriteLine(""); }