none
access to the port com1 is denied c# RRS feed

  • Question

  • I use a virtual serial port emulator , but im my application in c# , it still told me that access to the port com1 is denied 

    Question
    You cannot vote on your own post
    0

    and here is my app :

     public Emission(int i)
            {
                InitializeComponent();
                 serialPort1.Open();
                if (serialPort1.IsOpen==true)
                {
                    serialPort1.Write("1");
                    Thread.Sleep(460);
                    serialPort1.ReadByte();
                    Thread.Sleep(867 + ((i- 1) * 150) + ((i- 1) * 427));
                    serialPort1.Write("0");
                    Thread.Sleep(150);
                    serialPort1.Close();
                    serialPort1.Dispose();
                }

    Monday, April 14, 2014 1:58 PM

Answers

  • Hiya,

     from the looks of your code, you have custom methods encapsulating SerialPort class. Suggest you

    single-step debug and check the variables in local window usually below code window. You could

    also call  System.IO.Ports.SerialPort.GetPortNames() and verify your vitual is listed before an attempt

    to call methods read/write?

    Hope this helps. Thanks. :)

    PS. Try this link for code example;

    http://msdn.microsoft.com/en-us/library/s14dyf47%28v=vs.110%29.aspx

    • Edited by User3DX Wednesday, April 16, 2014 12:39 AM Added Code Ref
    • Marked as answer by Fred BaoModerator Monday, April 21, 2014 9:10 AM
    Wednesday, April 16, 2014 12:36 AM