New Serial Port object in .net 2.0

There's a new serial port object (system.io.ports.serialport) in .NET 2.0 for VS 2005

It seems to be that this is similar to the original vb6 mscomm control

I can't figure out how to send a command to my serial port.

in VB6 my mscomm control sends correctly to my serial device, but trying the same functionality with this new object using mySerialPort.write OR mySerialPort.writeLine doesn't work.   I made the setting such as baud and parity and handshake, etc the ssame..

Anyone familiar with this control?

Shahzad
shahzadqAsked:
Who is Participating?
 
Bob LearnedCommented:
1) The SerialPort has a few constructors.  Here is the one that I find useful:

    http://msdn2.microsoft.com/en-us/library/z8d1ykfs.aspx

    Private portAxxess As New SerialPort("COM1", 4800, Parity.None, 8, StopBits.One)

2) Set the handshaking:

     portAxxess.Handshake = Handshake.RequestToSend

3) Set RTS enable:

    portAxxess.RtsEnable = True

4) Set DTR enable:
    portAxxess.DtrEnable = True

5) Receive threshold:

    portAxxess.ReceivedBytesThreshold = 1
    portAxxess.ReadBufferSize = 1

6) Write buffer size:

    portAxxess.WriteBufferSize = 1

7) ParityReplace only applies to invalid bytes in the data stream

8) You might want to think about the Encoding property, and if you need it

Bob
0
 
Bob LearnedCommented:
1) What kind of device are you using?
2) Is the port open?
3) Can you show me an example of the code you are using to send data?

Bob
0
 
shahzadqAuthor Commented:
It's a serial port device that is plugged into a corporate phone system called AXXESS.  It accept most regular MODEM commands...  That's how I've been running it in VB6, just sending "ATA" or "ATDT" or whatever straight to the com port.

Yeah, I've opened it.


Here's a couple of different code options I've tried...

   Private Sub btnHuntGroupToggle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuntGroupToggle.Click
        portAxxess.Open()
        portAxxess.WriteLine("ATDT 818013601062")
        portAxxess.Close()
    End Sub

OR

   Private Sub btnHuntGroupToggle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuntGroupToggle.Click
        portAxxess = My.Computer.Ports.OpenSerialPort("COM1", 4800)
        MsgBox(portAxxess.IsOpen)
        Using portAxxess
            portAxxess.WriteLine("ATDT 818013601062,,049")
        End Using
   End sub

Also tried it wih --
           portAxxess = My.Computer.Ports.OpenSerialPort("COM1", 4800)


*shrug*...   I dunno

Shahzadq
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Bob LearnedCommented:
1) Did you get the stop bits, data bits, parity settings too?  

2) Does the device require a carriage return to signal the end of a send operation?

3) How did you accomplish this with the M$Comm control in VB6?  

4) With the VB6 version, did you specify the device settings on the control or in code?

Bob
0
 
shahzadqAuthor Commented:
In my VB6 program, I have

DTREnable - True
HAndshaking - 2 - comRTS
Inbuffersize - 1
InputLen - 1
InputMode 0 -comInputModeText
ParityReplace - ?
RThreshold - 1
RTSEnable - True
Settings 4800,n,8,1
SThreshold - 1

The .Net control has slightly different settings, so it's hard for me to match them up exactly

shahzadq
0
 
shahzadqAuthor Commented:
Also, OutBufferSize = 0




The default for PArityReplace in .net is 63, whereas in VB6 it's "?"

That's kind of odd I think
0
 
shahzadqAuthor Commented:
Just double checked adding a chr(13) to the end of the string sent...  no luck...

It doesn't give any errors, but doesn't do anything either.  When stepping through in debugging, it just walks right over it.






shahzadq
0
 
shahzadqAuthor Commented:
Hmmm...  ok will see how that works.  I figured I had these all setup statically in the visual properites section, but I'll code it all in, also try that new constructor...

shahzadq
0
 
Bob LearnedCommented:
I am in favor of setting properties in code.  Then, you can recreate the control, without losing any property values.

Bob
0
 
shahzadqAuthor Commented:
Should I delete the static object first?  Or does that not matter?



shahzad
0
 
Bob LearnedCommented:
If you are creating the port and setting properties in code, then you don't need the instance on the form.

Bob
0
 
shahzadqAuthor Commented:
Holy Smokes!!!

It works!

Woo hoo!!

:)


Shahzad
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.