コード例 #1
0
 public PLCSerialPortInfo(SerialPortInfo serialPortInfo)
 {
     UpdateInfo(serialPortInfo);
     InitOpenSerialPortCommand();
     InitEditCommand();
     InitDeleteCommand();
 }
コード例 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            imageList1.Images.Add(SystemIcons.Information);
            imageList1.Images.Add(SystemIcons.Warning);
            imageList1.Images.Add(SystemIcons.Error);

            checkBoxShowMessages.ImageIndex = 0;
            checkBoxShowWarnings.ImageIndex = 1;
            checkBoxShowErrors.ImageIndex   = 2;

            //dataGridView1.AutoGenerateColumns = false;
            //dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { DataPropertyName = "Name", HeaderText = "Variable" });
            //dataGridView1.Columns.Add(new DataGridViewTextBoxColumn() { DataPropertyName = "Value", HeaderText = "Value" });
            dataGridView1.DataSource = variableList;

            LoadEventDescriptors();

            se.Variables = variables;

            UpdatePortList();

            var ports = SerialPortInfo.GetSerialPorts();

            foreach (var p in ports)
            {
                if (p.ToString() == Settings.Default.Port)
                {
                    comboBoxPort.Text = p.ToString();
                }
            }

            checkBoxRun_CheckedChanged(null, null);
        }
コード例 #3
0
ファイル: ArduinoController.cs プロジェクト: valandil/munia
        public static List <ArduinoController> ListDevices()
        {
            var ret   = new List <ArduinoController>();
            var ports = SerialPortInfo.GetPorts();

            foreach (var entry in ConfigManager.ArduinoMapping)
            {
                var port = ports.FirstOrDefault(p => p.Name == entry.Key && p.IsConnected);
                if (port != null)
                {
                    switch (entry.Value)
                    {
                    case ControllerType.SNES:
                        ret.Add(new ArduinoSnes(port));
                        break;

                    case ControllerType.N64:
                        ret.Add(new ArduinoN64(port));
                        break;

                    case ControllerType.NGC:
                        ret.Add(new ArduinoNgc(port));
                        break;
                    }
                }
            }
            return(ret);
        }
コード例 #4
0
        /// <summary>
        /// 시리얼 포트 정보를 조회하여 설정한다.
        /// </summary>
        /// <param name="_strComPortName">컴포트 명</param>
        /// <returns></returns>
        public SerialPortInfo SerialPortLoad(string _strComPortName)
        {
            SerialPortInfo _result         = null;
            int            _resultPortNo   = -1;
            int            _resultBaudRate = -1;

            try
            {
                var    _strPort     = _strComPortName;
                var    _strBaudRate = "9600";
                string _SerialPort  = string.Empty;

                if (!string.IsNullOrWhiteSpace(_strPort))
                {
                    int.TryParse(_strPort, out _resultPortNo);
                }

                if (!string.IsNullOrWhiteSpace(_strBaudRate))
                {
                    int.TryParse(_strBaudRate, out _resultBaudRate);
                }

                if (_strComPortName.Contains("COM") == true)
                {
                    _SerialPort = _strComPortName;
                }
                else
                {
                    _SerialPort = $"COM{_resultPortNo.ToWhiteSpaceOrString()}";
                }

                if (!SerialPort.GetPortNames().Contains(_SerialPort) || _resultBaudRate < -1)
                {
                    var strMessage = this.BaseClass.GetResourceValue("ERR_BARSCN_SERIAL_NOT_FOUND");
                    this.BaseClass.MsgError(string.Format(strMessage, _SerialPort), BaseEnumClass.CodeMessage.MESSAGE);
                }
                else
                {
                    _result = new SerialPortInfo {
                        PortNo = _resultPortNo, BaudRate = _resultBaudRate
                    };
                }
            }
            catch (Exception err)
            {
                this.BaseClass.Error(new Exception("SerialPortLoad ERROR  : " + err.ToString()));
            }

            if (_resultPortNo > -1 && _resultBaudRate > -1)
            {
                return(new SerialPortInfo {
                    PortNo = _resultPortNo, BaudRate = _resultBaudRate
                });
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
        public void LoadFrom(XmlNode xn)
        {
            MappedType = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["type"].Value, true);
            Source     = (SourceType)Enum.Parse(typeof(SourceType), xn.Attributes["source"].Value, true);
            UUID       = xn.Attributes["uuid"] != null?Guid.Parse(xn.Attributes["uuid"].Value) : Guid.NewGuid();

            if (Source == SourceType.RawInput)
            {
                VendorID    = int.Parse(xn.Attributes["vid"].Value, NumberStyles.HexNumber);
                ProductID   = int.Parse(xn.Attributes["pid"].Value, NumberStyles.HexNumber);
                ReportHash  = uint.Parse(xn.Attributes["rpt_hash"].Value);
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.XInput)
            {
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.MUNIA)
            {
                DevicePath = xn.Attributes["devicepath"].Value;
            }
            else if (Source == SourceType.Arduino)
            {
                string port = xn.Attributes["arduino_port"].Value;
                ArduinoPort = SerialPortInfo.GetPorts().FirstOrDefault(spi => spi.Name == port) ?? new SerialPortInfo {
                    Name = port
                };
                ArduinoSource = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["arduino_type"].Value, true);
            }

            foreach (XmlNode n in xn["buttons"].ChildNodes)
            {
                var btn = new ButtonMap();
                btn.LoadFrom(n);
                ButtonMaps.Add(btn);
            }

            foreach (XmlNode n in xn["axes"].ChildNodes)
            {
                var axis = new AxisMap();
                axis.LoadFrom(n);
                AxisMaps.Add(axis);
            }

            foreach (XmlNode n in xn["buttons_to_axis"].ChildNodes)
            {
                var button = new ButtonToAxisMap();
                button.LoadFrom(n);
                ButtonToAxisMaps.Add(button);
            }

            foreach (XmlNode n in xn["axis_to_buttons"].ChildNodes)
            {
                var axis = new AxisToButtonMap();
                axis.LoadFrom(n);
                AxisToButtonMaps.Add(axis);
            }
        }
