Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    aiuto su implementazione javascript

    ciao a tutti.
    Premetto, non sono un programmatore html, ma mi servirebbe realizzare un minimo di codice per alcuni dispositivi da me utilizzati.
    Vi linko la pagina di riferimento, con un esempio funzionante: http://infosys.beckhoff.com/content/....html?id=21018
    Invece la documentazione del javascript è la seguente: http://infosys.beckhoff.com/content/....html?id=20537

    il problema è il seguente: il codice funzionante esegue:
    1. istanziamento variabili e parametri di connessione (ok)
    2. sulla onload, esegue un comando di readwrite, gestita con un pacchetto in formato base64, e legge i dati di risposta.
    3. sulla base della risposta, parte poi il codice ciclico, per la lettura delle variabili.

    Vi giro ora il mio "esempio" (con alcuni commenti in inglese per il supporto del fornitore):
    ---------------------------------
    <!DOCTYPE html>
    <html>
    <head>
    <title>TcAdsWebService.js Sample01</title>
    <script type="text/javascript" src="TcAdsWebService.js"></script>
    <script type="text/javascript">
    (function () {
    var NETID = "172.16.171.171.1.1";
    var PORT = "801";
    var SERVICE_URL = "http://172.16.171.171/TcAdsWebService/TcAdsWebService.dll";
    var client = new TcAdsWebService.Client(SERVICE_URL, null, null);
    var general_timeout = 500;
    var readLoopID = null;
    var readLoopDelay = 500;
    var readSymbolValuesData = null;

    (default code till here)

    window.onload = (function () {
    readLoopID = window.setInterval(ReadLoop, readLoopDelay);
    });
    (I removed the handle management, because it doesn’t matter. I left only cyclic management)

    var ReadLoop = (function () {
    client.read(
    NETID,
    PORT,
    0x4020,
    0,
    2,
    ReadCallback,
    null,
    general_timeout,
    ReadTimeoutCallback,
    true);
    });

    (over here the read request at address %MW0)

    var ReadCallback = (function (e, s) {
    if (e && e.isBusy) {
    var message = "attendere...";
    td_prova1.innerHTML = message;
    return;
    }
    if (e && !e.hasError) {
    var reader = e.reader;
    // var err = reader.readDWORD();

    if (err != 0) {
    div_log.innerHTML = "Symbol error!";
    return;
    }

    var prova1 = reader.readWORD();

    td_prova1.innerHTML = prova1;

    } else {

    if (e.error.getTypeString() == "TcAdsWebService.ResquestError") {
    // HANDLE TcAdsWebService.ResquestError HERE;
    div_log.innerHTML = "Error: StatusText = " + e.error.statusText + " Status: " + e.error.status;
    }
    else if (e.error.getTypeString() == "TcAdsWebService.Error") {
    // HANDLE TcAdsWebService.Error HERE;
    div_log.innerHTML = "Error: ErrorMessage = " + e.error.errorMessage + " ErrorCode: " + e.error.errorCode;
    }
    }
    });
    var ReadTimeoutCallback = (function () {
    // HANDLE TIMEOUT HERE;
    div_log.innerHTML = "Read timeout!";
    });

    (this is my version of client read response function. I left busy and error management because, if removed, wireshark changes packet format from xml to normal http. Why?
    Looking at wireshark packets, I see request, and response in Base64 format, but I don’t know how to read it!. Have you suggestions or can help me?)
    The code is taken by sample01: http://infosys.beckhoff.com/content/1033/tcsample_tcadswebservicejs/html/sample01.html?id=16321
    The browser is locked in “busy” state, but looking with Wireshark I can see a cyclic request.

    })();
    </script>
    </head>
    <body>
    <h1>TcAdsWebService.js Sample01</h1>
    <h2>Cyclic reading of multiple variables with sumcommando!</h2>
    <table>
    <tr>
    <td>prova:</td>
    <td id="td_prova1"></td>
    </tr>

    </table>
    </body>
    </html>

    ---------------------------------------
    Ciò che mi chiedo, e di cui vi chiedo lumi è:
    1. ho notato che se disabilito le parti di check riguardo al busy e all'error, il pacchetto sembra che venga gestito male, cioè: se sono presenti wireshark mi vede il codice come html gestito tramite xml, mentre se li rimuovo &nbsp;vede il codice come html non formattato. Qualcuno mi sa dire come mai?
    2. come vedete, nella parte di client.read, faccio una richiesta di 2 byte, e mi aspetto che sulla callback di risposta possa leggerle, il fatto è che non leggo nulla!! Anche qua, vedendo con wireshark, ho notato che il sistema riceve il pacchetto, formattato in base64, ma non capisco.. probabilmente sbaglio qualcosa nel codice html. Se è così, vi chiedo lumi e vi ringrazio.

    Daniele

  2. #2
    nota: nel codice ci sono alcuni commenti, che in origine erano rossi e senza il simbolo di commento //, vi chiedo scusa. Ho provato a modificare il messaggio, ma il sito mi dà errore.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.