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?
METHOD FB_Init: BOOL
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:=I2C_master.write(usiAddress, ADR(byWriteBufferC),3); //Generates an AccessViolation