- Home /
How to fix IOException: Access is denied.
So whenever I run press play, this error pops up in the console: IOException: Access is denied.
The error:
System.IO.Ports.WinSerialStream.ReportIOError (System.String optional_arg) (at :0) System.IO.Ports.WinSerialStream..ctor (System.String port_name, System.Int32 baud_rate, System.Int32 data_bits, System.IO.Ports.Parity parity, System.IO.Ports.StopBits sb, System.Boolean dtr_enable, System.Boolean rts_enable, System.IO.Ports.Handshake hs, System.Int32 read_timeout, System.Int32 write_timeout, System.Int32 read_buffer_size, System.Int32 write_buffer_size) (at :0) (wrapper remoting-invoke-with-check) System.IO.Ports.WinSerialStream..ctor(string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int) System.IO.Ports.SerialPort.Open () (at :0) (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort.Open() commands.Awake () (at Assets/commands.cs:31)
The script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
public class arduinothing: MonoBehaviour
{
SerialPort sp = new SerialPort("COM3", 9600);
// Start is called before the first frame update
void Awake()
{
sp.ReadTimeout = 16;
if (!sp.IsOpen)
{
sp.Open();
}
}
//the rest of this script