Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

Help with SerialPort

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Benedictum - 22 May 2008 16:34 GMT
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 - 22 May 2008 18:14 GMT
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)

> 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
[quoted text clipped - 37 lines]
>
> Any other ideas are welcome.
id10t error - 22 May 2008 18:20 GMT
> 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
[quoted text clipped - 36 lines]
>
> 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:@20,35:ZP08A|003")
           count = count + 1
       Loop

       ' Close the port
       port.Close()
       Return 0

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.