How to send a serial string ending in a carraige return?

Welcome Forums General PowerShell Q&A How to send a serial string ending in a carraige return?

Viewing 2 reply threads
  • Author
    Posts
    • #245409
      Participant
      Topics: 2
      Replies: 4
      Points: 32
      Rank: Member

      Hello,

      I have a motorized device that is controlled by serial commands.
      Typical text string commands include:

      “:G232[0xd]” //Set Motor direction as CCW
      “:I2130000[0xd]” //Set Motor Slew Speed
      “:J2[0xd]” //Start Motor movement

      I am successfully able to serially control the device from an application I have installed on my PC.  But I want to be able to control the device via Powershell.

      I’ve opened the port this way:
      $port= new-Object System.IO.Ports.SerialPort COM4,9600,1,8,1;
      $port.open();

      All seems to be fine at this point
      The commands I’ve tried to write this way:

      $port.WriteLine(“:K2[char]13”);

      or this way:
      $port.WriteLine(“:K2’n”);

      The device is not responding to any of these.
      I’m wondering if my syntax for the carriage return is valid?

      Any suggestions would be appreciated

    • #245412
      Participant
      Topics: 7
      Replies: 124
      Points: 600
      Helping Hand
      Rank: Major Contributor

      How about trying a CR and LF

      Sorry, I am failing to enter the code, the formatting keeps getting lost when I hit submit … bascially,

      backTick+r backtick+n

      the backtick is under the tilde

       

      • This reply was modified 2 months ago by TonyD05.
    • #245811
      Participant
      Topics: 2
      Replies: 4
      Points: 32
      Rank: Member

      AH!
      Maybe that’s what I had wrong.
      I understood the they were single quote r and single quote n
      I’ll try that!
      Thanks :-]

Viewing 2 reply threads
  • You must be logged in to reply to this topic.