コード例 #6
0
 private void optionsToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
 {
     comboBoxPorts.Items.Clear();
     comboBoxPorts.Items.AddRange(SerialPortInfo.GetSerialPorts());
     if (comboBoxPorts.SelectedIndex < 0 || comboBoxPorts.Text == "")
     {
         comboBoxPorts.SelectedIndex = 0;
     }
 }
コード例 #7
0
 public PLCSerialPortInfo(SerialPortInfo serialPortInfo)
 {
     UpdateInfo(serialPortInfo);
     InitOpenSerialPortCommand();
     InitEditCommand();
     InitDeleteCommand();
     TLSerialPort.DataReceived += TLSerialPort_DataReceived;
     Task.Factory.StartNew(AnalyseDatas);
 }
コード例 #8
0
 public void UpdateInfo(SerialPortInfo serialPortInfo)
 {
     PortSignName = serialPortInfo.PortSignName;
     PortName     = serialPortInfo.PortName;
     BaudRates    = serialPortInfo.BaudRates;
     DataBits     = serialPortInfo.DataBits;
     Parity       = serialPortInfo.Parity;
     StopBits     = serialPortInfo.StopBits;
 }
コード例 #9
0
        public SerialPortDataSource(string portname, int baudrate)
        {
            var ports = SerialPortInfo.GetPorts();

            PortInfo = ports.FirstOrDefault(p => p.Name == portname) ?? new SerialPortInfo {
                Name        = portname,
                Description = "Disconnected device"
            };
            BaudRate = baudrate;
        }
コード例 #10
0
        public async Task OpenAsync(SerialPortInfo portInfo)
        {
            _serialPort = _deviceManager.CreateSerialPort(portInfo);

            await _serialPort.OpenAsync();

            StartListening();

            IsConected = true;
        }
コード例 #11
0
 public void Setup(SerialPortInfo Info)
 {
     m_ComeInfo = Info;
     Properties.Settings.Default.Com      = m_ComeInfo.Com;
     Properties.Settings.Default.BaudRate = m_ComeInfo.BaudRate;
     Properties.Settings.Default.DataBits = m_ComeInfo.DataBits;
     Properties.Settings.Default.Parity   = m_ComeInfo.Parity;
     Properties.Settings.Default.StopBits = m_ComeInfo.StopBits;
     Properties.Settings.Default.Save();
 }
コード例 #12
0
ファイル: MainForm.cs プロジェクト: heyazhou/LineLaserMapping
        private void FillPortList()
        {
            SerialPortInfo[] portInfos = sCom.GetPortNames();
            comboBoxPort.Items.Clear();
            comboBoxPort.Items.AddRange(portInfos);
            SerialPortInfo arduinoPort = portInfos.FirstOrDefault(p => p.Name.Contains("Arduino"));

            if (arduinoPort != null)
            {
                comboBoxPort.SelectedItem = arduinoPort;
            }
        }
