Exemplo n.º 1
0
 public PLCSerialPortInfo(SerialPortInfo serialPortInfo)
 {
     UpdateInfo(serialPortInfo);
     InitOpenSerialPortCommand();
     InitEditCommand();
     InitDeleteCommand();
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
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 && 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);
        }
        /// <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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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;
     }
 }
Exemplo n.º 7
0
 public PLCSerialPortInfo(SerialPortInfo serialPortInfo)
 {
     UpdateInfo(serialPortInfo);
     InitOpenSerialPortCommand();
     InitEditCommand();
     InitDeleteCommand();
     TLSerialPort.DataReceived += TLSerialPort_DataReceived;
     Task.Factory.StartNew(AnalyseDatas);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 10
0
        public async Task OpenAsync(SerialPortInfo portInfo)
        {
            _serialPort = _deviceManager.CreateSerialPort(portInfo);

            await _serialPort.OpenAsync();

            StartListening();

            IsConected = true;
        }
Exemplo n.º 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();
 }
Exemplo n.º 12
0
        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;
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 14
0
        public SerialPortInfo GetSerialPortInfo()
        {
            var serialPortInfo = new SerialPortInfo
            {
                PortSignName = PortSignName,
                PortName     = PortName,
                BaudRates    = BaudRates,
                DataBits     = DataBits,
                Parity       = Parity,
                StopBits     = StopBits
            };

            return(serialPortInfo);
        }
Exemplo n.º 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);
        }
Exemplo n.º 16
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));
            }
            return(null);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
            }
        }
        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; }
        }
    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;
    }
Exemplo n.º 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)
                );
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 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");
            }
        }
Exemplo n.º 27
0
 protected ArduinoController(SerialPortInfo port)
 {
     PortInfo           = port;
     Port               = new SerialPort(port.Name, 115200);
     Port.DataReceived += OnDataReceived;
 }
Exemplo n.º 28
0
 public SerialPortDataSource(SerialPortInfo spInfo, int baudrate = 115200)
 {
     PortInfo = spInfo;
     BaudRate = baudrate;
 }
Exemplo n.º 29
0
 public SerialPortDataSource()
 {
     PortInfo = new SerialPortInfo();
     BaudRate = 115200;
 }
Exemplo n.º 30
0
 public SerialPortEventArgs(SerialPortInfo e)
 {
     SerialPort = e;
 }