source: libi4uccore/posixserialportutils.vala @ a53703c84e851235b6d46cdb7474eb77bd295d17

Revision a53703c84e851235b6d46cdb7474eb77bd295d17, 1.4 KB checked in by Matias De la Puente <mfpuente.ar@…>, 2 years ago (diff)

Remove usage of glib-dbus for getting serial ports

In Unix type systems test if exists /dev/ttyS{0..31}, /dev/ttyUSB{0..31} and /dev/rfcomm{0..31}

In Windows type systems test if exists COM{1..32}

  • Property mode set to 100644
Line 
1/* posixserialportutils.vala
2 *
3 * Copyright (C) 2010-2011  Matias De la Puente
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 *      Matias De la Puente <mfpuente.ar@gmail.com>
20 */
21using Gee;
22
23public class I4uc.Core.PosixSerialPortUtils : SerialPortUtils
24{
25        public override Gee.List<string> list_serial_ports ()
26        {
27                var serial_ports = new ArrayList<string> ();
28               
29                // Test if exists /dev/ttyS{0..31}, /dev/ttyUSB{0..31} and /dev/rfcomm{0..31}
30                var dev_types = new string[] { "/dev/ttyS", "/dev/ttyUSB", "/dev/rfcomm" };
31                foreach (var dev_type in dev_types)
32                {
33                        for (var i=0; i<32; i++)
34                        {
35                                var device = "%s%d".printf (dev_type, i);
36                                if (FileUtils.test (device, FileTest.EXISTS))
37                                        serial_ports.add (device);
38                        }
39                }
40               
41                return serial_ports.read_only_view;
42        }
43}
Note: See TracBrowser for help on using the repository browser.