Using a concat instruction in tia to help

stu

Member
Join Date
Aug 2005
Location
England
Posts
783
Hi all I am trying to set up a lhttp instruction to connect to an api https (with our IT) this will send data back to the plc?
I have an api https address for the url address for the lhttp_get but , I need to change the works number in the url address to call the right product? Say its http://api######300000##### I will need to change the 300000, I have heard that I could us a concat can this be done ? And how easy is it
 
Pretty simple, I think it can be done in a handful of instructions:

  • Start with a the basic tags you know:
    • URLFMT: String, URL with placeholders for the works number e.g. the blue Ws at ordinal position 29 are where the works number should go
    • WORKSNUM: DINT, works number to be inserted as a string e.g. 300000
    • URL: String, output URL with works number replacing WS
  • Allocate some other intermediate tags:
    • MWORKSNUM: DINT, the works number plus one million, so you get leading zeros
      • Protecting against works numbers that are either negative or greater than 999999 is left as an exercise
  • Write the URLFMT string to URL"
    • URL := URLFMT;
  • Add one million to the number to a six-digit string
    • MWORKSNUM := WORKSNUM + 1000000;
  • Write those seven digits, with the leading 1 play any subsequent zeros, into the URL, starting one position before the works number to account for the leading 1 that will be removed
    • VAL_STRING(in:=MWORKSNUM,size=7,prec:=0,format:=0,P:=29,out=URL);
  • Replace the first 29 character of URL to overwrite the leading 1 (millions digit)
    • REPLACE(in1:=URL,in2:=URLFMT,L:=29,p:=1,out:=URL);
Summat like that; there are other approaches (see RIGHT and CONCAT functions), especially if you don't need the leading zeros if the works number is below 100,000.
 
Thanks guys , I think I will have to try tomorrow , if I had the number entered on the hmi ,would I move that value into #udiworksorder?
 
Is the format always like this:
"http://api######" + Work Order Number + "#####" ?

The "http://api######" and the "#####" are fixed and do not change, only the work order number is input by the HMI ?

Must the work order number always have 6 digits, or does it grow or shrink depending on the number ?
I.e. "123" or "000123" ?

I think it is as simple as defining static strings for the beginning and and of the address, converting the work order number into a string (fixed or variable length) and then concating all 3 strings into the address.
 
thanks gents that works with the 500000 -the number is always going to be 7 numbers long
can #udiWorksOrder := 5000000; i understand this could be an input ? but how can i code that , this is new but interesting learning

http.PNG
 
i just added a s move from hmi to a hmi work order tag . the network and put it i where #udiworksorder is so #hmi works order input(string) := #udiworksorder (udint)
if i change the udint to a string it doesnt like it
 
OK, then it is really simple. No need to "find" or "replace" the position in the string.

Something like this should be enough:
Code:
VAL_STRG(IN:=#udiWorksOrder, // input from HMI
                  SIZE:=7,
                  PREC:=0,
                  FORMAT:=0,
                  P:=1,
                  OUT-> #sOrderNumber);

#sWorksOrder := CONCAT(IN1:='http://api######', IN2:=#sOrderNumber, IN3:='######');
 

Similar Topics

Good Morning , I'm working on trying to get timestamping done on some doses. I am very close, thanks to many of you with your advice. I...
Replies
7
Views
2,675
I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
64
Adding ethernet equipment to an existing panel that has none. We have some solid ethernet cables coming from other remote cabinets that I plan to...
Replies
3
Views
124
I'm trying to control a device via MODBUS RTU and the ModbusRtuMasterV2_PcCOM in Twincat 3. I've configured a device with the right com port and...
Replies
7
Views
222
Hi, I'm trying to use the IO Device Library (Product Versions) which is configured to work with the 1756-EN4TR & 1756-EN2TR but my system uses...
Replies
0
Views
60
Back
Top Bottom