コード例 #1
0
        private void SplitAndWriteDataTableRowSizeExceedPLCBuffer(ref List <ReadWriteRequest> joinRequests,
                                                                  ushort maximumAvailableBytesNo, string parentID)
        {
            WriteDataTables         wdt          = joinRequests[0] as WriteDataTables;
            List <ReadWriteRequest> splitWDTList = new List <ReadWriteRequest>();
            ushort remainingRowsNo = wdt.NumberOfRowsToWrite;

            ushort maxAvailableWriteRowBytesNo = maximumAvailableBytesNo;
            ushort remainingWriteRowByteNo     = (ushort)wdt.NumberOfBytesToWriteInRow;
            uint   startAddress = wdt.StartAddress;

            int sourceIndex = 0;

            wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   RequestProgress.en_NotificationType.SetMinMax, 0, "");
            wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   RequestProgress.en_NotificationType.ProgressChanged, 0, "");

            while (remainingRowsNo > 0)
            {
                while (remainingWriteRowByteNo > 0)
                {
                    byte[] values = new byte[maxAvailableWriteRowBytesNo];
                    Array.Copy(wdt.Values.ToArray(), sourceIndex, values, 0, maxAvailableWriteRowBytesNo);
                    sourceIndex += maxAvailableWriteRowBytesNo;

                    WriteDataTables tmpWDT = new WriteDataTables(startAddress, maxAvailableWriteRowBytesNo, 1,
                                                                 (ushort)wdt.RowSizeInBytes, values.ToList(), wdt.SubCommand);
                    splitWDTList.Add(tmpWDT);

                    ReadWriteDataTable(ref splitWDTList, parentID);
                    splitWDTList.Clear();

                    startAddress            += maxAvailableWriteRowBytesNo;
                    remainingWriteRowByteNo -= maxAvailableWriteRowBytesNo;

                    if (remainingWriteRowByteNo < maxAvailableWriteRowBytesNo && remainingWriteRowByteNo > 0)
                    {
                        maxAvailableWriteRowBytesNo = remainingWriteRowByteNo;
                    }
                }

                remainingRowsNo--;
                maxAvailableWriteRowBytesNo = maximumAvailableBytesNo;
                remainingWriteRowByteNo     = (ushort)wdt.NumberOfBytesToWriteInRow;
                startAddress =
                    (uint)(wdt.StartAddress + (wdt.NumberOfRowsToWrite - remainingRowsNo) * wdt.RowSizeInBytes);

                wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                       RequestProgress.en_NotificationType.ProgressChanged,
                                       (wdt.NumberOfRowsToWrite - remainingRowsNo) * wdt.NumberOfBytesToWriteInRow, "");
            }

            wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   RequestProgress.en_NotificationType.Completed, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   "");

            joinRequests[0].ResponseValues = String.Empty;
        }
コード例 #2
0
        private void SplitAndWriteDataTableRows(ref List <ReadWriteRequest> joinRequests, ushort maximumAvailableBytesNo,
                                                string parentID)
        {
            WriteDataTables wdt = joinRequests[0] as WriteDataTables;

            List <ReadWriteRequest> splitWDTList = new List <ReadWriteRequest>();
            int sourceIndex = 0;
            int length      = 0;

            ushort availableRowsNo = (ushort)(maximumAvailableBytesNo / wdt.NumberOfBytesToWriteInRow);
            int    remainingRowsNo = wdt.NumberOfRowsToWrite;
            uint   startAddress    = wdt.StartAddress;

            wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   RequestProgress.en_NotificationType.SetMinMax, 0, "");
            wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   RequestProgress.en_NotificationType.ProgressChanged, 0, "");

            while (remainingRowsNo > 0)
            {
                length = wdt.NumberOfBytesToWriteInRow * availableRowsNo;
                byte[] writeValues = new byte[length];
                Array.Copy(wdt.Values.ToArray(), sourceIndex, writeValues, 0, length);
                sourceIndex += length;

                WriteDataTables tmpWDT = new WriteDataTables(startAddress, wdt.NumberOfBytesToWriteInRow,
                                                             availableRowsNo, (ushort)(wdt.RowSizeInBytes), writeValues.ToList(), wdt.SubCommand);
                splitWDTList.Add(tmpWDT);
                ReadWriteDataTable(ref splitWDTList, parentID);
                splitWDTList.Clear();

                startAddress    += (uint)(availableRowsNo * wdt.RowSizeInBytes);
                remainingRowsNo -= availableRowsNo;

                if (remainingRowsNo < availableRowsNo && remainingRowsNo > 0)
                {
                    availableRowsNo = (ushort)remainingRowsNo;
                }


                wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                       RequestProgress.en_NotificationType.ProgressChanged,
                                       (wdt.NumberOfRowsToWrite - remainingRowsNo) * wdt.NumberOfBytesToWriteInRow, "");
            }

            wdt.RaiseProgressEvent(0, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   RequestProgress.en_NotificationType.Completed, wdt.NumberOfRowsToWrite * wdt.NumberOfBytesToWriteInRow,
                                   "");
            joinRequests[0].ResponseValues = String.Empty;
        }
