Help with SerialPort

Discussion in 'ASP .Net' started by Benedictum, May 22, 2008.

  1. Benedictum

    Benedictum Guest

    I have the following method that initializes the port. I am having problems
    assigning values to the Serial port properties. Can someone help ? Here is
    the snippet with my comments:

    private void btnOpenPort_Click(object sender, EventArgs e)

    {

    if (ServoPort.IsOpen)

    {

    ServoPort.Close();

    btnOpenPort.Text = "Open Port";

    }

    else

    {

    // SerialPort parameters

    ServoPort.PortName = tbxSPortName.Text; // This is OK

    ServoPort.BaudRate = int.Parse(tbxSBaud.Text); // This is OK

    ServoPort.Parity = int.Parse(tbxSParity.Text); // ERROR!

    ServoPort.DataBits = int.Parse(tbxSDatabits.Text); // This is OK

    ServoPort.StopBits = int.Parse(tbxSStopbit.Text); //ERROR!

    btnOpenPort.Text = "Close Port";

    }

    }

    Any other ideas are welcome.
    Benedictum, May 22, 2008
    #1
    1. Advertising

  2. Benedictum

    bruce barker Guest

    parity and stopbits are enums not ints. be sure you have the correct values.
    also be sure that ServoPort is a static (shared across page requests). also
    you should implement locking so two page requests do not access the port at
    the same time.

    if you are trying to control more than one server serial port, then keep a
    collection of port managers and use the name as a key.

    -- bruce (sqlwork.com)


    "Benedictum" wrote:

    > I have the following method that initializes the port. I am having problems
    > assigning values to the Serial port properties. Can someone help ? Here is
    > the snippet with my comments:
    >
    > private void btnOpenPort_Click(object sender, EventArgs e)
    >
    > {
    >
    > if (ServoPort.IsOpen)
    >
    > {
    >
    > ServoPort.Close();
    >
    > btnOpenPort.Text = "Open Port";
    >
    > }
    >
    > else
    >
    > {
    >
    > // SerialPort parameters
    >
    > ServoPort.PortName = tbxSPortName.Text; // This is OK
    >
    > ServoPort.BaudRate = int.Parse(tbxSBaud.Text); // This is OK
    >
    > ServoPort.Parity = int.Parse(tbxSParity.Text); // ERROR!
    >
    > ServoPort.DataBits = int.Parse(tbxSDatabits.Text); // This is OK
    >
    > ServoPort.StopBits = int.Parse(tbxSStopbit.Text); //ERROR!
    >
    > btnOpenPort.Text = "Close Port";
    >
    > }
    >
    > }
    >
    > Any other ideas are welcome.
    >
    >
    >
    >
    >
    bruce barker, May 22, 2008
    #2
    1. Advertising

  3. Benedictum

    id10t error Guest

    On May 22, 11:34 am, "Benedictum" <> wrote:
    > I have the following method that initializes the port. I am having problems
    > assigning values to the Serial port properties. Can someone help ? Here is
    > the snippet with my comments:
    >
    > private void btnOpenPort_Click(object sender, EventArgs e)
    >
    > {
    >
    > if (ServoPort.IsOpen)
    >
    > {
    >
    > ServoPort.Close();
    >
    > btnOpenPort.Text = "Open Port";
    >
    > }
    >
    > else
    >
    > {
    >
    > // SerialPort parameters
    >
    > ServoPort.PortName = tbxSPortName.Text; // This is OK
    >
    > ServoPort.BaudRate = int.Parse(tbxSBaud.Text); // This is OK
    >
    > ServoPort.Parity = int.Parse(tbxSParity.Text); // ERROR!
    >
    > ServoPort.DataBits = int.Parse(tbxSDatabits.Text); // This is OK
    >
    > ServoPort.StopBits = int.Parse(tbxSStopbit.Text); //ERROR!
    >
    > btnOpenPort.Text = "Close Port";
    >
    > }
    > }
    >
    > Any other ideas are welcome.


    Here is what I used in vb. I am not sure if it will help

    Function SendSampleData(ByVal copies As String)
    'Instantiate the communications port with some basic settings
    Dim count As String = 0
    Dim port As SerialPort
    port = New SerialPort("COM1", 9600, Parity.None, 8,
    StopBits.One)

    ' Open the port for communications
    port.Open()
    Do Until count = copies
    ' Write a string
    port.Write("EZ{PRINT,STOP350:mad:20,35:ZP08A|003")
    count = count + 1
    Loop

    ' Close the port
    port.Close()
    Return 0
    id10t error, May 22, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Taylor

    .NET Framework 2. SerialPort

    Ryan Taylor, Jan 10, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    3,100
    Yuri Astrakhan
    Mar 28, 2005
  2. Ny Het

    Problem accessing Serialport

    Ny Het, Oct 7, 2004, in forum: Java
    Replies:
    1
    Views:
    313
    Paul Lutus
    Oct 7, 2004
  3. hbk
    Replies:
    0
    Views:
    894
  4. =?Utf-8?B?VGFtaXIuRA==?=

    System.IO.Ports.SerialPort

    =?Utf-8?B?VGFtaXIuRA==?=, May 11, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    4,050
    =?Utf-8?B?VGFtaXIuRA==?=
    May 12, 2006
  5. Eduardo Aldaz-carroll

    Help getting ruby-serialport to run in Windows XP

    Eduardo Aldaz-carroll, Apr 25, 2008, in forum: Ruby
    Replies:
    2
    Views:
    123
    Eduardo Aldaz-carroll
    Apr 28, 2008
Loading...

Share This Page