C sharp - System.IO.IOException: No existe el fichero ó dire

 
Vista:

System.IO.IOException: No existe el fichero ó dire

Publicado por luis angel (6 intervenciones) el 20/06/2010 01:48:44
hola amigos tengo un programita en c#, que trata de comunicar desde el c# con una tarjeta arduino conectada al puerto usb. el programita al momento de que lo corro no me sale error, y me sale el formulario, el problema es que mi formulario tiene dos botones, Star y Stop, cuando le doy clik a Start me aparece esto y no hace nada:

System.IO.IOException: No existe el fichero ó directorio
at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000]
at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
at System.IO.Ports.SerialPort.Open () [0x00000]
at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
at SimpleSerial.Form1.buttonStart_Click (System.Object sender, System.EventArgs e) [0x00020] in /home/pitis/Descargas/ZedGraphSampleCS_v5.0.9/ZedGraphSample/Form1.cs:26
at System.Windows.Forms.Control.OnClick (System.EventArgs e) [0x00000]
at System.Windows.Forms.Button.OnClick (System.EventArgs e) [0x00000]
at System.Windows.Forms.ButtonBase.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) [0x00000]
at System.Windows.Forms.Button.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) [0x00000]
at System.Windows.Forms.Control.WmLButtonUp (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.ButtonBase.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Button.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000]
at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000]


Espero alguien me pueda ayudar con esto les dejo el codigo del programa, espero alguien me pueda ayudar porfavor ya que lo tengo q entregar el lunes es examen saludos:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SimpleSerial
{
public partial class Form1 : Form
{
// agregamos una variable de tipo texto
string RxString;

public Form1()
{
InitializeComponent();
}

private void buttonStart_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM232";
serialPort1.BaudRate = 9600;

serialPort1.Open();
if (serialPort1.IsOpen)
{
buttonStart.Enabled = false;
buttonStop.Enabled = true;
textBox1.ReadOnly = false;
}
}

private void buttonStop_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
buttonStart.Enabled = true;
buttonStop.Enabled = false;
textBox1.ReadOnly = true;
}

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// el puerto esta cerrado no puede enviar ningun caracter
if (!serialPort1.IsOpen) return;

// es para el puerto este abiero declara char
char[] buff = new char[1];

// espera el caracter para el bufer
buff[0] = e.KeyChar;

// envia el caracter al bufer
serialPort1.Write(buff, 0, 1);

// Set the KeyPress event as handled so the character won't
// display locally. If you want it to display, omit the next line.
e.Handled = true;
}

private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
}

private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
RxString = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:System.IO.IOException: No existe el fichero ó d

Publicado por Omar  (8 intervenciones) el 22/06/2010 08:30:30
Posiblemente tengas mal asignadas las propiedades del Puerto

serialPort1.PortName = "COM232";
serialPort1.BaudRate = 9600;

y al ejecutar el metodo Open, truena...
serialPort1.Open();
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:System.IO.IOException: No existe el fichero ó d

Publicado por Kristophone (1 intervención) el 04/02/2014 19:11:52
Chequea bien en la excepción que te esta mandando..
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar