/// <summary>Resets path and stored information to the empty state</summary> public void Clear() { path = string.Empty; name = string.Empty; fileSystemInfo = null; timeStamp = default(Time.QpcTimeStamp); }
protected internal string RunCmdWrite() { masterToSlaveBufferLen = 0; slaveToMasterBufferLen = 0; for (int preambles = 0; preambles < Details.DefaultMinPreambleBytesToSend; preambles++) { masterToSlaveBuffer[masterToSlaveBufferLen++] = Details.PreambleByte; } int startCharIdx = masterToSlaveBufferLen; masterToSlaveBuffer[masterToSlaveBufferLen++] = MasterToSlavePacketInfo.PacketAddressInfo.StartChar; if (MasterToSlavePacketInfo.PacketAddressInfo.AddressType == AddressType.Short_1Byte) { masterToSlaveBuffer[masterToSlaveBufferLen++] = MasterToSlavePacketInfo.PacketAddressInfo.PackShortAddr(); } else { MasterToSlavePacketInfo.PacketAddressInfo.PackLongAddr(masterToSlaveBuffer, masterToSlaveBufferLen); masterToSlaveBufferLen += 5; } masterToSlaveBuffer[masterToSlaveBufferLen++] = MasterToSlavePacketInfo.CommandCode; byte dataCount = MasterToSlavePacketInfo.DataLenByte; byte [] data = MasterToSlavePacketInfo.Data; masterToSlaveBuffer[masterToSlaveBufferLen++] = dataCount; for (byte cmdDataIdx = 0; cmdDataIdx < dataCount; cmdDataIdx++) { masterToSlaveBuffer[masterToSlaveBufferLen++] = data[cmdDataIdx]; } // build checksum byte checkSumByte = 0x00; for (int checkSumIdx = startCharIdx; checkSumIdx < masterToSlaveBufferLen; checkSumIdx++) { checkSumByte = (byte)(checkSumByte ^ masterToSlaveBuffer[checkSumIdx]); } masterToSlaveBuffer[masterToSlaveBufferLen++] = checkSumByte; // capture timestamp MasterToSlavePacketInfo.TimeStamp = Time.QpcTimeStamp.Now; // update WriteActionParms spWriteActionParam.Reset(); spWriteActionParam.Buffer = masterToSlaveBuffer; spWriteActionParam.BytesToWrite = masterToSlaveBufferLen; // run it. string ec = ((spWriteAction != null) ? spWriteAction.Run() : "WriteFailed: No SerialPort Defined"); spWriteCompleteTime = Time.QpcTimeStamp.Now; if (!String.IsNullOrEmpty(ec)) { SetFailed(ec); } return(ec); }
protected internal bool RunIncrementalCmdResponseRead(ref string ecOut) { Time.QpcTimeStamp timeoutAfter = spWriteCompleteTime + ResponseTimeLimit; TimeSpan remainingTime = timeoutAfter - Time.QpcTimeStamp.Now; spReadActionParam.Reset(); spReadActionParam.Buffer = slaveToMasterBuffer; spReadActionParam.BytesRead = slaveToMasterBufferLen; spReadActionParam.BytesToRead = slaveToMasterBuffer.Length; // we will be happy to stop before this as well spReadActionParam.WaitForAllBytes = false; string ec = ((spReadAction != null) ? spReadAction.Run() : "ReadFailed: No SerialPort Defined"); TimeSpan runTime = spReadActionParam.StartTime.Age; if (spReadActionParam.BytesRead != slaveToMasterBufferLen) { slaveToMasterBufferLen = spReadActionParam.BytesRead; string decodeEC = null; if (AttemptToDecodeAndVerifyCmdResponse(ref decodeEC)) { ec = decodeEC ?? ec; SlaveToMasterPacketInfo.TimeStamp = Time.QpcTimeStamp.Now; TimeSpan spReadActionRunTime = SlaveToMasterPacketInfo.TimeStamp - spReadActionParam.StartTime; ecOut = ec; return(true); } } else { switch (spReadActionParam.ActionResultEnum) { case MosaicLib.SerialIO.ActionResultEnum.ReadDone: case MosaicLib.SerialIO.ActionResultEnum.ReadTimeout: ec = String.Empty; // neither of these cases are errors at this level break; default: // all other cases are errors if (String.IsNullOrEmpty(ec)) { ec = "??" + spReadActionParam.ResultCode; } break; } } if (String.IsNullOrEmpty(ec) && remainingTime < TimeSpan.Zero) { if (slaveToMasterBufferLen == 0) { ec = "Timeout waiting for any response from target device(s)"; } else { ec = "Timeout waiting for complete response from target device(s)"; } SlaveToMasterPacketInfo.TimeStamp = Time.QpcTimeStamp.Now; } bool cmdFailed = !String.IsNullOrEmpty(ecOut = ec); return(cmdFailed); }
protected internal string RunCmdWrite() { masterToSlaveBufferLen = 0; slaveToMasterBufferLen = 0; for (int preambles = 0; preambles < Details.DefaultMinPreambleBytesToSend; preambles++) masterToSlaveBuffer[masterToSlaveBufferLen++] = Details.PreambleByte; int startCharIdx = masterToSlaveBufferLen; masterToSlaveBuffer[masterToSlaveBufferLen++] = MasterToSlavePacketInfo.PacketAddressInfo.StartChar; if (MasterToSlavePacketInfo.PacketAddressInfo.AddressType == AddressType.Short_1Byte) masterToSlaveBuffer[masterToSlaveBufferLen++] = MasterToSlavePacketInfo.PacketAddressInfo.PackShortAddr(); else { MasterToSlavePacketInfo.PacketAddressInfo.PackLongAddr(masterToSlaveBuffer, masterToSlaveBufferLen); masterToSlaveBufferLen += 5; } masterToSlaveBuffer[masterToSlaveBufferLen++] = MasterToSlavePacketInfo.CommandCode; byte dataCount = MasterToSlavePacketInfo.DataLenByte; byte [] data = MasterToSlavePacketInfo.Data; masterToSlaveBuffer[masterToSlaveBufferLen++] = dataCount; for (byte cmdDataIdx = 0; cmdDataIdx < dataCount; cmdDataIdx++) masterToSlaveBuffer[masterToSlaveBufferLen++] = data[cmdDataIdx]; // build checksum byte checkSumByte = 0x00; for (int checkSumIdx = startCharIdx; checkSumIdx < masterToSlaveBufferLen; checkSumIdx++) { checkSumByte = (byte) (checkSumByte ^ masterToSlaveBuffer[checkSumIdx]); } masterToSlaveBuffer[masterToSlaveBufferLen++] = checkSumByte; // capture timestamp MasterToSlavePacketInfo.TimeStamp = Time.QpcTimeStamp.Now; // update WriteActionParms spWriteActionParam.Reset(); spWriteActionParam.Buffer = masterToSlaveBuffer; spWriteActionParam.BytesToWrite = masterToSlaveBufferLen; // run it. string ec = ((spWriteAction != null) ? spWriteAction.Run() : "WriteFailed: No SerialPort Defined"); spWriteCompleteTime = Time.QpcTimeStamp.Now; if (!String.IsNullOrEmpty(ec)) SetFailed(ec); return ec; }