Exemple #1
0
        /// <summary>
        /// Execute a command
        /// </summary>
        /// <param name="method"></param>
        /// <param name="id"></param>
        /// <param name="parameters"></param>
        public void ExecuteCommand(METHODS method, int id = 0, List <object> parameters = null)
        {
            if (!IsMethodSupported(method))
            {
                throw new InvalidOperationException($"The operation {method.GetRealName()} is not allowed by the device");
            }

            Command command = new Command()
            {
                Id     = id,
                Method = method.GetRealName(),
                Params = parameters ?? new List <object>()
            };

            string data = JsonConvert.SerializeObject(command, Constants.DeviceSerializerSettings);

            byte[] sentData = Encoding.ASCII.GetBytes(data + Constants.LineSeparator); // \r\n is the end of the message, it needs to be sent for the message to be read by the device

            lock (_syncLock)
            {
                _tcpClient.Client.Send(sentData);
            }
        }
Exemple #2
0
        /// <summary>
        /// Execute a command
        /// </summary>
        /// <param name="method"></param>
        /// <param name="id"></param>
        /// <param name="parameters"></param>
        /// <param name="smooth"></param>
        public void ExecuteCommand(METHODS method, int id = 0, List <object> parameters = null)
        {
            Command command = new Command()
            {
                Id     = id,
                Method = method.GetRealName(),
                Params = parameters ?? new List <object>()
            };

            string data = JsonConvert.SerializeObject(command, _serializerSettings);

            byte[] sentData = Encoding.ASCII.GetBytes(data + Constantes.LineSeparator); // \r\n is the end of the message, it needs to be sent for the message to be read by the device

            lock (_syncLock)
            {
                _tcpClient.Client.Send(sentData);
            }
        }