private static void SendAmqpMessages(double x, double y, WaveProperties prop) { var value = prop.ValueFormatter(prop, y); var setPoint = prop.ValueFormatter(prop, prop.SetPoint); Func <double, string> formatter = (d) => string.Format("{0:0.000000}", Math.Round(d, 6)).Replace(',', '.'); var sev = "Normal"; double h = 0, hh = 0, l = 0, ll = 0; if (prop.DynamicSeverity) { var diff = Math.Abs(prop.SetPoint - y); if (diff >= prop.SeverityError) { sev = "Error"; } else if (diff >= prop.SeverityWarning) { sev = "Warning"; } hh = prop.SetPoint + prop.SeverityError; h = prop.SetPoint + prop.SeverityWarning; l = prop.SetPoint - prop.SeverityWarning; ll = prop.SetPoint - prop.SeverityError; } //Body Message string body = $@"{{ ""Id"": ""{Guid.NewGuid()}"", ""Key"" : ""{prop.ValueName}"", ""Type"": ""ValueMessage"", ""Source"": ""ValueUpdate"", ""ValueName"": ""{prop.ValueName}"", ""Name"": ""{prop.Key}"", ""Value"": ""{value.Trim()}"", ""HH"": {formatter(hh)}, ""H"": {formatter(h)}, ""L"": {formatter(l)}, ""LL"": {formatter(ll)}, ""Unit"": ""{prop.Unit}"", ""SetPoint"": ""{setPoint}"", ""Severity"": ""{sev}""}}"; var message1 = new Message { BodySection = new Data { Binary = Encoding.UTF8.GetBytes(body) } }; MessageLink.Send(message1); //PlcDataMessage var message2 = new Message { Properties = new Amqp.Framing.Properties { CorrelationId = Guid.NewGuid().ToString(), }, ApplicationProperties = new ApplicationProperties { Map = { { "Type", prop.PropType }, { "Name", prop.PropName }, { "Value", value }, { "Namespace", prop.PropNamespace }, { "Timestamp", DateTime.Now.ToString(CultureInfo.InvariantCulture) }, } } }; PlcDataLink.Send(message2); }
private static void DebugPrint(double x, double y, WaveProperties prop) { Console.WriteLine(string.Format("Sending: ({0,7:F3} | {1,7:F3} ) as {2}", x, y, prop.ValueName)); }