I want to obtain the weight of a scale through the serial port but I have this error
Error: System.IO.IOException: Uno de los dispositivos conectados al sistema no funciona.
en System.IO.Ports.InternalResources WintErrorent32 errorCode, String str
en System.IO.Ports InternalResources WinIOError
en System.IO.Ports SerialStream.InitializeDCB(Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Boolean discardNull
en System.IO.Ports. SeriatStream.ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull. Byte parityReplace) en System.IO.Ports.SerialPort Open
en puertoSerial.Form1.btnAccionPuerto Click(Object sender, EventArgs e) en
C\Users\Huawei Desktop puertoSerial puertoSerial Form1.cs:linea 43
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace puertoSerial {
public partial class Form1 : Form {
private bool conected = false;
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
string[] puertosDisponibles = SerialPort.GetPortNames();
cbPuertos.Items.Clear();
foreach (string puerto in puertosDisponibles) {
cbPuertos.Items.Add(puerto);
}
}
private void btnAccionPuerto_Click(object sender, EventArgs e) {
if (!conected) {
spPuertos.PortName = cbPuertos.Text;
spPuertos.BaudRate = Int32.Parse(cbBaudRate.Text);
spPuertos.DataBits = 8;
spPuertos.Parity = Parity.None;
spPuertos.StopBits = StopBits.One;
spPuertos.Handshake = Handshake.None;
try {
spPuertos.Open();
conected = true;
btnAccionPuerto.Text = "DESCONECTAR";
} catch(Exception er) {
MessageBox.Show("Error: "+ er);
}
}
else {
spPuertos.Close();
conected= false;
btnAccionPuerto.Text = "CONECTAR";
}
}
private void spPuertos_DataReceived(object sender, SerialDataReceivedEventArgs e) {
string data_in = spPuertos.ReadExisting();
MessageBox.Show(data_in);
}
}
}