none
Visual studio --> arduino port connection problem RRS feed

  • Question

  • hey everyone

    So I recently started using the kinect and i wanted to use my kinect data to controle some motors. Now I am trying to make the connection between my arduino and visual studio 2012.

    I did this once before in Unity also in c#. That was succesful but when i try it in VS 2012 it keeps saying that my port is closed. I'm using a serialport with my arduino on COM3 (checked in arduino cc self, so that isn't the problem). Does VS take full controle over a port instead of just using it (like unity)??

    code below :

            public SerialPort sp = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
            
            static string xvalue = "testing : 0";

     public MainWindow()
            {
                InitializeComponent();
    
                _closing = false;
                _kinectConnected = false;
                lblXvalue.Foreground = new SolidColorBrush(Colors.White);
    
                OpenConnection();
    
                SendThread = new Thread(threadB);
                SendThread.Start();
    
              
            }
    
          void threadB()
          {
              while (!stopsrlThread)
              {
                  if (blnPortcanopen)
                  {
                    
                      if (sendDatabyte)
                      {
                              sendDatabyte = false;
                              sp.Write(xvalue);
                      }
                  }
              }   
          }
    
          void OpenConnection()
          {
              if (sp != null)
              {
                  if (sp.IsOpen)
                  {
                      Console.WriteLine("port already open");
                  }
                  else
                  {
                      try
                      {
                          blnPortcanopen = true;
                          sp.Open();
                         
                      }
                      catch (Exception e)
                      {
                          Console.WriteLine(e);
                      }
                      if (blnPortcanopen)
                      {
                          sp.ReadTimeout = 20;
                          Console.WriteLine("port opend!");
                      }
                  }
              }
              else
              {
                  Console.WriteLine("port == null");
              }
          }
          void onApplicationQuit()
          {
              if (sp != null) sp.Close();
              stopsrlThread = true;
          }

    Can anyone spot the problem ?

    Thanks in advance !

    Nsmet

    Wednesday, February 19, 2014 2:55 PM