コード例 #3
0
        private void ReadWriteDataTable(ref List <ReadWriteRequest> dataTableDRs, string parentID)
        {
            PComB           pComB = new PComB();
            BinaryCommand   binaryCommand;
            ReadDataTables  rdt = null;
            WriteDataTables wdt = null;

            if (this.BreakFlag)
            {
                throw new ComDriveExceptions("Request aborted by user",
                                             ComDriveExceptions.ComDriveException.AbortedByUser);
            }

            foreach (ReadWriteRequest rwr in dataTableDRs)
            {
                if (this.BreakFlag)
                {
                    throw new ComDriveExceptions("Request aborted by user",
                                                 ComDriveExceptions.ComDriveException.AbortedByUser);
                }

                if (rwr is ReadDataTables)
                {
                    binaryCommand = BinaryCommand.ReadDataTables;
                    rdt           = rwr as ReadDataTables;

                    rdt.RaiseProgressEvent(0, rdt.NumberOfBytesToReadInRow * rdt.NumberOfRowsToRead,
                                           RequestProgress.en_NotificationType.SetMinMax, 0, "");
                    rdt.RaiseProgressEvent(0, rdt.NumberOfBytesToReadInRow * rdt.NumberOfRowsToRead,
                                           RequestProgress.en_NotificationType.ProgressChanged, 0, "");

                    if (rdt.PartOfProject)
                    {
                        binaryCommand = BinaryCommand.ReadPartOfProjectDataTables;
                    }

                    List <List <byte> > readDataTablesDataRequestBytes = new List <List <byte> >();
                    readDataTablesDataRequestBytes.Add(GetDataRequestBytesForReadDataTables(rdt));

                    if (rdt != null)
                    {
                        byte[] cmdDetails = new byte[6];
                        Array.Copy(BitConverter.GetBytes(rdt.StartAddress), cmdDetails, 4);

                        pComB.BuildBinaryCommand((byte)UnitId, binaryCommand, cmdDetails, dataTableDRs,
                                                 readDataTablesDataRequestBytes, (byte)rdt.SubCommand);

                        BinaryMessage receivedMessage =
                            ReceiveMessage(pComB, readDataTablesDataRequestBytes, parentID) as BinaryMessage;
                    }

                    rdt.RaiseProgressEvent(0, rdt.NumberOfBytesToReadInRow * rdt.NumberOfRowsToRead,
                                           RequestProgress.en_NotificationType.Completed,
                                           rdt.NumberOfBytesToReadInRow * rdt.NumberOfRowsToRead, "");
                }

                if (rwr is WriteDataTables)
                {
                    binaryCommand = BinaryCommand.WriteDataTables;
                    wdt           = rwr as WriteDataTables;

                    wdt.RaiseProgressEvent(0, wdt.NumberOfBytesToWriteInRow * wdt.NumberOfRowsToWrite,
                                           RequestProgress.en_NotificationType.SetMinMax, 0, "");
                    wdt.RaiseProgressEvent(0, wdt.NumberOfBytesToWriteInRow * wdt.NumberOfRowsToWrite,
                                           RequestProgress.en_NotificationType.ProgressChanged, 0, "");

                    List <List <byte> > writeDataTablesDataRequestBytes = new List <List <byte> >();
                    writeDataTablesDataRequestBytes.Add(GetDataRequestBytesForWriteDataTables(wdt));

                    if (wdt != null)
                    {
                        byte[] cmdDetails = new byte[6];
                        Array.Copy(BitConverter.GetBytes(wdt.StartAddress), cmdDetails, 4);

                        pComB.BuildBinaryCommand((byte)UnitId, binaryCommand, cmdDetails, dataTableDRs,
                                                 writeDataTablesDataRequestBytes, (byte)wdt.SubCommand);

                        BinaryMessage receivedMessage = ReceiveMessage(pComB, null, parentID) as BinaryMessage;
                    }

                    wdt.RaiseProgressEvent(0, wdt.NumberOfBytesToWriteInRow * wdt.NumberOfRowsToWrite,
                                           RequestProgress.en_NotificationType.ProgressChanged,
                                           wdt.NumberOfBytesToWriteInRow * wdt.NumberOfRowsToWrite, "");
                }
            }
        }