Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: DataArithm and ApCollect

DataArithm and ApCollect 3 years 2 months ago #10920

  • Pomplun
  • Pomplun's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 17
  • Karma: 0
Hi everyone,

I want to create a log file in csv format. A time stamp and 18 analog values per line should be saved for this.
If I used the normal A1 .. A6 it works too. But I can't find the right function for ApCollect with up to 24 analog values.
I'm looking for the right approach to copy the individual ApCollect data (Ap [0], .., Ap [x]) to double or char variables in a DataArithm module.
For string variables I found the variant with the gdh_TranslateRtdbPointer and thought to myself that this should also work with the analog values. But it doesn't for me.

classdef Da1 Sv;
classdef Da2 Sv;
classdef Da3 ApCollect;

char *filename = (char *) gdh_TranslateRtdbPointer((unsigned long)Da1->ActualValue);
char *filepathnameValues = (char *) gdh_TranslateRtdbPointer((unsigned long)Da2->ActualValue);

/* float *act_IN_V_fl = (float *) gdh_TranslateRtdbPointer((unsigned long)Da3->Ap[0] ); */
double *act_IN_V_fl = (double *) gdh_TranslateRtdbPointer((unsigned long)Da3->Ap[0] );

char cmd[200];
char msgValues[200];
char msg[] = "'Datum_Uhrzeit;act_IN_V;act_IN_A;act_IN_S7_V;Sig_OUT_V;Sig_OUT_Min;Sig_OUT_Max'";
char filepath[] = "/home/pwrp/log/";
char filepathname[80];

char act_IN_V[10];
char act_IN_A[10];
char act_IN_S7_V[10];
char Sig_OUT_V[10];
char Sig_OUT_Min[10];
char Sig_OUT_Max[10];

   snprintf( act_IN_V , sizeof( act_IN_V ) , "%.2f", act_IN_V_fl );

With the function snprintf the analog value is to be written into the variable 'act_IN_V'.

Thank's a lot

/Wolfgang
Screenshot_20210209_095135.png
The administrator has disabled public write access.

DataArithm and ApCollect 3 years 2 months ago #10921

  • claes
  • claes's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 3176
  • Thank you received: 502
  • Karma: 133
Hi Wolfgang,

It's only when reference a signal object in a Da input or a DataCollect that you need to convert the ActualValue pointer. The Ap array in the ApCollect contains the float values and can not be translated. They can be printed as they are.

ActualValue in the Sv objects should be translated, but if the writing and reading of the string is made in the same plc process without any chance of interruption, you could also use a LightSv that doesn't need to be translated. Here ActualValue is not a pointer but the string value itself. If you use different plc processes for read and write and there is a chance of interruption you should use the string lock both when reading and writing in DataArithms (lck_LockStr and lck_UnlockStr).
lck_LockStr;
sprintf(...);
lck_UnlockStr;

/Claes
The administrator has disabled public write access.

DataArithm and ApCollect 3 years 2 months ago #10922

  • Pomplun
  • Pomplun's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 17
  • Karma: 0
Hi Claes,

many thanks for the quick reply.
Me, "C / C ++" and pointers that's a complicated relationship. But I'm working hard to improve my understanding.

Of course you were right, I just need the direct query.
My solution now looks like this:
   snprintf( act_IN_V , sizeof( act_IN_V ) , "%.2f", Da3->Ap[0]  );
   snprintf( act_IN_A , sizeof( act_IN_A ) , "%.2f", Da3->Ap[1]  );

Many greetings
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 8.499 seconds