cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Data Logging with CtrlX

Data Logging with CtrlX

hundch
Member

Hi, 

for a Test Project i need to log some Data from a Sensor. 

The data come from a IO-Link device in cycle time of 5ms . So i guess every 3 PLC cycle i want to record 16 Bytes (1 measurement)

I need around 10000 measurements . 

I thought over the IDE App in Python or directly in Codesys.

I am little bit concerned about the storage and the record speed/ rate. 

How is the most efficent way to do this ? Is there anyone who already have done this. 

Any approach or example is helpful

Thanks in advanced. 

Best regards

Christoph Hund

 

8 REPLIES 8

CodeShepherd
Community Moderator
Community Moderator

As python cannot really be connected to a bus cycle in your case I would suggest to use the PLC. Create a task with the cycle time needed by you (e.g. 5ms). Setup an array with 10k variables space and go.

Of course you could also use python or data bases / cloud connector apps for this e.g. via the Bosch - DeviceBridge, Cedalo - Eclipse Mosquitto MQTT Broker or ctrlX CORE - Node-RED App.

Yes we did some projects where we implemented such stuff in the PLC, as described above.

  • Data size is 16Bytes * 100 000 Measures = 160 kByte no problem for the PLC.
  • When your measurement is finished you can store it to a disc. e.g. A csv file for analysing it e.g. in Excel.

Cool , Thanks for the Feedback. 
Works pretty good so far. 
I have now made an Array for test purpose with a size of 10000. 

Which way approach is the best from here ?

  • Write the array in a file i guess.

Which method you have used ?
Where is the file located on the system / in the data layer ?

Thanks for the help 🙂 

HmiGuide
Community Moderator
Community Moderator

Use library CXA_FileAsync with FB IL_FileWriteAsync. Have a look into the libaries FB, where you find an example, how to use it.

HmiGuide_0-1663588085089.png

The plc app only has access to the active configuration folder of the plc app. So just provide a relative name (without a "/" at start) like "myFile.cvs" or "data/myFile.csv"

Use PLC Engineering to browse this folder.

Double click on (1) Select tab "Files" (2) Click on "Refresh" (3)

HmiGuide_1-1663588608332.png

 

You can additionally access the app data (activeConfiguration). See the modified example from the CXA_FileAsyn library:

Declaration:

PROGRAM WriteFile
VAR
  fbFile: CXA_FileAsync.IL_FileAsync;
  fbFileWrite: CXA_FileAsync.IL_FileWriteAsync;
  filename: STRING := '/var/snap/rexroth-solutions/common/solutions/activeConfiguration/testfile.txt';
  itestcase: UINT := 0;
  writebuf: STRING(500);
  writebuflen: UDINT := 500;
  writelen: UDINT := 0;
END_VAR

Implementation:

CASE itestcase OF
1: // open the file
  fbFile(Enable:=TRUE, FileName:=ADR(filename), Mode:=IL_FILE_ACCESS_MODE.AM_WRITE);
  IF fbFile.InOperation THEN
    itestcase := itestcase + 1;
  END_IF

2: // write the file
  writebuf := 'BoschRexroth$R$NCtrlX Automation$R$NCXA_FileAsync$R$N';
  writebuflen := IL_LEN(ADR(writebuf));

  fbFileWrite(Execute:=TRUE, FileHandle:=fbFile.FileHandle, BufferAddr:=ADR(writebuf), BufferSize:=writebuflen, BytesWritten=>writelen);
  IF fbFileWrite.Done THEN
    fbFileWrite(Execute:=FALSE);
    itestcase := itestcase + 1;
  END_IF

3: // close file
  fbFile(Enable:=FALSE);
  If NOT fbFile.Shutdown AND NOT fbFile.InOperation THEN
    itestcase := 0;
  END_IF
END_CASE

IF fbFileWrite.Error OR fbFile.Error THEN
  ; // post some error
END_IF

 

Thanks for your help works everthing like expected with the file writeing. 

But it is strange that i only get each 200ms new Data from the BUS even the Cycle Time is 5ms and i have set the Buscycle Option to the Main Task. 

hundch_0-1663687184088.png

Is there anything which i do not cover at the moment ? 

Thanks for all your help. 

 

cc2go
Occasional Contributor

Hi, please check cycle time of the Main Task or your PLC Task, by Default it's set to 200ms

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist