-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsc-udp-dll-ctrl.ps1
167 lines (132 loc) · 4.68 KB
/
sc-udp-dll-ctrl.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<#
.SYNOPSIS
Load/unload all SierraChart Custom Study DLLs using UDP commands.
.DESCRIPTION
Load/unload all SierraChart Custom Study DLLs using UDP commands.
See https://www.sierrachart.com/index.php?page=doc/UDPAPI.html
.NOTES
Authors: cxxxxx, Frozen Tundra, malykubo
#>
Param(
# Hostname, Default = localhost
[parameter(Mandatory=$false)]
[string]$Targethost = "127.0.0.1",
# Load or unload?
[parameter(Mandatory=$true)]
[switch]$UnloadAllDLLs = $true,
# Disable verbose help messages
[parameter(Mandatory=$false)]
[switch]$DisableHelp = $false
)
# ################################################################################
# SETTINGS
# ################################################################################
# Halt on errors
$ErrorActionPreference = "Stop"
# Destination IP address / hostname
$IpAddress = $Targethost
# Destination SierraChart port, as defined in
# Global Settings -> Sierra Chart Server Settings -> "UDP Port"
$SCPortUDP = 4242
# --------------------------------------------------------------------------------
# Issue message and die
# --------------------------------------------------------------------------------
function Die
{
Param(
# Output message
[parameter(Mandatory=$true)]
[string]$Msg,
[parameter(Mandatory=$false)]
[int]$RetCode
)
Write-Output "`n`n`n"
Write-Output "***************************************************************************"
Write-Output "*****"
Write-Output "***** DIE: $Msg"
Write-Output "*****"
Write-Output "***************************************************************************"
Write-Output "`n`n`n"
if ($RetCode -ne 0)
{
# Use user-defined return code
exit $RetCode
}
exit 1
}
# --------------------------------------------------------------------------------
# Send UDP string
# --------------------------------------------------------------------------------
function Send-UdpDatagram
{
Param (
# Destination address
[string] $EndPoint,
# Destination port
[int] $Port,
# THE message
[string] $Message
)
$IP = [System.Net.Dns]::GetHostAddresses($EndPoint)
$Address = [System.Net.IPAddress]::Parse($IP)
$EndPoints = New-Object System.Net.IPEndPoint($Address, $Port)
$Socket = New-Object System.Net.Sockets.UDPClient
$EncodedText = [Text.Encoding]::ASCII.GetBytes($Message)
$SendMessage = $Socket.Send($EncodedText, $EncodedText.Length, $EndPoints)
$Socket.Close()
}
# ################################################################################
#
# START
#
# ################################################################################
# Write-Output "PS Version is: $($PSVersionTable.PSVersion.Major)"
if ($PSVersionTable.PSVersion.Major -lt 5)
{
Die "PS Version not compatible -- At least version 5 is required!" -immediateNoCollect $true
}
$MyName = $MyInvocation.MyCommand.Name
# Some explanatory text. Maybe removed later ...
if (!$DisableHelp)
{
if ($UnloadAllDLLs)
{
Write-Host "### ********************************************************************************"
Write-Host "### $($MyName):"
Write-Host "###"
Write-Host "### Using SierraChart UDP port: $($SCPortUDP)"
Write-Host "###"
Write-Host "### If not already done, you have to define/activate the port first -- use:"
Write-Host "###"
Write-Host "### <Global Settings | Sierra Chart Server Settings | UDP Port>"
Write-Host "###"
Write-Host "### ********************************************************************************"
}
}
if ($UnloadAllDLLs)
{
Write-Host "### Unloading DLLs ..."
Send-UdpDatagram -EndPoint $IpAddress -Port $SCPortUDP -Message "RELEASE_ALL_DLLS"
Write-Host "(ok)"
}
else
{
if (!$DisableHelp)
{
Write-Host "### Allow loading of DLLs ..."
Write-Host "### ********************************************************************************"
Write-Host "### To reload chart(s) in SierraChart:"
Write-Host "###"
Write-Host "### Choose <Chart | Recalculate> [CTRL-Insert]"
Write-Host "###"
Write-Host "### If defaults (sc.SetDefaults) or params/subgraphs have been changed:"
Write-Host "###"
Write-Host "### Remove and add the study!"
Write-Host "### ********************************************************************************"
}
Send-UdpDatagram -EndPoint $IpAddress -Port $SCPortUDP -Message "ALLOW_LOAD_ALL_DLLS"
Write-Host "(ok)"
}
Write-Host "(done - ok)"
exit 0
# ################################################################################