Skip to content

Commit

Permalink
Merge pull request #86 from royalapplications/create-pull-request/patch
Browse files Browse the repository at this point in the history
Merge Serial Devices PR
  • Loading branch information
lemonmojo committed Oct 10, 2023
2 parents ac3204b + f7242a4 commit 16c47e7
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 40 deletions.
@@ -0,0 +1,162 @@
<DynamicFolderExport>
<Name>Dynamic Folder Export</Name>
<Objects>
<DynamicFolderExportObject>
<Type>DynamicFolder</Type>
<Name>Attached Serial Devices</Name>
<Description>Version 2.2. Compatible with Windows or Mac. 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.</Description>
<Notes><![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title>
<style type="text/css">
.csB7EA527D{text-align:left;text-indent:0pt;margin:12pt 0pt 12pt 0pt;line-height:1.2}
.cs167BCCEB{color:#000000;background-color:transparent;font-family:'Microsoft Sans Serif';font-size:24pt;font-weight:normal;font-style:normal;}
.cs828CB189{text-align:left;text-indent:0pt;margin:12pt 0pt 12pt 0pt}
.cs69B997E3{color:#000000;background-color:transparent;font-family:'Microsoft Sans Serif';font-size:10.5pt;font-weight:normal;font-style:normal;}
.cs6250E9AF{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt;line-height:13.57pt}
.cs519FF10D{color:#000000;background-color:transparent;font-family:'Microsoft Sans Serif';font-size:18pt;font-weight:normal;font-style:normal;}
.cs39641E51{color:#000000;background-color:transparent;font-family:'Microsoft Sans Serif';font-size:13.5pt;font-weight:normal;font-style:normal;}
.csB9B2B44{text-align:left;margin:0pt 0pt 0pt 0pt;list-style-type:disc;color:#000000;background-color:transparent;font-family:Arial;font-size:10.5pt;font-weight:normal;font-style:normal}
.cs290E6A33{color:#000000;background-color:transparent;font-family:'Microsoft Sans Serif';font-size:10.5pt;font-weight:bold;font-style:normal;}
.cs9BE33341{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt}
.csBBC365F6{color:#000000;background-color:transparent;font-family:'Times New Roman';font-size:12pt;font-weight:normal;font-style:normal;}
</style>
</head>
<body>
<h1 class="csB7EA527D">
<a name="_dx_frag_StartFragment"></a><a name="_dx_frag_EndFragment"></a><a name="ATTACHED-SERIAL-DEVICES-DYNAMIC-FOLDER"></a><span class="cs167BCCEB">Attached Serial Devices Dynamic Folder</span></h1>
<p class="cs828CB189"><span class="cs69B997E3">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.</span></p><p class="cs828CB189"><span class="cs69B997E3">The resulting folder structure will look something like the following:</span></p><p class="cs6250E9AF"><span class="cs69B997E3">Attached Serial Devices</span></p><p class="cs6250E9AF"><span class="cs69B997E3">|-- USB Serial Device (COM12)</span></p><p class="cs6250E9AF"><span class="cs69B997E3">| &nbsp;&nbsp;|-- COM12 9600 8N1</span></p><p class="cs6250E9AF"><span class="cs69B997E3">| &nbsp;&nbsp;|-- COM12 9600 7E1</span></p><p class="cs6250E9AF"><span class="cs69B997E3">| &nbsp;&nbsp;|-- COM12 19200 8N1</span></p><p class="cs6250E9AF"><span class="cs69B997E3">| &nbsp;&nbsp;`-- COM12 19200 7E1</span></p><p class="cs6250E9AF"><span class="cs69B997E3">`-- USB-SERIAL CH340 (COM34)</span></p><p class="cs6250E9AF"><span class="cs69B997E3">&nbsp; &nbsp;&nbsp;|-- COM34 9600 8N1</span></p><p class="cs6250E9AF"><span class="cs69B997E3">&nbsp; &nbsp;&nbsp;|-- COM34 9600 7E1</span></p><p class="cs6250E9AF"><span class="cs69B997E3">&nbsp; &nbsp;&nbsp;|-- COM34 19200 8N1</span></p><p class="cs6250E9AF"><span class="cs69B997E3">&nbsp; &nbsp;&nbsp;`-- COM34 19200 7E1</span></p><h2 class="cs828CB189">
<a name="REQUIREMENTS"></a><span class="cs519FF10D">Requirements</span></h2>
<p class="cs828CB189"><span class="cs69B997E3">Installation of PowerShell for Mac OS.</span></p><p class="cs828CB189"><span class="cs69B997E3">Setting the exection policy of PowerShell to Remote Signed for Windows.</span></p><h2 class="cs828CB189">
<a name="CUSTOM-PROPERTIES"></a><span class="cs519FF10D">Custom Properties</span></h2>
<h3 class="cs828CB189">
<a name="PORT-SPEEDS"></a><span class="cs39641E51">Port Speeds</span></h3>
<p class="cs828CB189"><span class="cs69B997E3">This field must contain comma-separated list of serial port speeds in numeric format.</span></p><ul style="margin-top:0;margin-bottom:0;">
<li class="csB9B2B44"><span class="cs290E6A33">Example 1</span><span class="cs69B997E3">:&nbsp;9600</span></li><li class="csB9B2B44"><span class="cs290E6A33">Example 2</span><span class="cs69B997E3">:&nbsp;9600,19200,115200</span></li></ul>
<h3 class="cs828CB189">
<a name="FRAME-SETTINGS"></a><span class="cs39641E51">Frame Settings</span></h3>
<p class="cs828CB189"><span class="cs69B997E3">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.</span></p><ul style="margin-top:0;margin-bottom:0;">
<li class="csB9B2B44"><span class="cs290E6A33">Example 1</span><span class="cs69B997E3">:&nbsp;&quot;8N1&quot;</span></li><li class="csB9B2B44"><span class="cs290E6A33">Example 2</span><span class="cs69B997E3">:&nbsp;&quot;8N1&quot;,&quot;7E1&quot;</span></li></ul>
<p class="cs9BE33341"><span class="csBBC365F6">&nbsp;</span></p></body>
</html>
]]></Notes>
<CustomProperties>
<CustomProperty>
<Name>Port Speeds</Name>
<Type>Text</Type>
<Value>9600,19200,115200</Value>
</CustomProperty>
<CustomProperty>
<Name>Frame Settings</Name>
<Type>Text</Type>
<Value>"8N1","7E1"</Value>
</CustomProperty>
</CustomProperties>
<ScriptInterpreter>powershell</ScriptInterpreter>
<Script><![CDATA[# Royal TS Attached Serial Devices Dynamic Folder script
# version 2.2

$ErrorActionPreference = "STOP"

# Determine OS type based on version and platform
switch ($PSVersionTable.PSVersion.Major) {
{ $_ -le 5 } {
$IsOSWindows = ([System.Environment]::OSVersion.Platform -eq "Win32NT")
$IsOSMacOS = -not $IsOSWindows
}
default {
$IsOSWindows = $IsWindows # Utilize predefined variables for PowerShell 6.0+
$IsOSMacOS = $IsMacOS
}
}

# Set variables for com port speeds and frame settings
$comPortSpeeds = @($CustomProperty.PortSpeeds$)
$comPortFrameSettings = @($CustomProperty.FrameSettings$)

# Pulls serial device list per OS type.
if ($IsOSWindows){
# Collect a list of avilable serial ports from WMI. See here for discussion: https://stackoverflow.com/questions/19840811/list-of-serialports-queried-using-wmi-differs-from-devicemanager
$comPorts = Get-WmiObject -query 'SELECT * FROM Win32_PnPEntity WHERE ClassGuid="{4d36e978-e325-11ce-bfc1-08002be10318}"'
}
elseif ($IsOSMacOS){
# Collect a list of available usb serial devices for Mac OS
$comPorts = ls /dev/tty.usbserial*
}
else {
Write-Host "[ERROR] OS not detected. Halting" -ForegroundColor Red
throw
}

$folders = @()
foreach ($comPort in $comPorts) {
$connections = @()
$comPortCaption = $comPort.Caption;
if ($comPortCaption -match '.*\((COM\d+)\)') {
$comPortDevice = $Matches[1]
}
elseif ($comPort -match '(usbserial.\d+)') {
$comPortCaption = $comPort
$comPortDevice = $Matches[1]
}
else {
continue
}
foreach ($comPortSpeed in $comPortSpeeds) {
foreach ($comPortFrameSetting in $comPortFrameSettings) {
if ($comPortFrameSetting -match '^(\d)([NOEMSnoems])(\d)$') {
[int]$comPortDataBits = $Matches[1]
$comPortParityAlpha = $Matches[2].ToUpper()
[int]$comPortStopBits = $Matches[3]
}
else {
continue
}
if ($comPortParityAlpha -eq "N") {
[int]$comPortParity = "0"
}
elseif ($comPortParityAlpha -eq "O") {
[int]$comPortParity = "1"
}
elseif ($comPortParityAlpha -eq "E") {
[int]$comPortParity = "2"
}
elseif ($comPortParityAlpha -eq "M") {
[int]$comPortParity = "3"
}
elseif ($comPortParityAlpha -eq "S") {
[int]$comPortParity = "4"
}
else {
continue
}
$connectionProperties = New-Object PSCustomObject -Property @{
"BaudRate" = $comPortSpeed;
"DataBits" = $comPortDataBits;
"Parity" = $comPortParity;
"StopBits" = $comPortStopBits;
}
$connection = New-Object PSCustomObject -Property @{
"Type" = "TerminalConnection";
"TerminalConnectionType" = "SerialPort";
"Name" = "$comPortDevice $comPortSpeed $comPortFrameSetting";
"SerialPortName" = $comPortDevice;
"Properties" = $connectionProperties;
}
$connections += $connection
}
}
$folder = New-Object PSCustomObject -Property @{
"Type" = "Folder";
"Name" = $comPortCaption;
"Objects" = $connections;
}
$folders += $folder
}
@{ Objects = $folders } | ConvertTo-Json -Depth 5]]></Script>
<DynamicCredentialScriptInterpreter>json</DynamicCredentialScriptInterpreter>
</DynamicFolderExportObject>
</Objects>
</DynamicFolderExport>

This file was deleted.

0 comments on commit 16c47e7

Please sign in to comment.