public void SendNoReply(int slaveAddress, BufferFrame message)
        {
            if (slaveAddress == linkLayer.GetBroadcastAddress())
            {
                if (nextBroadcastMessage != null)
                {
                    throw new LinkLayerBusyException("Broadcast message pending");
                }
                else
                {
                    nextBroadcastMessage = message;
                }
            }
            else
            {
                SlaveConnection slave = GetSlaveConnection(slaveAddress);

                if (slave != null)
                {
                    if (slave.IsMessageWaitingToSend())
                    {
                        throw new LinkLayerBusyException("Message pending");
                    }
                    else
                    {
                        slave.nextMessage         = message;
                        slave.requireConfirmation = false;
                    }
                }
            }
        }
        public void AddSlaveConnection(int slaveAddress)
        {
            SlaveConnection slave = GetSlaveConnection(slaveAddress);

            if (slave == null)
            {
                slaveConnections.Add(new SlaveConnection(slaveAddress, linkLayer, DebugLog, this));
            }
        }
        public void RequestClass1Data(int slaveAddress)
        {
            SlaveConnection slave = GetSlaveConnection(slaveAddress);

            if (slave != null)
            {
                slave.requestClass1Data = true;
            }
        }
        /********************************
        * IPrimaryLinkLayerUnbalanced
        ********************************/


        public void ResetCU(int slaveAddress)
        {
            SlaveConnection slave = GetSlaveConnection(slaveAddress);

            if (slave != null)
            {
                slave.resetCu = true;
            }
        }
Exemplo n.º 5
0
 public ModbusConstants.ConnectionType GetConnectionType()
 {
     if (IPAddress.TryParse(SlaveConnection, out IPAddress address))
     {
         return(ModbusConstants.ConnectionType.ModbusTCP);
     }
     else if (SlaveConnection.Contains("COM") || SlaveConnection.Contains("/tty"))
     {
         return(ModbusConstants.ConnectionType.ModbusRTU);
     }
     //TODO: ModbusRTU ModbusASCII
     return(ModbusConstants.ConnectionType.Unknown);
 }
        public LinkLayerState GetStateOfSlave(int slaveAddress)
        {
            SlaveConnection connection = GetSlaveConnection(slaveAddress);

            if (connection != null)
            {
                return(connection.linkLayerState);
            }
            else
            {
                throw new ArgumentException("No slave with this address found");
            }
        }
Exemplo n.º 7
0
 public ModbusConstants.ConnectionType GetConnectionType()
 {
     if (IPAddress.TryParse(SlaveConnection, out IPAddress address))
     {
         return(ModbusConstants.ConnectionType.ModbusTCP);
     }
     else if (SlaveConnection.Substring(0, 3) == "COM" || SlaveConnection.Substring(0, 8) == "/dev/tty")
     {
         return(ModbusConstants.ConnectionType.ModbusRTU);
     }
     //TODO: ModbusRTU ModbusASCII
     return(ModbusConstants.ConnectionType.Unknown);
 }
        public bool IsChannelAvailable(int slaveAddress)
        {
            SlaveConnection slave = GetSlaveConnection(slaveAddress);

            if (slave != null)
            {
                if (slave.IsMessageWaitingToSend() == false)
                {
                    return(true);
                }
            }

            return(false);
        }
        public void RequestClass2Data(int slaveAddress)
        {
            SlaveConnection slave = GetSlaveConnection(slaveAddress);

            if (slave != null)
            {
                if (slave.IsMessageWaitingToSend())
                {
                    throw new LinkLayerBusyException("Message pending");
                }
                else
                {
                    slave.requestClass2Data = true;
                }
            }
        }
        public void SendConfirmed(int slaveAddress, BufferFrame message)
        {
            SlaveConnection slave = GetSlaveConnection(slaveAddress);

            if (slave != null)
            {
                if (slave.nextMessage != null)
                {
                    throw new LinkLayerBusyException("Message pending");
                }
                else
                {
                    slave.nextMessage         = message.Clone();
                    slave.requireConfirmation = true;
                }
            }
        }
        public override void RunStateMachine()
        {
            // run all the link layer state machines for the registered slaves

            if (slaveConnections.Count > 0)
            {
                if (currentSlave == null)
                {
                    /* schedule next slave connection */
                    currentSlave      = slaveConnections[currentSlaveIndex];
                    currentSlaveIndex = (currentSlaveIndex + 1) % slaveConnections.Count;
                }

                currentSlave.RunStateMachine();

                if (currentSlave.waitingForResponse == false)
                {
                    currentSlave = null;
                }
            }
        }
        public override void HandleMessage(FunctionCodeSecondary fcs, bool acd, bool dfc,
                                           int address, byte[] msg, int userDataStart, int userDataLength)
        {
            SlaveConnection slave = null;

            if (address == -1)
            {
                slave = currentSlave;
            }
            else
            {
                slave = GetSlaveConnection(address);
            }

            if (slave != null)
            {
                slave.HandleMessage(fcs, acd, dfc, address, msg, userDataStart, userDataLength);
            }
            else
            {
                DebugLog("PLL RECV - response from unknown slave " + address + " !");
            }
        }