CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Tue Feb 18, 2020 7:35 am

All times are UTC+01:00

Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Jan 14, 2020 12:41 pm 

Joined: Thu Dec 05, 2019 5:38 pm
Posts: 15
I have a CFC block which is supposed to read a value from a I2C device regularly, but before that, the device (actually an ADS1115) has to be configured once before the the evaluation of the block starts. I thought that could be done in the method FB_Init for the block. But it can't. The code compiles without any problems, but after download I get an Exception which says AccessViolation. Why? And how do I configure the device only once?

    bInitRetains: BOOL; // TRUE: the retain variables are initialized (reset warm / reset cold)
    bInCopyCode: BOOL;  // TRUE: the instance will be copied to the copy code afterward (online change)   
   usiAddress : USINT:= 16#48;
   byWriteBufferC : ARRAY [0..2] OF BYTE :=[16#01,16#84,16#83]; //Sets continous mode
   write :DINT;

write:=I2C_master.write(usiAddress, ADR(byWriteBufferC),3); //Generates an AccessViolation

PostPosted: Tue Jan 14, 2020 2:38 pm 

Joined: Thu Jul 27, 2017 7:54 pm
Posts: 16
It is a bad idea to utilize or reference any (external) objects in FB_Init other than the FB that you are initializing as you run the risk of the object (I2C_master in this case) not "existing" in memory yet when the FB is initialized.

Did you write a driver for the ADS1115? If you do, you can set the initial config of the ADS1115 using the state machine built into the template found at ... ?version=1

Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited