// private void Append(bool isCommand, params byte[] data) { //add I2C control flag when operation changed if (data == null) { return; } bool needI2CCtrlFlag = _busType == BusTypes.I2C; TransmissionData.TransmissionDataTypes currType = isCommand ? TransmissionData.TransmissionDataTypes.Command : TransmissionData.TransmissionDataTypes.Data; if (_lastData == null) { //first data _lastData = new TransmissionData(currType); needI2CCtrlFlag = needI2CCtrlFlag && true; } else if (_lastData.Type != currType) { //data type changed _dataQueue.Enqueue(_lastData); _lastData = new TransmissionData(currType); needI2CCtrlFlag = needI2CCtrlFlag && true; } else { //same type as previous needI2CCtrlFlag = false; } byte[] oriData = _lastData.Data; int oriSize = oriData.Length; int newSize = oriSize + data.Length + (needI2CCtrlFlag ? 1 : 0); //extend array Array.Resize(ref oriData, newSize); if (needI2CCtrlFlag) { //add I2C control flag oriData[oriSize++] = isCommand ? SSD1603.I2CTransmissionControlFlags.Command : SSD1603.I2CTransmissionControlFlags.Data; } //append data foreach (byte s in data) { oriData[oriSize++] = s; } _lastData.Data = oriData; }
public bool Send() { if (!Initialized) { return(false); } if (_lastData == null) { return(false); } try { //queue the last data _dataQueue.Enqueue(_lastData); _lastData = null; foreach (TransmissionData td in _dataQueue) { if (_busType == BusTypes.I2C) { _i2cDevic.Write(td.Data); } else if (_busType == BusTypes.SPI) { _pinCmdData.Write(td.Type == TransmissionData.TransmissionDataTypes.Command ? GpioPinValue.Low : GpioPinValue.High); _spiDevice.Write(td.Data); } } return(true); } catch (Exception ex) { Debug.WriteLine(string.Format("Failed to send data to {0} device", _busType), ex.Message); return(false); } finally { Empty(); } }
public void Empty() { _lastData = null; _dataQueue.Clear(); }
public bool Send() { if (!Initialized) { return false; } if (_lastData == null) { return false; } try { //queue the last data _dataQueue.Enqueue(_lastData); _lastData = null; foreach (TransmissionData td in _dataQueue) { if (_busType == BusTypes.I2C) { _i2cDevic.Write(td.Data); } else if (_busType == BusTypes.SPI) { _pinCmdData.Write(td.Type == TransmissionData.TransmissionDataTypes.Command ? GpioPinValue.Low : GpioPinValue.High); _spiDevice.Write(td.Data); } } return true; } catch (Exception ex) { Debug.WriteLine(string.Format("Failed to send data to {0} device", _busType), ex.Message); return false; } finally { Empty(); } }