11using System . Reflection ;
22using System . Windows . Forms ;
33using UnderAutomation . UniversalRobots ;
4+ using System . Linq ;
5+ using System ;
46
57public partial class ProgramControl : UserControl , IUserControl
68{
@@ -62,6 +64,43 @@ public void PeriodicUpdate()
6264 }
6365
6466 public void OnClose ( ) { }
65- public void OnOpen ( ) { }
67+ public void OnOpen ( )
68+ {
69+ cbPrograms . Items . Clear ( ) ;
70+
71+ if ( ! _ur . SftpEnabled || string . IsNullOrEmpty ( _ur . IP ) ) return ;
72+
73+ var loadedPrograms = _ur . GetLoadedProgram ( ) ;
74+ var splitedPath = loadedPrograms . Value . Split ( new string [ ] { "programs/" } , System . StringSplitOptions . RemoveEmptyEntries ) ;
75+ var pathToPrograms = $ "{ splitedPath [ 0 ] } programs";
76+
77+ var items = _ur . SFTP . ListDirectory ( pathToPrograms ) ;
78+
79+ var programs = items . Where ( x => x . Name . EndsWith ( ".urp" , StringComparison . InvariantCultureIgnoreCase ) ) . Select ( x => x . Name ) . ToArray ( ) ;
80+
81+ cbPrograms . Items . AddRange ( programs ) ;
82+ if ( splitedPath . Length > 0 ) cbPrograms . Text = splitedPath [ 1 ] ;
83+ }
6684 #endregion
85+
86+ private void btnRun_Click ( object sender , System . EventArgs e )
87+ {
88+ var result = _ur . LoadProgram ( cbPrograms . Text ) ;
89+
90+ if ( ! result . Succeed ) throw new Exception ( result . Message ) ;
91+
92+ result = _ur . Play ( ) ;
93+
94+ if ( ! result . Succeed ) throw new Exception ( result . Message ) ;
95+ }
96+
97+ private void btnPause_Click ( object sender , EventArgs e )
98+ {
99+ _ur . Pause ( ) ;
100+ }
101+
102+ private void btnStop_Click ( object sender , EventArgs e )
103+ {
104+ _ur . Stop ( ) ;
105+ }
67106}
0 commit comments