예제 #1
0
        /// <summary>
        /// Создание нового фрейма
        /// </summary>
        /// <param name="deviceId">id устройства</param>
        /// <param name="command">команда</param>
        /// <param name="messageBody">даннфе команды</param>
        /// <returns></returns>
        public static TrackerFrame NewFrame(string deviceId, TrackerCommand command, string messageBody)
        {
            var data = new List <byte> {
                BeginFrame, Convert.ToByte('0')
            };

            data.AddRange(Encoding.ASCII.GetBytes(deviceId));
            data.AddRange(command.BlockData);
            data.AddRange(Encoding.ASCII.GetBytes(messageBody));
            data.Add(EndFrame);
            return(new TrackerFrame(data.ToArray()));
        }
예제 #2
0
        /// <summary>
        /// Отправка фрейма данных
        /// </summary>
        /// <param name="command"></param>
        /// <param name="messageBody"></param>
        protected void SendFrame(TrackerCommand command, string messageBody)
        {
            TrackerFrame frame = null;

            try
            {
                frame = CreateFrame(command, messageBody);
                Logger.InfoFormat("Отправка фрейма {0}", frame.ToString());
                TcpClient.Client.Send(frame.BlockData);
            }
            catch (Exception ex)
            {
                Logger.Error(String.Format("Ошибка при отправке фрейма {0}", frame == null ? "(фрейм не создан)" : frame.ToString()), ex);
            }
        }
예제 #3
0
 /// <summary>
 /// Создание фрейма команды
 /// </summary>
 /// <param name="command"></param>
 /// <param name="messageBody"></param>
 /// <returns></returns>
 public TrackerFrame CreateFrame(TrackerCommand command, string messageBody)
 {
     return(TrackerFrame.NewFrame(DeviceId, command, messageBody));
 }
예제 #4
0
 /// <summary>
 /// Отправка фрейма данных
 /// </summary>
 /// <param name="command"></param>
 protected void SendFrame(TrackerCommand command)
 {
     SendFrame(command, "");
 }