Пример #1
0
 protected void CacheTransmission(byte[] request, byte[] response, EdiabasNet.ErrorCodes errorCode)
 {
     if (!EnableTransmitCache)
     {
         return;
     }
     if (errorCode == EdiabasNet.ErrorCodes.EDIABAS_IFH_0003)
     {
         return;
     }
     if (request.Length > 0)
     {
         StoreWriteTransaction();
         WriteTransaction = new TransmitStorage(request, response, errorCode);
     }
     else
     {
         if (WriteTransaction != null)
         {
             if (response != null && response.Length > 0)
             {
                 byte[] buffer = new byte[response.Length];
                 Array.Copy(response, buffer, response.Length);
                 WriteTransaction.ResponseList.Add(buffer);
             }
             if (errorCode != EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE && WriteTransaction.ErrorCode == EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
             {
                 WriteTransaction.ErrorCode = errorCode;
             }
         }
     }
 }
Пример #2
0
 protected void StoreWriteTransaction()
 {
     if (WriteTransaction != null)
     {
         if (TransmitCacheDict.ContainsKey(WriteTransaction.Key))
         {
             TransmitCacheDict.Remove(WriteTransaction.Key);
         }
         TransmitCacheDict.Add(WriteTransaction.Key, WriteTransaction);
         WriteTransaction = null;
     }
 }
Пример #3
0
 protected bool ReadCachedTransmission(byte[] request, out byte[] response, out EdiabasNet.ErrorCodes errorCode)
 {
     response  = null;
     errorCode = EdiabasNet.ErrorCodes.EDIABAS_IFH_0009;
     if (!EnableTransmitCache)
     {
         return(false);
     }
     if (request.Length > 0)
     {
         StoreWriteTransaction();
         ReadTransaction    = null;
         ReadTransactionPos = 0;
         TransmitCacheDict.TryGetValue(BitConverter.ToString(request), out ReadTransaction);
     }
     if (ReadTransaction == null)
     {
         return(false);
     }
     if (request.Length > 0)
     {
         Ediabas.LogData(EdiabasNet.EdLogLevel.Ifh, request, 0, request.Length, "Send Cache");
     }
     if ((ReadTransaction.Request.Length > 0) && ((ReadTransaction.Request[0] & 0xC0) == 0xC0))
     {     // functional address
         if (ReadTransaction.ErrorCode == EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
         { // transmission not completed
             Ediabas.LogString(EdiabasNet.EdLogLevel.Ifh, "Incomplete cached response");
             return(false);
         }
     }
     if (ReadTransaction.ResponseList.Count > ReadTransactionPos)
     {
         response  = ReadTransaction.ResponseList[ReadTransactionPos++];
         errorCode = EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE;
         Ediabas.LogData(EdiabasNet.EdLogLevel.Ifh, response, 0, response.Length, "Resp Cache");
     }
     else
     {
         if (ReadTransaction.ErrorCode != EdiabasNet.ErrorCodes.EDIABAS_ERR_NONE)
         {
             errorCode = ReadTransaction.ErrorCode;
         }
     }
     return(true);
 }