Exemple #1
0
        public void initializeSensor(int portNum, string[] ports)
        {
            serialPort = new SerialPort();
            if (ports.Length <= 0)
            {
                sensorExisting = false;
                message        = "Arduino no detectado";
                SensorNotFoundExceptio ex = new SensorNotFoundExceptio(message);
                throw ex;
            }
            else
            {
                sensorExisting      = true;
                serialPort.PortName = ports[portNum];
                serialPort.BaudRate = 9600;

                try
                {
                    serialPort.Open();
                }
                catch (Exception e)
                {
                    message = "No se pudo establecer comunicacion con el arduino";
                    SensorNotFoundExceptio ex = new SensorNotFoundExceptio(message);
                    throw ex;
                }
            }
        }
Exemple #2
0
 public string[] ExistingPortsOnly()
 {
     string[] ports = SerialPort.GetPortNames();
     if (ports.Length <= 0)
     {
         sensorExisting = false;
         message        = "Arduino no detectado";
         SensorNotFoundExceptio ex = new SensorNotFoundExceptio(message);
         throw ex;
     }
     else
     {
         return(ports);
     }
 }
Exemple #3
0
        public void WriteColorRGB(Int16 r, Int16 g, Int16 b)
        {
            string rgb = r.ToString() + "," + g.ToString() + "," + b.ToString() + ",";

            try
            {
                serialPort.Write(rgb);
            }
            catch (Exception e)
            {
                message = "Error al escribir";
                SensorNotFoundExceptio ex = new SensorNotFoundExceptio(message);
                throw ex;
            }
        }
Exemple #4
0
 public string[] ExistingPorts()
 {
     //string[] ports = SerialPort.GetPortNames();
     string[] portnames = SerialPort.GetPortNames();
     if (portnames.Length > 0)
     {
         using (var searcher = new ManagementObjectSearcher
                                   ("SELECT * FROM WIN32_SerialPort"))
         {
             var ports = searcher.Get().Cast <ManagementBaseObject>().ToList();
             var tList = (from n in portnames
                          join p in ports on n equals p["DeviceID"].ToString()
                          select n + " - " + p["Caption"]).ToList();
             return(tList.ToArray());
         }
     }
     else
     {
         message = "Arduino no detectado";
         SensorNotFoundExceptio ex = new SensorNotFoundExceptio(message);
         throw ex;
     }
 }