Hi Julian, i am not sure about this. according to documentation this has to be enabled explicitly. https://support.industry.siemens.com/cs/document/87149213/how-do-you-define-the-true-constant-in-the-lad-fdb-editor-in-step-7-(tia-portal)-?dti=0&lc=en-AT.
Gunther On 29.03.19 09:17, Julian Feinauer wrote: > Hi Gunter, > > I am currently looking through your code and wanted to prepare a commit, so > just a question about the s7 implementation. > Is the M1.2 a generally available bit or is this something more specific to > your use cases? > I know that the M are the Markers and generally all Boolean, but can there be > a situation where this bit does not exist? > > Julian > > Am 28.03.19, 15:16 schrieb "Gunther Gruber" > <[email protected]>: > > Hi Julian, > > somhow my github account got flagged. > > I append the two functions below, i think it will take some time for > github to respond on the mail i wrote. > > > public boolean ping(String host, int port, int timeout) { > Socket s = null; > try { > s = new Socket(); > s.connect(new InetSocketAddress(host, port), timeout); > return true; > } catch (Exception e) { > return false; > } finally { > if (s != null) { > try { > s.close(); > } catch (Exception e) { > } > } > } > } > > private boolean channelPingCheck(int timeout) { > String variable = "%M1.2:BOOL"; > return channelPingCheck(timeout, variable); > } > > private boolean channelPingCheck(int timeout, String variable) { > > // String variable = "%M1.2:BOOL"; > > // boolean expectedResult = true; > > try { > plcConnection = getPlcConnection(); > } catch (PlcConnectionException e) { > return false; > } > > PlcReadRequest.Builder builder = > plcConnection.readRequestBuilder(); > > builder.addItem(variable, variable); > > PlcReadRequest readRequest = builder.build(); > > PlcReadResponse result = null; > try { > result = readRequest.execute().get(timeout, > TimeUnit.MILLISECONDS); > } catch (InterruptedException e) { > Thread.currentThread().interrupt(); > } catch (ExecutionException | TimeoutException e) { > return false; > } > > if (result == null) { > return false; > } > > Object content; > content = result.getObject(variable); > if (content == null) { > return false; > } > //we could compare against the real value of the object here, > but then we need to be more specific about the variable type > return true; > > } >
