WindowsIoT.TouchSample/Communication/SerialComm.cs
/// <summary>
/// Sets internal fields from byte array
/// </summary>
/// <param name="value">Byte array from device</param>
/// <returns>Data integrity checking result (0 - OK, 1 - bad CRC, 2 - bad size)</returns>
Sets internal fields from byte array
Sets internal fields from byte array
public async Task<byte> SetBuffer(byte[] value)
        {
            byte result = 0;
            lock (LockObj)
            {
                _bv = false;
                if (value != null && value.Length == buffer.Length)
                {
                    if (CRC16(value) == BitConverter.ToUInt16(value, value.Length - 2))
                    {
                        if (!_bv || TxAddress == 0)
                            Array.Copy(value, buffer, buffer.Length);
                        _bv = true;
                    }
                    else
                        result = 1;
                }
                else
                    result = 2;
            }
            if (result == 0 && DataReady != null)
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => DataReady?.Invoke(this));
            return result;
        }
public async Task < byte > SetBuffer ( byte [ ] value ) { byte result = 0 ; lock ( LockObj ) { _bv = false ; if ( value != null && value . Length == buffer . Length ) { if ( CRC16 ( value ) == BitConverter . ToUInt16 ( value , value . Length - 2 ) ) { if ( ! _bv || TxAddress == 0 ) Array . Copy ( value , buffer , buffer . Length ) ; _bv = true ; } else result = 1 ; } else result = 2 ; } if ( result == 0 && DataReady != null ) await Dispatcher . RunAsync ( Windows . UI . Core . CoreDispatcherPriority . Low , ( ) => DataReady ? . Invoke ( this ) ) ; return result ; }
Sets internal fields from byte array
Sets internal fields from byte array
Data integrity checking result (0 - OK, 1 - bad CRC, 2 - bad size)
Data integrity checking result ( 0 - OK 1 - bad CRC 2 - bad size )
value
byte[]
Byte array from device
Byte array from device