Esempio n. 1
0
        // Autogenerated signature.
        private void Poll(object sender, ElapsedEventArgs e)
        {
            byte[] buffer       = new byte[bufferLength];
            int    bytesRecived = NativeMethods.poll_COM_port(buffer, bufferLength);

            if (bytesRecived < 0)
            {
                // Negative length- error has occurred.
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            else if (bytesRecived > 0)
            {
                if (DataRecived != null)
                {
                    // Crop buffer to only include recived characters.
                    byte[] croppedBuffer = new byte[bytesRecived];
                    Array.Copy(buffer, croppedBuffer, bytesRecived);

                    DataRecived?.Invoke(this, new DataRecivedEventArgs(croppedBuffer));
                }

                if (bytesRecived == bufferLength)
                {
                    // Data may exceed buffer size. Poll until all data has been read.
                    Poll(this, e);
                }
            }
        }
Esempio n. 2
0
        private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string message = serialPort.ReadLine();

            DataRecived?.Invoke(message);
            mainForm.addOutputString(message);
            mainForm.addControlDebugString("message was got");
        }
        private void SendData()
        {
            DetectingEventArgs data = new DetectingEventArgs
            {
                AverageMotions = (int)average_motions,
                AveragePixels  = average_pixels,
                TimeStart      = _cycleStart,
                TimeFinish     = DateTime.Now,
                TotalCount     = total_count,
                DataSource     = _connectionString
            };

            DataRecived?.Invoke(this, data); //если есть подписчик, то передаем ему данные
        }
Esempio n. 4
0
        public override void OnMessage(byte[] data)
        {
            if (!_isOpened)
            {
                _receiveMessages.WaitOne();
            }

            Console.WriteLine("Connection message bytes");

            DataRecived.Invoke(this, new SimpleEventArgs <byte[]>()
            {
                Value = data
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Read Data
        /// </summary>
        /// <param name="eventClientHandleName"></param>
        private void ReadData(string eventClientHandleName)
        {
            using (var readEventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventClientHandleName))
            {
                var data = m_JsonShmReceiver.LoadFromSharedMemory();
                if (data != null)
                {
                    ReciveQueue.Enqueue(data);

                    DataRecived?.Invoke(this, EventArgs.Empty);
                }

                readEventWaitHandle.Set();
            }
        }
Esempio n. 6
0
        public void ReadCallback(IAsyncResult ar)
        {
            string content = string.Empty;

            // Retrieve the state object and the handler socket
            // from the asynchronous state object.
            StateObject state     = (StateObject)ar.AsyncState;
            Socket      handler   = state.workSocket;
            int         bytesRead = 0;

            try
            {
                if (!((handler.Poll(1000, SelectMode.SelectRead) && (handler.Available == 0)) || !handler.Connected))
                {
                    // Read data from the client socket.
                    bytesRead = handler.EndReceive(ar);
                }
                else
                {
                    LogRecived?.Invoke(LogTypes.ClientDisconnected, string.Format("Client {0} is now disconected: ", handler.IpAdress()));
                    OnClientDisConnect?.Invoke(handler.IpAdress());
                }
            }
            catch (Exception ex)
            {
                LogRecived?.Invoke(LogTypes.Error, ex.ToString());
            }

            if (bytesRead > 0)
            {
                // There  might be more data, so store the data received so far.
                //state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
                //content = Encoding.Unicode.GetString(state.buffer, 0, bytesRead);

                for (int i = 0; i < bytesRead; i++)
                {
                    content += (char)state.buffer[i];
                }

                handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);

                DataRecived?.Invoke(((IPEndPoint)(((StateObject)(ar.AsyncState)).workSocket.RemoteEndPoint)).Address.ToString(), content);
            }
        }
Esempio n. 7
0
        public Connection(string uri)
        {
            _webSocket = new WebSocket(uri);

            _webSocket.Opened += (sender, args) =>
            {
                Console.WriteLine("OPENED");
                _reconnect.Reset();

                ConnectionStateChanged.Invoke(this, new SimpleEventArgs <bool>(true));
            };

            _webSocket.Error += (sender, args) =>
            {
                Console.WriteLine("ERROR");
                _reconnect.Set();
            };

            _webSocket.Closed += (sender, args) =>
            {
                Console.WriteLine("CLOSED");
                _reconnect.Set();

                ConnectionStateChanged.Invoke(this, new SimpleEventArgs <bool>(false));
            };

            _webSocket.MessageReceived += (sender, args) =>
            {
                MessageRecived.Invoke(this, new SimpleEventArgs <string>()
                {
                    Value = args.Message
                });
            };

            _webSocket.DataReceived += (sender, args) =>
            {
                DataRecived.Invoke(this, new SimpleEventArgs <byte[]>()
                {
                    Value = args.Data
                });
            };
        }
Esempio n. 8
0
 public void setError(string data)
 {
     DataRecived?.Invoke(this, new DataRecivedEventArgs {
         Data = data, IsError = RecivedDataType.Error
     });
 }
Esempio n. 9
0
 public void setData(string data, string id)
 {
     DataRecived?.Invoke(this, new DataRecivedEventArgs {
         Data = data, Id = id
     });
 }
 private void OnControllerDataRecived(object sender, DetectingEventArgs e)
 {
     DataRecived?.Invoke(this, e);
 }