SHARE
TWEET

Untitled

a guest Sep 10th, 2019 156 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FUNCTION_BLOCK PUBLIC WriteRegisterMir
  2. VAR_INPUT
  3.     sRegister : STRING(3);
  4.     rValue : REAL;
  5. END_VAR
  6. VAR_OUTPUT
  7.     diError : BOOL;
  8.     diDone : BOOL;
  9. END_VAR
  10. VAR
  11.     wState : WORD := 0;
  12.  
  13.     (* Http POST *)
  14.     oHttpPost: FbHTTP_Post;
  15.     sURL : STRING(255) := '192.168.12.20/api/v2.0.0/registers/';
  16.     sURI : STRING(255);
  17.     MyAuthentification : eAuthentication := 1;
  18.     xHttpSend : BOOL;
  19.     sStatus : WagoSysErrorBase.FbResult;
  20.     aRxBuffer : ARRAY [0..19999] OF BYTE;
  21.     uiResponse : UDINT;
  22.     sBasePayload : STRING :='{"value": ';
  23.     sPayload : STRING;
  24. END_VAR
  25.  
  26.  
  27. oHttpPost(
  28.     sURI:= sURI,
  29.     sUser:= 'admin' ,
  30.     sPassword:= '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918',
  31.     sPostfields:= sPayload,
  32.     sHeader:= 'Content-Type: application/json',
  33.     eAuthentication:= MyAuthentification,
  34.     pRxBuffer:= ADR(aRxBuffer),
  35.     udiRxBufferSize:= 20000,
  36.     tTimeout:= T#5S,
  37.     xTrigger:= xHttpSend,
  38.     xBusy=> ,
  39.     xError=> diError,
  40.     oStatus=> sStatus,
  41.     udiRxNBytes=> uiResponse);
  42.  
  43. CASE wState OF
  44. 0 : (* IDLE - wait for something to do *)
  45.     diDone := FALSE;
  46.     sURI := CONCAT(sURL, sRegister);
  47.     //sPayload := CONCAT(sBasePayload, REAL_TO_STRING(rValue)); // Use if double is needed
  48.     sPayload := CONCAT(sBasePayload, INT_TO_STRING(REAL_TO_INT(rValue)));
  49.     sPayload := CONCAT(sPayload, ', "label": "string"}');
  50.     xHttpSend := TRUE;
  51.     wState := 10;
  52.    
  53. 10 : (* Wait for HTTP-GET response data *) 
  54.     IF NOT xHttpSend THEN
  55.         IF  NOT diError THEN
  56.             wState := 20;
  57.         ELSE
  58.             wState := 999;     
  59.         END_IF
  60.     END_IF
  61.    
  62. 20 :
  63.     diDone := TRUE;
  64.     wState := 0;
  65.  
  66.    
  67. 999 : (* *)
  68.     diDone := TRUE;
  69.     wState := 0;
  70.  
  71. END_CASE
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top