private static void CompareDataPortConfig(DataPortConfig dataPortConfig, DataPortConfig defaultDataPortConfig) { var isValid = true; if (!dataPortConfig.ActChannelsDataPacking.SequenceEqual(defaultDataPortConfig.ActChannelsDataPacking)) { isValid = false; SmartLog.WriteErrorLine( $"Act Channel Data Pack {dataPortConfig.ActChannelsDataPacking.ToHex()} not matching with default {defaultDataPortConfig.ActChannelsDataPacking.ToHex()}"); } if (!dataPortConfig.SampleInterval.SequenceEqual(defaultDataPortConfig.SampleInterval)) { isValid = false; SmartLog.WriteErrorLine( $"Sample Interval {dataPortConfig.SampleInterval.ToHex()} not matching with default {defaultDataPortConfig.SampleInterval.ToHex()}"); } if (!dataPortConfig.FirmwareVersion.SequenceEqual(defaultDataPortConfig.FirmwareVersion)) { isValid = false; SmartLog.WriteErrorLine( $"Firmware Version {dataPortConfig.FirmwareVersion.ToHex()} not matching with default {defaultDataPortConfig.FirmwareVersion.ToHex()}"); } if (!dataPortConfig.ModeFlag.SequenceEqual(defaultDataPortConfig.ModeFlag)) { isValid = false; SmartLog.WriteErrorLine( $"Mode Flag {dataPortConfig.ModeFlag.ToHex()} not matching with default {defaultDataPortConfig.ModeFlag.ToHex()}"); } if (!isValid) { _smartPort.WriteDataPortConfig(_boardId, dataPortConfig, defaultDataPortConfig); } }
public static async Task <int> IncrementOrDecrementStrain(SgAdjust sgAdjust) { if (_deviceCount == 0) { await Init(); } // set the SPI xFer params for I/O expander uint baudRate2 = 250000; //1000000 uint idleCsVal2 = 0x1ff; uint activeCsVal2 = 0x1fd; //GP1 CS PIN, remaining pins are GP //0x1ee GP4 and GP0 set as active low CS uint csToDataDly2 = 0; uint dataToDataDly2 = 0; uint dataToCsDly2 = 0; uint txFerSize2 = 3; // I/O expander xFer size set to 4 byte spiMd2 = 0; uint csMask4 = 0x02; //GP1 as CS // 0x10 set GP4 as CS byte[] txData = new byte[3], rxData = new byte[3]; switch (sgAdjust) { // set the expander config params case SgAdjust.Increment: txData[0] = 0x60; break; case SgAdjust.Decrement: txData[0] = 0xE0; break; case SgAdjust.Save: txData[0] = 0x20; //SmartLog.WriteLine( // $"txData:{txData.ToHex()}\nrxData:{rxData.ToHex()}\nbaudRate2:{baudRate2}\ntxFerSize2:{txFerSize2}\ncsMask4:{csMask4}\nidleCsVal2:{idleCsVal2}\nactiveCsVal2:{activeCsVal2}\ncsToDataDly2:{csToDataDly2}\ndataToCsDly2:{dataToCsDly2}\ndataToDataDly2:{dataToDataDly2}\nspiMd2:{spiMd2}"); break; } txData[1] = 0x00; txData[2] = 0x00; // send the data // use the extended SPI xFer API first time in order to set all the parameters // the subsequent xFer with the same device may use the simple API in order to save CPU cycles _response = MCP2210.M_Mcp2210_xferSpiDataEx(_deviceHandle, txData, rxData, ref baudRate2, ref txFerSize2, csMask4, ref idleCsVal2, ref activeCsVal2, ref csToDataDly2, ref dataToCsDly2, ref dataToDataDly2, ref spiMd2); if (_response != MCP2210.M_E_SUCCESS) { MCP2210.M_Mcp2210_Close(_deviceHandle); SmartLog.WriteErrorLine($"Sg ({sgAdjust.ToString()}) transfer error: " + _response); _deviceCount = 0; return(_response); } SmartLog.WriteLine($"Sg ({sgAdjust.ToString()}) transfer response: " + _response); return(0); }
public static async Task <int> Init() { _deviceCount = MCP2210.M_Mcp2210_GetConnectedDevCount(DefaultVid, DefaultPid); SmartLog.WriteLine(_deviceCount + " SPI Module Device(s) found"); if (_deviceCount <= 0) { return(_response); } StringBuilder path = new StringBuilder(); _deviceHandle = MCP2210.M_Mcp2210_OpenByIndex(DefaultVid, DefaultPid, 0, path); _response = MCP2210.M_Mcp2210_GetLastError(); if (_response != MCP2210.M_E_SUCCESS) { SmartLog.WriteErrorLine("Failed to open connection"); return(await Task.FromResult(-1)); } return(_response); }