Menu

Suggestions for moka7 improvement

Marc
2015-05-20
2015-05-21
  • Marc

    Marc - 2015-05-20

    In S7Client, the method WaitForData slows down the communication because of the sleep.
    In java, the resolution of sleep is 10ms, so sleep(1) actually takes 10ms.
    I would suggest to set a socket timeout and do one or more blocking reads for the timeout desired:

    private int RecvPacket(byte[] Buffer,
    int Start,
    int Size)
    {
    int res;

    LastError = 0;
    try
    {
      while (Size > 0)
      {
        res = InStream.read(Buffer,
                            Start,
                            Size);
        if (res == 0 || res == -1)
        {
          LastError = errTCPConnectionReset;
          break;
        }
        Start += res;
        Size -= res;
      }
    }
    catch (SocketTimeoutException e)
    {
      LastError = errTCPDataRecvTout;
    }
    catch (IOException ex)
    {
      LastError = errTCPDataRecv;
    }
    return LastError;
    

    }

    The method GetPlcDateTime takes a reference to a date object as an argument, but never returns the actual result date. Probably a conversion error from the original language.

    In RecvIsoPacket is a RecvPacket() call of which the return code is not checked.

    Why use a global LastError variable that is returned by almost all method calls anyway? Wouldn't it be cleaner to just check the return code of method calls? Tools like findbugs help to find methods of which return codes are ignored.

     
  • Davide Nardella

    Davide Nardella - 2015-05-21

    Hi Marc,
    thanks for reporting ;)
    I will look at it as I have 5 min of free time.

    regards

     

Log in to post a comment.

MongoDB Logo MongoDB