コード例 #13
0
        public MainWindow()
        {
            InitializeComponent();
            sc = new SerialCommunicator();
            List <SerialPortInfo> portInfos   = sc.getPortNames();
            SerialPortInfo        arduinoPort = portInfos.FirstOrDefault(p => p.Name.Contains("Arduino"));

            if (arduinoPort != null)
            {
                //sc.connect(this, receive, arduinoPort.Name, 9600);
            }
        }
コード例 #14
0
        public SerialPortInfo GetSerialPortInfo()
        {
            var serialPortInfo = new SerialPortInfo
            {
                PortSignName = PortSignName,
                PortName     = PortName,
                BaudRates    = BaudRates,
                DataBits     = DataBits,
                Parity       = Parity,
                StopBits     = StopBits
            };

            return(serialPortInfo);
        }
コード例 #15
0
        public static List <ArduinoController> ListDevices()
        {
            var ret   = new List <ArduinoController>();
            var ports = SerialPortInfo.GetPorts();

            foreach (var entry in ConfigManager.ArduinoMapping)
            {
                var port = ports.FirstOrDefault(p => p.Name == entry.Key);
                if (port != null && entry.Value != ControllerType.None)
                {
                    ret.Add(CreateDevice(port, entry.Value));
                }
            }
            return(ret);
        }
コード例 #16
0
ファイル: ArduinoController.cs プロジェクト: ROMaster2/munia
        public static ArduinoController CreateDevice(SerialPortInfo port, ControllerType type)
        {
            switch (type)
            {
            case ControllerType.SNES:
                return(new ArduinoSnes(port));

            case ControllerType.N64:
                return(new ArduinoN64(port));

            case ControllerType.NGC:
                return(new ArduinoNgc(port));
            }
            return(null);
        }
コード例 #17
0
        public Form1()
        {
            InitializeComponent();

            sCom1     = new SerialCommunicator();
            portInfos = sCom1.GetPortNames();
            portComboBox.Items.Clear();
            portComboBox.Items.AddRange(portInfos);
            SerialPortInfo arduinoPort = portInfos.FirstOrDefault(p => p.Name.Contains("Arduino"));

            if (arduinoPort != null)
            {
                portComboBox.SelectedItem = arduinoPort;
            }

            UpdateGui();
        }
コード例 #18
0
 private void ProcessComPortInfo(
     SerialPortInfo comPortInfo,
     Action actionWhileComPortNotFound = null,
     Action <SerialPortInfo> actionIfComPortIsFound = null
     )
 {
     if (comPortInfo == null)
     {
         _logger.LogError("Не удалось найти соответствующий COM порт!");
         actionWhileComPortNotFound?.Invoke();
     }
     else
     {
         _logger.LogInformation($"COM порт найден: {comPortInfo.Title}");
         actionIfComPortIsFound?.Invoke(comPortInfo);
     }
 }
コード例 #19
0
        public static ArduinoController CreateDevice(SerialPortInfo port, ControllerType type)
        {
            switch (type)
            {
            case ControllerType.SNES:
                return(new ArduinoSnes(port));

            case ControllerType.N64:
                return(new ArduinoN64(port));

            case ControllerType.NGC:
                return(new ArduinoNgc(port));

            default:
                throw new ArgumentOutOfRangeException("type is not one of possible arduino devices");
            }
            return(null);
        }
コード例 #20
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            comPortsComboBox.Items.AddRange(SerialPortInfo.GetSerialPorts());
            try
            {
                comPortsComboBox.SelectedIndex = 0;
            } catch (ArgumentOutOfRangeException) { }
            powerComboBox.SelectedIndex   = 0;
            channelComboBox.SelectedIndex = 0;
            var pane = zedGraphControl.GraphPane;

            pane.Title.IsVisible       = false;
            pane.XAxis.Title.IsVisible = false;
            pane.YAxis.Title.IsVisible = false;
            pane.Fill             = new Fill(Color.Transparent);
            pane.Border.IsVisible = false;
            pane.Chart.Fill       = new Fill(Color.Black);
        }
コード例 #21
0
        private void UpdateDeviceSources(string selectPort = null)
        {
            var selected = cbSerialPort.SelectedItem;

            cbSerialPort.Items.Clear();
            var ports = SerialPortInfo.GetPorts().ToArray();

            cbSerialPort.Items.AddRange(ports);
            // keep currently selected if still exists
            if (ports.Contains(selected))
            {
                cbSerialPort.SelectedItem = selected;
            }
            // else select newly arrived port
            else
            {
                cbSerialPort.SelectedItem = ports.FirstOrDefault(p => p.Name.Equals(selectPort));
            }
        }
