Ejemplo n.º 1
0
 private void BtnSend_Click(object sender, RoutedEventArgs e)
 {
     if (tbMessage.Text != string.Empty)
     {
         var msg = tbMessage.Text;
         SocketServerEx.Send(msg);
         tbMessage.Text       = string.Empty;
         tbConsoleOutput.Text = tbConsoleOutput.Text + DateTime.Now.ToString("h:mm:ss tt") + " Server:\n" + msg + "\n";
     }
 }
Ejemplo n.º 2
0
 private void btnSend_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(tbPayLoad.Text))
     {
         return;
     }
     try
     {
         tbConsoleOutPut.Text = DateTime.Now.ToString("h:mm:ss tt") + " Server: " + tbPayLoad.Text + "\n" + tbConsoleOutPut.Text;
         SocketServerEx.Send(tbPayLoad.Text);
         tbPayLoad.Text = "";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Ejemplo n.º 3
0
        private void SocketServer_NewMessage2Event(System.Net.IPEndPoint remoteIpEndPoint, string Message)
        {
            SimpleLogHelper.Instance.WriteLog(LogType.Info, Message);
            SimpleLogHelper.Instance.WriteLog(LogType.Info, Message.Length);
            //验证
            string          commandText = "SELECT TOP 1 [正累积流量] AS 'Water' FROM Water ORDER BY [更新时间] DESC";
            List <TSKModel> models      = sql.GetDataTable <TSKModel>(commandText);

            if (models != null)
            {
                string a = MathHelper.SingleToHex(models[0].Water);
                Debug.WriteLine(a);
                string backdata = Message.Substring(0, 4);
                backdata += MathHelper.DecToHex((int.Parse(Message.Substring(10, 2)) * 2)
                                                .ToString()).PadLeft(2, '0');
                backdata += a;
                backdata += CRC.ToModbusCRC16(backdata);
                SimpleLogHelper.Instance.WriteLog(LogType.Info, "返回的数据是:" + backdata);
                socketServer.Send(remoteIpEndPoint, MathHelper.StrToHexByte(backdata));
            }
        }