Help with SerialPort and C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrea Judge

    Help with SerialPort and C#

    Hi there,

    I'm developing an application to catch OBD sensors' data from my car.
    I connect it via a RS232 interface.
    Now.
    with HyperTerminal I can connect and send/receive data, but I'd like to do
    this from inside my C# program.
    Anyone can write down a very small (or tell how to do it myself) application
    containing methods like WriteToSerialPo rt(string what) and
    ReadFromSerialP ort(what).

    Using the built in control SerialPort, I can correctly open a port, and
    write something to it (commands like "ATX" and other worked fine from
    HyperTerminal), but I can't read nothing, using SerialPort.Read Line(). This
    method always generates a Timeout exception.

    What's wrong?
    To send, for example, the "ATX" command through the serial port, I use
    SerialPort.Writ e("ATX"), but nothing seems to happen.

    Hope someone will help me soon!!!


    Andrea


  • Ales

    #2
    Re: Help with SerialPort and C#

    Hi,
    you should use SerialPort.Read Line() when you recive DataReceived
    event. If no event is triggered then you didn't recive any data.

    Try to send SerialPort.Writ eLine("ATX") or SerialPort.Writ e("ATX\r").

    Ales

    Andrea Judge je napisal:[color=blue]
    > Hi there,
    >
    > I'm developing an application to catch OBD sensors' data from my car.
    > I connect it via a RS232 interface.
    > Now.
    > with HyperTerminal I can connect and send/receive data, but I'd like to do
    > this from inside my C# program.
    > Anyone can write down a very small (or tell how to do it myself) application
    > containing methods like WriteToSerialPo rt(string what) and
    > ReadFromSerialP ort(what).
    >
    > Using the built in control SerialPort, I can correctly open a port, and
    > write something to it (commands like "ATX" and other worked fine from
    > HyperTerminal), but I can't read nothing, using SerialPort.Read Line(). This
    > method always generates a Timeout exception.
    >
    > What's wrong?
    > To send, for example, the "ATX" command through the serial port, I use
    > SerialPort.Writ e("ATX"), but nothing seems to happen.
    >
    > Hope someone will help me soon!!!
    >
    >
    > Andrea[/color]

    Comment

    • ozbear

      #3
      Re: Help with SerialPort and C#

      On Thu, 22 Dec 2005 18:32:27 +0100, "Andrea Judge"
      <judge@SPAMNOGR AZIEarea51staff .it> wrote:
      [color=blue]
      >Hi there,
      >
      >I'm developing an application to catch OBD sensors' data from my car.
      >I connect it via a RS232 interface.
      >Now.
      >with HyperTerminal I can connect and send/receive data, but I'd like to do
      >this from inside my C# program.
      >Anyone can write down a very small (or tell how to do it myself) application
      >containing methods like WriteToSerialPo rt(string what) and
      >ReadFromSerial Port(what).
      >
      >Using the built in control SerialPort, I can correctly open a port, and
      >write something to it (commands like "ATX" and other worked fine from
      >HyperTerminal) , but I can't read nothing, using SerialPort.Read Line(). This
      >method always generates a Timeout exception.
      >
      >What's wrong?
      >To send, for example, the "ATX" command through the serial port, I use
      >SerialPort.Wri te("ATX"), but nothing seems to happen.
      >
      >Hope someone will help me soon!!!
      >
      >
      >Andrea
      >
      >[/color]

      Send a carriage return along with your command string.

      Oz
      --
      A: Because it fouls the order in which people normally read text.
      Q: Why is top-posting such a bad thing?
      A: Top-posting.
      Q: What is the most annoying thing on usenet and in e-mail?

      Comment

      Working...