コード例 #22
0
        private ScannerConnectResult InitScanner()
        {
            try
            {
                ScannerConnectResult result         = new ScannerConnectResult();
                SerialPortInfo       serialPortInfo = null;
                string strPortName = string.Empty;

                switch (this.SerialCommMethod)
                {
                case BaseEnumClass.SerialCommMethod.SERIAL_STX_ETX:

                    break;

                case BaseEnumClass.SerialCommMethod.SERIAL_CR_LF:
                    break;
                }
            }
            catch { throw; }
        }
コード例 #23
0
    public async Task RefreshPorts()
    {
        var token = _cancellationSource.Token;

        IsRefreshBusy = true;
        await Task.Delay(750, token).ConfigureAwait(true);

        var lastSelectedDeviceId = SelectedSerialPortDeviceId;

        SerialPorts.Clear();
        try
        {
            var scope    = new ManagementScope("\\\\.\\ROOT\\cimv2");
            var observer = new ManagementOperationObserver();
            using var searcher = new ManagementObjectSearcher(scope, new SelectQuery("Win32_PnPEntity"));

            observer.ObjectReady += (_, e) =>
            {
                var portInfo = SerialPortInfo.FromManagementObject(e.NewObject as ManagementObject);
                if (portInfo == null)
                {
                    return;
                }

                SerialPorts.Add(portInfo);
            };

            var taskCompletion = new TaskCompletionSource();
            observer.Completed += (_, _) => taskCompletion.TrySetResult();

            searcher.Get(observer);
            using (token.Register(() => taskCompletion.TrySetCanceled()))
                await taskCompletion.Task.WaitAsync(token).ConfigureAwait(true);
        }
        catch { }

        SelectSerialPortByDeviceId(lastSelectedDeviceId);
        await Task.Delay(250, token).ConfigureAwait(true);

        IsRefreshBusy = false;
    }
コード例 #24
0
        private void InitializeSerialPort(SerialPortInfo serialPortInfo)
        {
            _serialPort = new SerialPort(serialPortInfo.PortName, 9600)
            {
                DtrEnable = true,
                RtsEnable = true
            };
            _serialPort.DataReceived += SerialPortOnDataReceived;
            if (!_serialPort.IsOpen)
            {
                _serialPort.Open();
            }

            _serialPortInfo = serialPortInfo;

            _serialPortHealthTimer ??= new Timer(
                e => SerialPortHealthCheckByTimer(),
                null,
                TimeSpan.FromSeconds(SerialPortHealthCheckPeriod),
                TimeSpan.FromSeconds(SerialPortHealthCheckPeriod)
                );
        }
コード例 #25
0
ファイル: XMLOperation.cs プロジェクト: scaperow/-V2.0
        /// <summary>
        public SerialPortInfo GetSerialPort()
        {
            String FilePath = Path.Combine(Application.StartupPath, "SerialPortInfos.xml");

            if (!File.Exists(FilePath))
            {
                return(null);
            }
            DataSet        SerialPortDate = new DataSet();
            SerialPortInfo SPInfo         = new SerialPortInfo();

            try
            {
                SerialPortDate.ReadXml(FilePath);

                SPInfo = (Deserialize(SerialPortDate.Tables[0].Rows[0]["SerialPortInfo"].ToString())) as SerialPortInfo;
                File.Delete(FilePath);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(SPInfo);
        }
コード例 #26
0
        private void RefreshListbox()
        {
            lbSerialPorts.Items.Clear();
            var ports = SerialPortInfo.GetPorts().ToList();

            foreach (var spi in ports)
            {
                lbSerialPorts.Items.Add(spi);
            }
            foreach (var entry in Mapping)
            {
                // if port was mapped, but now unavailable, don't hide the original mapping
                if (ports.All(p => p.Name != entry.Key))
                {
                    lbSerialPorts.Items.Add(new SerialPortInfo {
                        Name = entry.Key, Description = "Unavailable"
                    });
                }
            }
            if (!ports.Any() && !Mapping.Any())
            {
                lbSerialPorts.Items.Add("None available");
            }
        }
コード例 #27
0
ファイル: ArduinoController.cs プロジェクト: valandil/munia
 protected ArduinoController(SerialPortInfo port)
 {
     PortInfo           = port;
     Port               = new SerialPort(port.Name, 115200);
     Port.DataReceived += OnDataReceived;
 }
コード例 #28
0
 public SerialPortDataSource(SerialPortInfo spInfo, int baudrate = 115200)
 {
     PortInfo = spInfo;
     BaudRate = baudrate;
 }
コード例 #29
0
 public SerialPortDataSource()
 {
     PortInfo = new SerialPortInfo();
     BaudRate = 115200;
 }
コード例 #30
0
 public SerialPortEventArgs(SerialPortInfo e)
 {
     SerialPort = e;
 }