Exemple #1
0
        /// <summary>
        /// Send data.
		/// </summary>
		/// <param name="eventSender"></param>
		/// <param name="eventArgs"></param>
		private void SendBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
		{
            try
            {
                ReceivedText.Text = string.Empty;
                if (SyncBtn.Checked) // Sends data synchronously.
                {
                    if (HexCB.Checked)
                    {
                        // Sends data as byte array.                        
                        lock (gxTerminal1.Synchronous)
                        {
                            Gurux.Common.ReceiveParameters<byte[]> p = new Gurux.Common.ReceiveParameters<byte[]>()
                            {
                                WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                                Eop = EOPText.Text,
                                Count = Convert.ToInt32(MinSizeTB.Text)
                            };
                            gxTerminal1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text));
                            if (gxTerminal1.Receive(p))
                            {
                                ReceivedText.Text = Convert.ToString(p.Reply);
                            }
                        }
                    }
                    else
                    {
                        // Sends data as ASCII string.
                        lock (gxTerminal1.Synchronous)
                        {
                            Gurux.Common.ReceiveParameters<string> p = new Gurux.Common.ReceiveParameters<string>()
                            {
                                WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                                Eop = EOPText.Text,
                                Count = Convert.ToInt32(MinSizeTB.Text)
                            };
                            gxTerminal1.Send(SendText.Text);
                            if (gxTerminal1.Receive(p))
                            {
                                ReceivedText.Text = Convert.ToString(p.Reply);
                            }
                        }
                    }
                }
                else // Sends data asynchronously.
                {
                    if (HexCB.Checked)
                    {
                        // Sends data as byte array.
                        gxTerminal1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text));
                    }
                    else
                    {
                        // Sends data as ASCII string.
                        gxTerminal1.Send(SendText.Text);
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemple #2
0
 /// <summary>
 /// Send data.
 /// </summary>
 /// <param name="eventSender"></param>
 /// <param name="eventArgs"></param>
 private void SendBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
 {
     try
     {
         ReceivedText.Text = string.Empty;
         if (SyncBtn.Checked) // Sends data synchronously.
         {
             if (HexCB.Checked)
             {
                 // Sends data as byte array.
                 lock (Net1.Synchronous)
                 {
                     Gurux.Common.ReceiveParameters <byte[]> p = new Gurux.Common.ReceiveParameters <byte[]>()
                     {
                         WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                         Eop      = EOPText.Text,
                     };
                     Net1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text), null);
                     if (Net1.Receive(p))
                     {
                         ReceivedText.Text = Convert.ToString(p.Reply);
                     }
                 }
             }
             else
             {
                 // Sends data as ASCII string.
                 lock (Net1.Synchronous)
                 {
                     Gurux.Common.ReceiveParameters <string> p = new Gurux.Common.ReceiveParameters <string>()
                     {
                         WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                         Eop      = EOPText.Text,
                     };
                     Net1.Send(SendText.Text, null);
                     if (Net1.Receive(p))
                     {
                         ReceivedText.Text = Convert.ToString(p.Reply);
                     }
                 }
             }
         }
         else // Sends data asynchronously.
         {
             if (HexCB.Checked)
             {
                 // Sends data as byte array.
                 Net1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text), null);
             }
             else
             {
                 // Sends data as ASCII string.
                 Net1.Send(SendText.Text, null);
             }
         }
     }
     catch (Exception Ex)
     {
         //disable timer is exists
         if (IntervalTimer.Enabled)
         {
             IntervalBtn_Click(IntervalBtn, new System.EventArgs());
         }
         MessageBox.Show(Ex.Message);
     }
 }
