Пример #1
0
        private void WriteOut_Prepare(out FanucChunk[] chunks, ref string data, FanucSocketOptions options)
        {
            if (!options.HasFlag(FanucSocketOptions.RawMode))
            {
                WriteOut_ToLF(ref data);              // Correct newlines
                WriteOut_Sanitize(ref data, options); // Sanitize data
            }

            WriteOut_ChunkData(out chunks, data);
        }
Пример #2
0
        /// <summary>
        /// Parses the data and keeps a state
        /// </summary>
        /// <param name="chunk">The chunk to process</param>
        /// <param name="options">Processing options</param>
        static private void ReadIn_ParseData(ref FanucChunk chunk, FanucSocketOptions options)
        {
            if (!options.HasFlag(FanucSocketOptions.RawMode))
            {
                if (!options.HasFlag(FanucSocketOptions.IgnoreControlCodes))
                {
                    ReadIn_ClipBlock(ref chunk);
                }

                if (options.HasFlag(FanucSocketOptions.FixNewline) && chunk.State != FanucChunkState.Error)
                {
                    ReadIn_ToCRLF(ref chunk);
                }
            }
            if (chunk.State == FanucChunkState.ReadyForProcessing)
            {
                chunk.State = FanucChunkState.Processed;
            }
        }
Пример #3
0
        /// <summary>
        /// Santizes data before sending it out. Needs some work
        /// </summary>
        /// <param name="data">The data string</param>
        static private void WriteOut_Sanitize(ref string data, FanucSocketOptions options)
        {
            //Remove control codes left over in old files
            data = Regex.Replace(data, @"[\x11-\x14]", "");

            if (!options.HasFlag(FanucSocketOptions.NoStartBlock))
            {
                // Trim junk to the first program block
                Match m = Regex.Match(data, @"[:oO][\d]{4}");

                if (m != null)
                {
                    data = data.Substring(m.Index);
                    data = "%\n" + data;
                }
                else
                {
                    throw new FanucException("No sub-programs found!");
                }
            }
            if (!options.HasFlag(FanucSocketOptions.NoEndBlock))
            {
                Match m = Regex.Match(data, "%", RegexOptions.RightToLeft);

                //If it found a % (it better i JUST put one there)
                if (m.Index != 0)
                {
                    data = data.Substring(0, m.Index + 1);
                }
                else
                {
                    //Fix this, its a 2AM hack.
                    data += "%"; // Append one to the end
                }
            }
        }
Пример #4
0
        private void WriteOut_Prepare(out FanucChunk[] chunks, ref string data, FanucSocketOptions options)
        {
            if (!options.HasFlag(FanucSocketOptions.RawMode))
            {
                WriteOut_ToLF(ref data); // Correct newlines
                WriteOut_Sanitize(ref data, options); // Sanitize data
            }

            WriteOut_ChunkData(out chunks, data);
        }
Пример #5
0
        /// <summary>
        /// Locks access to the socket and does a read operation. If data has arrived, it is checked for Fanuc
        ///  control codes and saved to memory.
        /// </summary>
        /// <returns>A FanucChunk with the complete data and status</returns>
        private void ReadIn_Main(FanucSocketOptions options)
        {
            FanucChunk chunk;

            opCancelToken.ThrowIfCancellationRequested();

            chunk = new FanucChunk(0);

            ChangeState(FanucSocketState.Receiving);

            while (!opCancelToken.IsCancellationRequested)
            {
                if (ns.DataAvailable)
                {
                    ReadIn_GetData(ref chunk);

                    if (chunk.State == FanucChunkState.ReadyForProcessing)
                    {
                        ReadIn_ParseData(ref chunk, options);
                    }

                    if (chunk.State == FanucChunkState.Processed)
                    {
                        if (ChunkReceived != null) ChunkReceived.Invoke(this, chunk.Data);
                    }
                    else if (chunk.State == FanucChunkState.Error)
                    {
                        if (BadChunkReceived != null) BadChunkReceived.Invoke(this, chunk.Data);
                    }

                    if (!options.HasFlag(FanucSocketOptions.IgnoreControlCodes))
                        if ((int)chunk.PersistentExtra == 0x14)
                            return;

                    chunk = new FanucChunk(chunk);
                }
                else
                {
                    Thread.Sleep(500);
                }

                opCancelToken.ThrowIfCancellationRequested();
            }

            opCancelToken.ThrowIfCancellationRequested();
        }
Пример #6
0
        /// <summary>
        /// Santizes data before sending it out. Needs some work
        /// </summary>
        /// <param name="data">The data string</param>
        private static void WriteOut_Sanitize(ref string data, FanucSocketOptions options)
        {
            //Remove control codes left over in old files
            data = Regex.Replace(data, @"[\x11-\x14]", "");

            if (!options.HasFlag(FanucSocketOptions.NoStartBlock))
            {
                // Trim junk to the first program block
                Match m = Regex.Match(data, @"[:oO][\d]{4}");

                if (m != null)
                {
                    data = data.Substring(m.Index);
                    data = "%\n" + data;
                }
                else
                {
                    throw new FanucException("No sub-programs found!");
                }
            }
            if (!options.HasFlag(FanucSocketOptions.NoEndBlock))
            {
                Match m = Regex.Match(data, "%", RegexOptions.RightToLeft);

                //If it found a % (it better i JUST put one there)
                if (m.Index != 0)
                {
                    data = data.Substring(0, m.Index + 1);
                }
                else
                {
                    //Fix this, its a 2AM hack.
                    data += "%"; // Append one to the end
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Parses the data and keeps a state
        /// </summary>
        /// <param name="chunk">The chunk to process</param>
        /// <param name="options">Processing options</param>
        private static void ReadIn_ParseData(ref FanucChunk chunk, FanucSocketOptions options)
        {
            if (!options.HasFlag(FanucSocketOptions.RawMode))
            {
                if (!options.HasFlag(FanucSocketOptions.IgnoreControlCodes))
                {
                    ReadIn_ClipBlock(ref chunk);
                }

                if (options.HasFlag(FanucSocketOptions.FixNewline) && chunk.State != FanucChunkState.Error)
                {
                    ReadIn_ToCRLF(ref chunk);
                }
            }
            if (chunk.State == FanucChunkState.ReadyForProcessing)
            {
                chunk.State = FanucChunkState.Processed;
            }
        }