@@ -60,7 +60,17 @@ public async Task OnExecute()
6060
6161 logger . Debug ( "Starting API Call" ) ;
6262 logger . Debug ( $ "Connecting to Beckhoff Port: { AdsPort } - AdsNet: '{ AdsNetId } '") ;
63- adsClient . Connect ( AdsNetId , AdsPort ) ;
63+
64+ if ( string . IsNullOrEmpty ( AdsNetId ) )
65+ {
66+ adsClient . Connect ( AdsPort ) ;
67+ }
68+ else
69+ {
70+ adsClient . Connect ( AdsNetId , AdsPort ) ;
71+ }
72+
73+ logger . Debug ( $ "Beckhoff connection state: { adsClient . ConnectionState } ") ;
6474
6575 var callAddress = Address . IsValidUrl ( ) ? Address : await adsClient . ReadAsync < string > ( Address ) ;
6676 logger . Debug ( $ "Url: { callAddress } ") ;
@@ -88,32 +98,35 @@ public async Task OnExecute()
8898
8999 if ( ! string . IsNullOrEmpty ( ResponseCode ) )
90100 {
91- logger . Debug ( $ "Wrinting status code into { ResponseCode } ...") ;
101+ logger . Debug ( $ "Writing status code into { ResponseCode } ...") ;
92102 await adsClient . WriteAsync ( ResponseCode , response . StatusCode ) ;
103+ logger . Debug ( $ "Written status code into { ResponseCode } .") ;
93104 }
94105
95106 //Try parsing object or array from response content
96- logger . Debug ( $ "Wrinting json response into { Response } ...") ;
107+ logger . Debug ( $ "Writing json response into { Response } ...") ;
97108 try
98109 {
99110 var objectResponse = JObject . Parse ( response . Content ) ;
100111 await adsClient . WriteJson ( Response , objectResponse ) ;
112+ logger . Debug ( $ "Written response into { Response } .") ;
101113 }
102114 catch ( JsonReaderException exception )
103115 {
104- logger . Error ( "Unable to write response content parsing a json object" , exception ) ;
116+ logger . Error ( "Unable to write response content parsing a json object - 2nd try with json array " , exception ) ;
105117
106118 try
107119 {
108120 var arrayResponse = JArray . Parse ( response . Content ) ;
109121 await adsClient . WriteJson ( Response , arrayResponse ) ;
122+ logger . Debug ( $ "Written response into { Response } .") ;
110123 }
111124 catch ( JsonReaderException innerException )
112125 {
113126 logger . Error ( "Unable to write response content parsing a json array" , innerException ) ;
114127 }
115128 }
116-
129+ logger . Debug ( $ "Disconnecting to Beckhoff" ) ;
117130 adsClient . Disconnect ( ) ;
118131 }
119132 catch ( Exception e )
0 commit comments