/*
-* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
/// <summary>
/// Native handle to Spi.
/// </summary>
- private IntPtr _handle;
+ private IntPtr _handle = IntPtr.Zero;
private bool _disposed = false;
/// <summary>
/// <param name="chip">The SPI chip select number.</param>
public SpiDevice(int bus, int chip)
{
- var ret = NativeSpi.Open(bus, chip, out IntPtr handle);
+ var ret = NativeSpi.Open(bus, chip, out _handle);
if (ret != Internals.Errors.ErrorCode.None)
throw ExceptionFactory.CreateException(ret);
-
- _handle = handle;
}
/// <summary>
}
NativeSpi.Close(_handle);
+ _handle = IntPtr.Zero;
_disposed = true;
}
/// <param name="buffer">The Data buffer.</param>
public void Read(byte[] buffer)
{
+ if (buffer == null)
+ throw new ArgumentNullException(nameof(buffer));
var length = Convert.ToUInt32(buffer.Length);
var ret = NativeSpi.Read(_handle, buffer, length);
if (ret != Internals.Errors.ErrorCode.None)
/// <param name="data">The data buffer to write.</param>
public void Write(byte[] data)
{
+ if (data == null)
+ throw new ArgumentNullException(nameof(data));
var length = Convert.ToUInt32(data.Length);
var ret = NativeSpi.Write(_handle, data, length);
if (ret != Internals.Errors.ErrorCode.None)
/// <param name="readBuffer">Array containing data read from the dievice.</param>
public void TransferSequential(byte[] writeBuffer, byte[] readBuffer)
{
+ if (readBuffer == null)
+ throw new ArgumentNullException(nameof(readBuffer));
+ if (writeBuffer == null)
+ throw new ArgumentNullException(nameof(writeBuffer));
if (writeBuffer.Length != readBuffer.Length)
throw new Exception("writeBuffer.Length is not equal to readBuffer.Length");