-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSSH Client (FM).usp
77 lines (63 loc) · 1.43 KB
/
SSH Client (FM).usp
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
#DEFAULT_VOLATILE
#ENABLE_STACK_CHECKING
#ENABLE_TRACE
#USER_SIMPLSHARP_LIBRARY "SSHClient"
// module inputs
digital_input init, connect, disconnect, debug, _skip_;
string_input tx$[250], _skip_, hostname[50], username[20], password[20], debug_name[10];
// module outputs
digital_output initialized_fb, connected_fb;
string_output _skip_,_skip_,_skip_, rx$, _skip_;
// global variables
integer connected;
SSHClientDevice client;
function RegisterDelegates()
{
RegisterDelegate(client, InitializedData, InitializedDataHandler);
RegisterDelegate(client, ConnectionState, ConnectionStateHandler);
RegisterDelegate(client, ReceivedData, ReceivedDataHandler);
}
callback function InitializedDataHandler (integer state)
{
initialized_fb = state;
}
callback function ConnectionStateHandler (integer state)
{
connected = state;
connected_fb = state;
}
callback function ReceivedDataHandler(string data)
{
rx$ = data;
}
push init
{
client.Initialize(hostname, username, password, debug_name);
}
push connect
{
client.Connect();
}
push disconnect
{
client.Disconnect();
}
push debug
{
client.debug_enable = 1;
}
release debug
{
client.debug_enable = 0;
}
threadsafe Change tx$
{
// only send commands when connected
if (connected)
client.SendCommand(tx$);
}
function Main()
{
WaitForInitializationComplete();
RegisterDelegates();
}