Example #1
0
        private void WriteOperations(ref List <ReadWriteRequest> values, string parentID, bool suppressEthernetHeader)
        {
            PComA pcomA = new PComA();

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

            foreach (WriteOperands wo in values)
            {
                pcomA.BuildAsciiCommand(UnitId,
                                        Utils.ASCIIOperandTypes[Enum.GetName(typeof(OperandTypes), wo.OperandType)].CommandCodeForWrite,
                                        (wo as WriteOperands).StartAddress, wo.NumberOfOperands, (wo as WriteOperands).Values,
                                        (wo as WriteOperands).TimerValueFormat);
                string readMessage = pcomA.MessageToPLC as string;

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

                GuidClass guid = new GuidClass();

                lock (guid)
                {
                    Channel.Send(readMessage, ReceiveString, guid, parentID, "ASCII Protocol - Write Operands", PlcGuid,
                                 suppressEthernetHeader);
                    Monitor.Wait(guid);
                }

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

                PlcResponseMessage plcResponseMessage;

                lock (_lockObj)
                {
                    plcResponseMessage = m_responseMessageQueue[guid];
                    m_responseMessageQueue.Remove(guid);
                }

                if (plcResponseMessage.comException == CommunicationException.Timeout)
                {
                    throw new ComDriveExceptions("Cannot communicate with the PLC with the specified UnitID!",
                                                 ComDriveExceptions.ComDriveException.CommunicationTimeout);
                }

                pcomA.DisAssembleAsciiResult(plcResponseMessage.responseStringMessage, UnitId,
                                             Utils.ASCIIOperandTypes[Enum.GetName(typeof(OperandTypes), wo.OperandType)].CommandCodeForWrite,
                                             wo.StartAddress, wo.NumberOfOperands, null, wo.TimerValueFormat);
            }
        }
        internal override void PerformReadWrite(ref ReadWriteRequest[] values, string parentID,
                                                bool suppressEthernetHeader)
        {
            if (pcomA == null)
            {
                pcomA = new PComA();
            }

            ReadWriteOperandsCommand(ref values, parentID, suppressEthernetHeader);
        }