none
$port.writeline unwanted line feed RRS feed

  • Question

  • I have a Numato Labs usb DAQ that I'm trying to utilize in a project using PowerShell. The DAQ appears in the system as a simple com port.  For setting and clearing its GPO's the device expects a simple character string that's terminated with a carriage return. When I send the string as follows:

    $port.writeline("gpio set 6`r")

    ...it sends the character string and the carriage return, but at the end sends a line feed.  The line feed character stays in the buffer of the DAQ and prevents any further successful communication.  How can I prevent the writeline command from sending the unwanted line feed?

    Monday, May 16, 2016 9:25 PM

Answers

  • Most DACs work with writeline and do not require you to place a return at the end.  The linefeed is ignored.  Sending <ret><lf> cause a blank line and an orphaned linefeed which can hag some DACs. 

    An even better method is to set the terminator and use writeline as it is more normal.

    $port.NewLine="`r"

    Now writeline and readline will only use a single return character([char]13).


    \_(ツ)_/


    • Edited by jrv Monday, May 16, 2016 10:42 PM
    • Marked as answer by Chalk-X CPG Tuesday, May 17, 2016 1:24 PM
    Monday, May 16, 2016 10:42 PM
  • Again: Use the Write method, rather than WriteLine method. The Write method doesn't append a newline, as already stated. (The fact that we don't support your device is an aside and a reminder.)

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Chalk-X CPG Tuesday, May 17, 2016 1:24 PM
    Monday, May 16, 2016 11:33 PM
    Moderator

All replies

  • If the $port object has a write method instead of writeline, you can use that.

    Otherwise, omit the `r at the end of your string.

    Aside from that, please note that this is not a support forum for your device.


    -- Bill Stewart [Bill_Stewart]


    Monday, May 16, 2016 9:37 PM
    Moderator
  • I'm not seeking support for my device.  Its requirements are clear.  I'm asking for guidance with using PowerShell to meet those requirements.  The `r is necessary to get the required carriage return.  But there is apparently a default line feed being sent after the carriage return that is causing a problem.  I'm creating and opening the com port as follows:

    $port= new-object system.io.ports.serialport com7,9600,none,8,one

    $port.open()

    The writeline method has worked with other DAQs that I've used, but this one has more specific requirements.  Is there a way to output my strings without the unwanted line feed?  Is there an alternative to the writeline method that will work here?

    Monday, May 16, 2016 9:56 PM
  • Most DACs work with writeline and do not require you to place a return at the end.  The linefeed is ignored.  Sending <ret><lf> cause a blank line and an orphaned linefeed which can hag some DACs. 

    An even better method is to set the terminator and use writeline as it is more normal.

    $port.NewLine="`r"

    Now writeline and readline will only use a single return character([char]13).


    \_(ツ)_/


    • Edited by jrv Monday, May 16, 2016 10:42 PM
    • Marked as answer by Chalk-X CPG Tuesday, May 17, 2016 1:24 PM
    Monday, May 16, 2016 10:42 PM
  • Again: Use the Write method, rather than WriteLine method. The Write method doesn't append a newline, as already stated. (The fact that we don't support your device is an aside and a reminder.)

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Chalk-X CPG Tuesday, May 17, 2016 1:24 PM
    Monday, May 16, 2016 11:33 PM
    Moderator
  • I'm not seeking support for my device.  Its requirements are clear.  I'm asking for guidance with using PowerShell to meet those requirements.  The `r is necessary to get the required carriage return.  But there is apparently a default line feed being sent after the carriage return that is causing a problem.  I'm creating and opening the com port as follows:

    $port= new-object system.io.ports.serialport com7,9600,none,8,one

    $port.open()

    The writeline method has worked with other DAQs that I've used, but this one has more specific requirements.  Is there a way to output my strings without the unwanted line feed?  Is there an alternative to the writeline method that will work here?

    The SerialPort class supports ALL standard serial port devices and is configured the same as any industry standard serial port.

    $port= new-object system.io.ports.serialport com7,9600,none,8,one
    
    $Port.NewLine="`r"
    $port.open()
    
    ...
    $port.writeline("gpio set")
    #Now all commands can be sent withut the return being added.  If you want to snd a set o commands on mmost devices do th following:
    $port.writeline("gpio set 6`rgpio set 7`rgpio set 8")
    
    # not all devices support combining commands in that way.
    some use "gpio set 6,7,8"
    # I believe most National Instruments boards support both syntaxes.
    


    \_(ツ)_/

    Monday, May 16, 2016 11:41 PM
  • Thanks for the assist, gentlemen.  It's working perfectly now.  My next hurdle will be figuring out how to parse all of the junk this device echoes back.  Thanks.
    Tuesday, May 17, 2016 1:26 PM