Пример #1
0
        /// <summary>
        /// Process our command log
        /// </summary>
        /// <param name="state"></param>
        private void ProcessCommandLog(object state)
        {
            List <MM_EMS_Command> NewCommands = new List <MM_EMS_Command>();
            String InLine;

            using (FileStream fS = new FileStream((string)state, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (StreamReader sRd = new StreamReader(fS))
                    while ((InLine = sRd.ReadLine()) != null)
                    {
                        if (InLine.Contains("Sent") && InLine.Contains("TEDE"))
                        {
                            InLine = InLine.Substring(InLine.IndexOf('>') + 1);
                            InLine = InLine.Substring(0, InLine.IndexOf('<'));
                            String[] splStr     = InLine.Split(' ');
                            String[] splCommand = splStr[5].Split(',');
                            NewCommands.Add(new MM_EMS_Command()
                            {
                                UserName    = splStr[1],
                                CommandType = splCommand[0],
                                Application = splCommand[1],
                                Family      = splCommand[2],
                                CommandName = splCommand[3],
                                Database    = splCommand[4],
                                Record      = splCommand[5],
                                Field       = splCommand[6],
                                TEID        = Convert.ToInt32(splCommand[7]),
                                Value       = splCommand[8],
                                IssuedOn    = DateTime.Parse(splStr[7] + " " + splStr[8] + " " + splStr[9])
                            });
                        }
                    }
            Invoke((MethodInvoker) delegate
            {
                EMSCommands.Clear();
                AddCommands(NewCommands.ToArray(), Servers[cmbServer.SelectedItem.ToString()]);
            });
        }
Пример #2
0
        /// <summary>
        /// Process a stream, reading and parsing its content
        /// </summary>
        /// <param name="InLines"></param>
        /// <param name="FileName"></param>
        public static void ProcessStreamRead(StreamReader sRd, String FileName, Type TargetType, ref DateTime LatestBatchID)
        {
            //Now, parse our stream
            IList OutList = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(TargetType));

            //Read our header
            String FirstLine = sRd.ReadLine().TrimStart('#').TrimEnd(',');

            String[] HeaderLine;
            Double   ProperDate;
            DateTime BatchId = DateTime.Now;

            if (Double.TryParse(FirstLine, out ProperDate))
            {
                BatchId    = new DateTime(1970, 1, 1).AddSeconds(ProperDate);
                HeaderLine = sRd.ReadLine().TrimStart('#').Split(',');
            }
            else
            {
                HeaderLine = FirstLine.Split(',');
            }

            if (BatchId < LatestBatchID)
            {
                MM_Notification.WriteLine(ConsoleColor.Red, "Aborting {0} Batch {1} because it's older than {1}", FileName, BatchId, LatestBatchID);
                return;
            }
            else
            {
                LatestBatchID = BatchId;
            }

            PropertyInfo[] HeaderInfo = MM_Serialization.GetHeaderInfo(TargetType, HeaderLine);
            for (int a = 0; a < HeaderLine.Length; a++)
            {
                if (HeaderInfo[a] == null)
                {
                    MM_Notification.WriteLine(ConsoleColor.Yellow, "Unknown variable {0} in {1}", HeaderLine[a], FileName);
                }
            }

            //Confirm all of our headers are present
            foreach (PropertyInfo pI in TargetType.GetProperties())
            {
                if (Array.FindIndex <String>(HeaderLine, T => T.Equals(pI.Name, StringComparison.CurrentCultureIgnoreCase)) == -1)
                {
                    MM_Notification.WriteLine(ConsoleColor.Yellow, "Missing variable {0} ({1}) in {2} / {3}", pI.Name, pI.PropertyType.Name, TargetType.Name, FileName);
                }
            }

            //Now, read in all of our lines of data, using reflection to store our data
            String InLine;

            while ((InLine = sRd.ReadLine()) != null)
            {
                if (InLine.StartsWith("#"))
                {
                    DateTime EndTime = new DateTime(1970, 1, 1).AddSeconds(Convert.ToDouble(InLine.TrimStart('#').TrimEnd(',')));
                    if (EndTime != BatchId)
                    {
                        MM_Notification.WriteLine(ConsoleColor.Red, "Mismatch date on {0}: Start {1}, End {2}", FileName, BatchId, EndTime);
                    }
                }
                else
                {
                    Object OutObj = MM_Serialization.Deserialize(HeaderInfo, InLine.Split(','), Activator.CreateInstance(TargetType));
                    //if (OutObj is MacomberMapCommunications.Messages.EMS.MM_BreakerSwitch_Data)
                    //{
                    //    MacomberMapCommunications.Messages.EMS.MM_BreakerSwitch_Data bs = (MacomberMapCommunications.Messages.EMS.MM_BreakerSwitch_Data)OutObj;
                    //    if (bs.TEID_CB == 118964)
                    //        MM_Notification.WriteLine(ConsoleColor.Magenta, "   TEID=" + bs.TEID_CB.ToString() + "    status=" + (bs.Open_CB ? "Open" : "Closed"));
                    //}
                    OutList.Add(OutObj);
                }
            }

            //Once our data are done, use the interprocess communication to update our data
            if (TargetType == typeof(MM_EMS_Command))
            {
                MM_Server.EMSCommands.Clear();
                foreach (Object obj in OutList)
                {
                    MM_Server.EMSCommands.Add((MM_EMS_Command)obj);
                }
            }
            else
            {
                MM_EMS_Data_Updater.ProcessUpdate(TargetType, (Array)OutList.GetType().GetMethod("ToArray").Invoke(OutList, null));
            }
            OutList.Clear();
            OutList = null;
        }
Пример #3
0
        static void Main(string[] args)
        {
            string InFileName  = null;
            string OutFileName = null;
            string InLine;

            string[]     HpglCommands;
            string       HpglCode;
            StreamReader InFile;
            StreamWriter OutFile;

            Settings settings  = new Settings();
            ArgProc  arguments = new ArgProc(args, settings);

            // test

            /*
             * Console.WriteLine("Arguments:");
             * for (int i = 0; i < arguments.ArgCount; i++)
             * {
             *  Console.WriteLine("[" + i.ToString() + "] " + arguments[i]);
             * }
             * Console.WriteLine("Switches:");
             * foreach (string switchKey in arguments.SwitchKeys)
             * {
             *  Console.WriteLine("[" + switchKey + "] " + arguments[switchKey]);
             * }
             */
            // end test



            double HpglPpmm = arguments["HpglPpmm"].ToDouble(); // Hpgl Points per mm
            //double Speed = arguments["Speed"].ToDouble();
            Cordinate CurrentXY;
            Cordinate CenterXY = new Cordinate(0, 0);;
            double    Angle;
            double    Alpha;
            Cordinate XY = new Cordinate(0, 0);
            double    R;
            Cordinate IJ;

            string[] HpglParams;
            bool     IsDrawing = false;

            Console.WriteLine("HPGL to GCODE Converter v0.1 alpha - Copyright (C) 2017 by SUF");
            Console.WriteLine("This program is free software: you can redistribute it and / or modify");
            Console.WriteLine("it under the terms of the GNU General Public License as published by");
            Console.WriteLine("the Free Software Foundation, either version 3 of the License, or");
            Console.WriteLine("any later version.");

            if (arguments.ArgCount == 2)
            {
                InFileName  = arguments[0];
                OutFileName = arguments[1];
            }
            else
            {
                InFileName  = arguments["Source"];
                OutFileName = arguments["Destination"];
            }
            if (InFileName != null && OutFileName != null)
            {
                InFile  = new StreamReader(InFileName);
                OutFile = new StreamWriter(OutFileName);
                // Write header
                OutFile.WriteLine("G21");
                OutFile.WriteLine(arguments["PenUp"]);
                IsDrawing = false;
                if (!ArgProc.GetBool(arguments["IgnoreSpeed"]))
                {
                    OutFile.WriteLine("G1 F" + arguments["Speed"]);
                }
                OutFile.WriteLine("G28 " + arguments["HomeAxes"]);
                CurrentXY = new Cordinate(0, 0);
                while (!InFile.EndOfStream)
                {
                    InLine       = InFile.ReadLine();
                    HpglCommands = InLine.Split(';');
                    foreach (string HpglCommand in HpglCommands)
                    {
                        if (HpglCommand.Trim().Length > 1)
                        {
                            HpglCode = HpglCommand.Trim().Substring(0, 2);
                            switch (HpglCode)
                            {
                            case "PU":      // Pen Up
                                OutFile.WriteLine(arguments["PenUp"]);
                                IsDrawing = false;
                                CurrentXY = DrawPoly(OutFile, HpglPpmm, HpglCommand.Substring(2).Trim(), false);
                                break;

                            case "PD":     // Pen Down
                                OutFile.WriteLine(arguments["PenDown"]);
                                IsDrawing = true;
                                CurrentXY = DrawPoly(OutFile, HpglPpmm, HpglCommand.Substring(2).Trim(), true);
                                break;

                            case "VS":     // Velocity Set
                                if (!ArgProc.GetBool(arguments["IgnoreVelocity"]))
                                {
                                    OutFile.WriteLine("G1 F" + (HpglCommand.Substring(2).ToDouble() * arguments["VelocityScale"].ToDouble()).ToIString());
                                }
                                break;

                            case "IN":     // Start
                                break;

                            case "SP":
                                break;

                            case "PA":     // Position Absolute
                                XY        = CurrentXY;
                                CurrentXY = DrawPoly(OutFile, HpglPpmm, HpglCommand.Substring(2).Trim(), IsDrawing);
                                CurrentXY = XY;
                                break;

                            case "CI":      // Circle
                                // Parse radius
                                R = HpglCommand.Substring(2).Trim().ToDouble() / HpglPpmm;
                                // Move negative X by Radius to arrive to the arc
                                OutFile.WriteLine("G0 X" + (CurrentXY.X - R).ToIString());
                                // Pen down - there is no PD command before CI, it assume that you draw the circle
                                OutFile.WriteLine(arguments["PenDown"]);
                                IsDrawing = true;
                                // Draw the circle
                                OutFile.WriteLine("G2 I" + R.ToIString());
                                CurrentXY.X -= R;
                                break;

                            case "AA":     // Arc Absolute
                                // gather the parameters
                                HpglParams = HpglCommand.Substring(2).Trim().Split(',');
                                CenterXY.X = HpglParams[0].ToDouble() / HpglPpmm;
                                CenterXY.Y = HpglParams[1].ToDouble() / HpglPpmm;
                                Angle      = HpglParams[2].ToDouble();
                                // calculate the relative center point (I,J)
                                IJ = CenterXY - CurrentXY;
                                // calculate the radius (pythagorean theorem)
                                R = Math.Sqrt(Math.Pow(IJ.X, 2) + Math.Pow(IJ.Y, 2));
                                // calculate the angle between start point and the X axis
                                Alpha = DegMath.Asin((CurrentXY.Y - CenterXY.Y) / R);
                                // extend the -90 to 90 degree angle to -270 to 90
                                if (CurrentXY.X < CenterXY.X)
                                {
                                    Alpha = -180 - Alpha;
                                }
                                // calculate the arc end absolute cordinates
                                XY.X = CenterXY.X + R * DegMath.Cos(Angle + Alpha);
                                XY.Y = CenterXY.Y + R * DegMath.Sin(Angle + Alpha);
                                // generate the gcode
                                // the positive angles moves CCV, the negative angles move CV
                                OutFile.WriteLine((Angle > 0 ? "G3 X" : "G2 X") + XY.XString + " Y" + XY.YString + " I" + IJ.XString + " J" + IJ.YString);
                                // Save the cordinates
                                CurrentXY = XY;
                                break;

                            default:
                                // Unknown or unimplemented command arrived
                                Console.WriteLine("Warrning: Unknown Command: " + HpglCommand);
                                break;
                            }
                        }
                    }
                }
                OutFile.Flush();
                OutFile.Close();
                InFile.Close();
            }
            else
            {
                if (InFileName == null)
                {
                    Console.WriteLine("Command line error: Source file missing");
                }
                if (OutFileName == null)
                {
                    Console.WriteLine("Command line error: Destination file missing");
                }
            }
        }