Exemple #3
0
        /// <summary>
        /// Sends data to the serial port.
        /// </summary>
        /// <param name="eventSender"></param>
        /// <param name="eventArgs"></param>
        private void SendBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
        {
            try
            {
                ReceivedText.Text = string.Empty;
                if (SyncBtn.Checked) // Sends data synchronously.
                {
                    if (HexCB.Checked)
                    {
                        // Sends data as byte array.
                        lock (gxSerial1.Synchronous)
                        {
                            Gurux.Common.ReceiveParameters <byte[]> p = new Gurux.Common.ReceiveParameters <byte[]>()
                            {
                                WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                                Count    = Convert.ToInt32(MinSizeTB.Text)
                            };
                            // Sends data as ASCII string.
                            if (EOPText.Text == "\\r")
                            {
                                p.Eop = '\r';
                            }
                            else if (EOPText.Text == "\\n")
                            {
                                p.Eop = '\n';
                            }
                            else if (EOPText.Text == "\\r\\n")
                            {
                                p.Eop = "\r\n";
                            }
                            else
                            {
                                p.Eop = EOPText.Text;
                            }

                            gxSerial1.Send(GXCommon.HexToBytes(SendText.Text));
                            if (gxSerial1.Receive(p))
                            {
                                ReceivedText.Text = GXCommon.ToHex(p.Reply, true);
                            }
                        }
                    }
                    else
                    {
                        // Sends data as ASCII string.
                        lock (gxSerial1.Synchronous)
                        {
                            Gurux.Common.ReceiveParameters <string> p = new Gurux.Common.ReceiveParameters <string>()
                            {
                                WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                                Count    = Convert.ToInt32(MinSizeTB.Text)
                            };
                            // Sends data as ASCII string.
                            if (EOPText.Text == "\\r")
                            {
                                p.Eop = '\r';
                            }
                            else if (EOPText.Text == "\\n")
                            {
                                p.Eop = '\n';
                            }
                            else if (EOPText.Text == "\\r\\n")
                            {
                                p.Eop = "\r\n";
                            }
                            else
                            {
                                p.Eop = EOPText.Text;
                            }

                            gxSerial1.Send(SendText.Text);
                            if (gxSerial1.Receive(p))
                            {
                                ReceivedText.Text = Convert.ToString(p.Reply);
                            }
                        }
                    }
                }
                else // Sends data asynchronously.
                {
                    if (HexCB.Checked)
                    {
                        // Sends data as byte array.
                        gxSerial1.Send(GXCommon.HexToBytes(SendText.Text));
                    }
                    else
                    {
                        string data = SendText.Text;
                        gxSerial1.Send(data);
                    }
                    // Sends data as ASCII string.
                    if (EOPText.Text == "\\r")
                    {
                        gxSerial1.Send('\r');
                    }
                    else if (EOPText.Text == "\\n")
                    {
                        gxSerial1.Send('\n');
                    }
                    else if (EOPText.Text == "\\r\\n")
                    {
                        gxSerial1.Send("\r\n");
                    }
                    else if (EOPText.Text.Length != 0)
                    {
                        gxSerial1.Send(EOPText.Text);
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemple #4
0
 /// <summary>
 /// Send data.
 /// </summary>
 /// <param name="eventSender"></param>
 /// <param name="eventArgs"></param>
 private void SendBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
 {
     try
     {
         ReceivedText.Text = string.Empty;
         if (SyncBtn.Checked) // Sends data synchronously.
         {
             if (HexCB.Checked)
             {
                 // Sends data as byte array.
                 lock (gxTerminal1.Synchronous)
                 {
                     Gurux.Common.ReceiveParameters <byte[]> p = new Gurux.Common.ReceiveParameters <byte[]>()
                     {
                         WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                         Eop      = EOPText.Text,
                         Count    = Convert.ToInt32(MinSizeTB.Text)
                     };
                     gxTerminal1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text));
                     if (gxTerminal1.Receive(p))
                     {
                         ReceivedText.Text = Convert.ToString(p.Reply);
                     }
                 }
             }
             else
             {
                 // Sends data as ASCII string.
                 lock (gxTerminal1.Synchronous)
                 {
                     Gurux.Common.ReceiveParameters <string> p = new Gurux.Common.ReceiveParameters <string>()
                     {
                         WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                         Eop      = EOPText.Text,
                         Count    = Convert.ToInt32(MinSizeTB.Text)
                     };
                     gxTerminal1.Send(SendText.Text);
                     if (gxTerminal1.Receive(p))
                     {
                         ReceivedText.Text = Convert.ToString(p.Reply);
                     }
                 }
             }
         }
         else // Sends data asynchronously.
         {
             if (HexCB.Checked)
             {
                 // Sends data as byte array.
                 gxTerminal1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text));
             }
             else
             {
                 // Sends data as ASCII string.
                 gxTerminal1.Send(SendText.Text);
             }
         }
     }
     catch (Exception Ex)
     {
         MessageBox.Show(Ex.Message);
     }
 }
Exemple #5
0
 /// <summary>
 /// Send data.
 /// </summary>
 /// <param name="eventSender"></param>
 /// <param name="eventArgs"></param>
 private void SendBtn_Click(System.Object eventSender, System.EventArgs eventArgs)
 {
     try
     {
         ReceivedText.Text = string.Empty;
         if (SyncBtn.Checked) // Sends data synchronously.
         {
             if (HexCB.Checked)
             {
                 // Sends data as byte array.                        
                 lock (Net1.Synchronous)
                 {
                     Gurux.Common.ReceiveParameters<byte[]> p = new Gurux.Common.ReceiveParameters<byte[]>()
                     {
                         WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                         Eop = EOPText.Text,                                
                     };
                     Net1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text), null);
                     if (Net1.Receive(p))
                     {
                         ReceivedText.Text = Convert.ToString(p.Reply);
                     }
                 }
             }
             else
             {
                 // Sends data as ASCII string.
                 lock (Net1.Synchronous)
                 {
                     Gurux.Common.ReceiveParameters<string> p = new Gurux.Common.ReceiveParameters<string>()
                     {
                         WaitTime = Convert.ToInt32(WaitTimeTB.Text),
                         Eop = EOPText.Text,                                
                     };
                     Net1.Send(SendText.Text, null);
                     if (Net1.Receive(p))
                     {
                         ReceivedText.Text = Convert.ToString(p.Reply);
                     }
                 }
             }
         }
         else // Sends data asynchronously.
         {
             if (HexCB.Checked)
             {
                 // Sends data as byte array.
                 Net1.Send(ASCIIEncoding.ASCII.GetBytes(SendText.Text), null);
             }
             else
             {
                 // Sends data as ASCII string.
                 Net1.Send(SendText.Text, null);
             }
         }
     }
     catch (Exception Ex)
     {
         //disable timer is exists
         if (IntervalTimer.Enabled)
         {
             IntervalBtn_Click(IntervalBtn, new System.EventArgs());
         }
         MessageBox.Show(Ex.Message);
     }
 }