hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Serial Port Access

Last post 03-05-2008, 0:50 by Robert. 1 replies.
Sort Posts: Previous Next
  •  03-04-2008, 23:42 5191

    Serial Port Access

    Hi everybody

    I want to use the serial port class in the .Net Framework to access COM-port devices.

    I am presently able to open a port and send some data over the port as follows:

    #light

    open System.IO.Ports

    let availablePortsArray = SerialPort.GetPortNames

    let s1 = new SerialPort ("COM5",9600)

    if s1.IsOpen then print_endline "Port is Open"

    s1.Open()

    s1.Write "0xFF"

    s1.Write "Hello World"

    s1.Close()

    if s1.IsOpen then print_endline "Port is Open"

    //end of code

     

     

    FSI output:

    val availablePortsArray : unit -> string []

    val s1 : SerialPort

    How do I access the array "availablePortsArray" to see what ports are 
    available for the current computer?
    Kind Regards
  •  03-05-2008, 0:50 5193 in reply to 5191

    Re: Serial Port Access

    "availablePortsArray" is actually a function because you're missing the () from the end when trying to call it. The following change should fix your problem:

    let availablePortsArray = SerialPort.GetPortNames()


    Robert Pickering
    http://strangelights.com
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems