Access to the port 'COM1' is denied from time controller
<p>This is my code. In this code I am calling from time in every second bit I am getting </p>

<blockquote>
  <p>error comp port access denied </p>
</blockquote>

<p>I am getting this after 5 calls. </p>

<pre><code>using (SerialPort port = new SerialPort(serialPortName))
    {
        if (port.IsOpen)
        {
            port.Close();
            port.Dispose();
        }

        port.BaudRate = 19200;
        port.DataBits = 8;
        port.Parity = Parity.None;
        port.StopBits = StopBits.Two;

        port.Open();

        // create modbus master
        IModbusSerialMaster master = ModbusSerialMaster.CreateRtu(port);
        byte slaveId = Convert.ToByte(txtSlaveId.Text.Trim());
        ushort startAddress = Convert.ToUInt16(StartAddress);
        ushort numRegisters = Convert.ToUInt16(NumberofRegisters);

        SystemLog systemLog = new SystemLog();
        systemLog.SlaveId = txtSlaveId.Text.Trim();
        systemLog.VariableName = VariableName;
        systemLog.ReadStartTime = DateTime.Now;

        switch (Type)
        {
            case "CO":
                bool[] status = master.ReadCoils(slaveId, startAddress, numRegisters);
                for (int j = 0; j &lt; numRegisters; j++)
                {
                    systemLog.ReadEndTime = DateTime.Now;
                    systemLog.ReadAddress = Convert.ToString(Convert.ToInt32(StartAddress) + j);
                    systemLog.ReadType = (int)PLCReadType.COIL;
                    systemLog.ReadValue = Convert.ToString(status[j]);

                }
                break;
            case "IR":
                ushort[] inputRegister = master.ReadInputRegisters(slaveId, startAddress, numRegisters);
                for (int j = 0; j &lt; numRegisters; j++)
                {
                    systemLog.ReadEndTime = DateTime.Now;
                    systemLog.ReadAddress = Convert.ToString(Convert.ToInt32(StartAddress) + j);
                    systemLog.ReadType = (int)PLCReadType.COIL;
                    systemLog.ReadValue = Convert.ToString(inputRegister[j]);

                }
                break;
            case "HR":
                ushort[] holdingRegister = master.ReadHoldingRegisters(slaveId, startAddress, numRegisters);
                for (int j = 0; j &lt; numRegisters; j++)
                {
                    systemLog.ReadEndTime = DateTime.Now;
                    systemLog.ReadAddress = Convert.ToString(Convert.ToInt32(StartAddress) + j);
                    systemLog.ReadType = (int)PLCReadType.COIL;
                    systemLog.ReadValue = Convert.ToString(holdingRegister[j]);
                }
                break;
        }
        systemLogArray[i] = systemLog;
        port.Close();
        port.Dispose();
    }
</code></pre>