Beispiel #1
0
        private void CmdSende_Click(object sender, EventArgs e)
        {
            try
            {
                String telegram = (char)0x02 + TbTelegram.Text + (char)0x03;
                byte[] msg      = Encoding.ASCII.GetBytes(telegram);

                int bytesSent = rxdSocket.Send(msg);
                TbRxd.AppendText(ReplaceSonder(telegram) + Environment.NewLine);
                TbRxd.ScrollToCaret();

                TbTelegram.Text = "";
            }
            catch (Exception ex)
            {
                TbRxd.AppendText(Environment.NewLine + ex.Message);
                TbRxd.ScrollToCaret();
            }
        }
Beispiel #2
0
        public void StartRxd()
        {
            // Data buffer for incoming data.
            byte[] bytes = new byte[1024];
            while (true)
            {
                try
                {
                    int bytesRec = rxdSocket.Receive(bytes);

                    if (bytesRec > 0)
                    {
                        TbRxd.Invoke(new Action(() =>
                        {
                            String qTelegram = Encoding.ASCII.GetString(bytes, 0, bytesRec);

                            TbRxd.AppendText(ReplaceSonder(qTelegram + Environment.NewLine + Environment.NewLine));

                            TbTelegram.Text = (Convert.ToInt16(qTelegram.Substring(1, 2)) + 1).ToString("00") + qTelegram.Substring(3, 6);

                            TbRxd.ScrollToCaret();
                        }));
                    }
                }
                catch (ArgumentNullException ane)
                {
                    Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
                }
                catch (SocketException se)
                {
                    Console.WriteLine("SocketException : {0}", se.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Unexpected exception : {0}", e.ToString());
                }
            }
        }