WinCC C-script Raw data operation.

AdamF

Member
Join Date
Apr 2024
Location
Germany
Posts
7
Hello.
I have a db which is 1000 INT, and this db is represented in WinCC as a raw data type set of 5x 400 Bytes.
This set is read with a script to form an INT inside, which is working ok.
What i have to do is to multiply the INTs * 1000 and write them back.
I have to do inside wincc because I can't touch db structure.

With the following code:

Code:
GetTagRawWait(Kurve1, &Yb[0],    400);
GetTagRawWait(Kurve2, &Yb[400],  400);
GetTagRawWait(Kurve3, &Yb[800],  400);
GetTagRawWait(Kurve4, &Yb[1200], 400);
GetTagRawWait(Kurve5, &Yb[1600], 400);


 for (i=0; i < 1000; i++)
 {
  
    Y = (Yb[2 * i] << 8) + Yb[2 * i +1];        // -- Read 2 bytes, form INT
            Ymul =(unsigned int) Y*100;        // -- Multiply

    printf("Before: %d", Y);
    printf("After: %d", Ymul);
    printf("\n");

    if (Ymul >= 32768) Ymul = Ymul - 65536;
  
    Yb[2*i] =  (Ymul <<8);            // -- Write back INT to 2 bytes
    Yb[2 * i +1] = Ymul &0xFF;
}

I can read my values, i see correct result, but I have trouble writing it back.
It doesnt really matter if i swap bytes or not - my data written back is totally something else.

Do You have any suggestion what I'm doing wrong?
Thank You for any help and suggestions.

EDIT: IF i write them back without changing (Write3 image), my DB remains the same... Now I'm really confused.
 

Attachments

  • Data.png
    Data.png
    329 KB · Views: 6
  • Write1.png
    Write1.png
    391.8 KB · Views: 6
  • Write2.png
    Write2.png
    372.9 KB · Views: 7
  • write3.png
    write3.png
    317.3 KB · Views: 5
Last edited:
Ok I figured it out by myself.
Code:
Yb[2*i] =  (Ymul /256)&0xFF;            // -- Write back INT to 2 bytes
Yb[2 * i +1] = Ymul &0xFF;
 

Similar Topics

Hello Experts I am working on a project with WinCC Unified v16 PC system and want to create an option on the screen to export logs to the...
Replies
0
Views
93
Hello, I have a quick question. I have been using scripts to change the color of buttons. The reason, I am usually using multiple hmiruntime.tags...
Replies
1
Views
137
Hello all, In an WinCC Professional v15 application I need to filter the alarms by alarm class, not using the filter button on the toolbar of the...
Replies
3
Views
2,621
Hi everybody.We want to an application via C script.The scenario is ; there is a silo.Goods into the silo and empty when filled.There will be a...
Replies
1
Views
1,323
Hi! So I have a problem with the VB script part of the TIA portal. I'm no good at scripting but I have a script that is working in WinCC Flexible...
Replies
8
Views
6,073
Back
Top Bottom