Community discussion forum

Port.Writeline using VB 2008 express

  • 4 months ago

    I trying to send a string to a Quasar relay kit #3108v3 using the code below. The com port is opening ok yet I can trigger a relay? Help its so easy in qbasic a simple print command.

     Imports System
    Imports System.IO.Ports
    Namespace Shauntrapmatic.test
    
        Public Class shauntest
            Public Shared Sub Main()
    
    
                Console.WriteLine("Available Ports on this computer:")
                For Each portname As String In SerialPort.GetPortNames
                    Console.WriteLine("PORT: " & portname)
                Next
                Console.WriteLine()
    
                Dim testport As String = SerialPort.GetPortNames(0)
    
                Using port As New SerialPort(testport)
                    port.BaudRate = 9600
                    port.DataBits = 8
                    port.Parity = Parity.None
                    port.StopBits = StopBits.One
    
                    'Write a string
                    port.Open()
    
                    port.WriteLine("N1")
    
                    port.Close()
    
                    Console.WriteLine("Wrote to the {0} port ", testport)
    
                End Using
    
                Console.WriteLine(Environment.NewLine)
                Console.WriteLine("Main method complete. Press Enter ")
                Console.ReadLine()
            End Sub
    
        End Class
    End Namespace
    

    N1 being the relay's command to turn on relay 1

    What am I doing wrong?????

    Post was edited on 01/07/2009 12:16:20 Report abuse

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback