Start a new topic
Answered

RoyalJSON and serial baud rate

I do a lot of screwing around with microcontrollers which has me connecting random serial devices very regularly.  Windows being Windows, this means I'm constantly trying to figure out which COM port was just created and then trying to create another new session with the right port/speed/etc combination to talk to it.


This get tedious pretty quickly.


I'm looking to create a dynamic folder which will contain terminal sessions for local serial devices.  I've knocked together this quick PowerShell script as a starting point:

$comPorts = Get-WMIObject Win32_SerialPort
$connections = @()
ForEach ($comPort in $comPorts) {
  $connection = New-Object PSCustomObject -Property @{
    "Type"                   = "TerminalConnection";
    "TerminalConnectionType" = "SerialPort";
    "Name"                   = $comPort.Caption;
    "SerialPortName"         = $comPort.DeviceID;
    "BaudRate"               = 115200;
  }
  $connections += $connection
}
@{ Objects = $connections } | ConvertTo-Json -Depth 100

"Baud" and "BaudRate" don't appear to work.  I'd like to set the speed, parity, data bits, stop bits, etc from this script.


Digging through the RoyalJSON documentation, I find no reference to how one might set the various Advanced Properties of a SerialPort object.  Is that property exposed to this functionality?


If I might add a feature request to this post - it would be super helpful if an "export to JSON" option was available for existing connections.  Then one could setup a connection manually, export it, and use that as a guide for scripting out dynamic connections.



Best Answer

Between posting that question and having it approved I found the answer and finished the script.


Details

I've submitted this RTS Dynamic Folder to the RTS toolbox repo which will create a set of connections for all available serial ports with various (configurable) speed and framing options.  On my system the result looks like this:


Here's the documentation for this simple PowerShell script:


Attached Serial Devices Dynamic Folder

This script utilizes PowerShell to generate a list of available serial devices, along with RTS Custom Properties defining speeds and framing settings, to generate a set of Terminal connections for each combination of port/speed/framing.

The resulting folder structure will look something like the following:

Attached Serial Devices
|-- USB Serial Device (COM12)
|   |-- COM12 9600 8N1
|   |-- COM12 9600 7E1
|   |-- COM12 19200 8N1
|   `-- COM12 19200 7E1
`-- USB-SERIAL CH340 (COM34)
    |-- COM34 9600 8N1
    |-- COM34 9600 7E1
    |-- COM34 19200 8N1
    `-- COM34 19200 7E1

Requirements

This solution only works under Windows due to its use of WMI to identify available COM ports.

Custom Properties

Port Speeds

This field must contain comma-separated list of serial port speeds in numeric format.

Example 1: 9600

Example 2: 9600,19200,115200


Frame Settings

This field must contain comma-separated list of serial port framing standards (8N1, 7E1, etc) in alphanumeric format, and each entry must be in double quotes.

Example 1: "8N1"

Example 2: "8N1","7E1"


Glad you figured it out - and thanks for sharing your solution!

Answer

Between posting that question and having it approved I found the answer and finished the script.


Details

I've submitted this RTS Dynamic Folder to the RTS toolbox repo which will create a set of connections for all available serial ports with various (configurable) speed and framing options.  On my system the result looks like this:


Here's the documentation for this simple PowerShell script:


Attached Serial Devices Dynamic Folder

This script utilizes PowerShell to generate a list of available serial devices, along with RTS Custom Properties defining speeds and framing settings, to generate a set of Terminal connections for each combination of port/speed/framing.

The resulting folder structure will look something like the following:

Attached Serial Devices
|-- USB Serial Device (COM12)
|   |-- COM12 9600 8N1
|   |-- COM12 9600 7E1
|   |-- COM12 19200 8N1
|   `-- COM12 19200 7E1
`-- USB-SERIAL CH340 (COM34)
    |-- COM34 9600 8N1
    |-- COM34 9600 7E1
    |-- COM34 19200 8N1
    `-- COM34 19200 7E1

Requirements

This solution only works under Windows due to its use of WMI to identify available COM ports.

Custom Properties

Port Speeds

This field must contain comma-separated list of serial port speeds in numeric format.

Example 1: 9600

Example 2: 9600,19200,115200


Frame Settings

This field must contain comma-separated list of serial port framing standards (8N1, 7E1, etc) in alphanumeric format, and each entry must be in double quotes.

Example 1: "8N1"

Example 2: "8N1","7E1"

Login or Signup to post a comment