Your syntax on updateCustomIn() is wrong. %IW is not a valid C macro nor a construct. Also, you need to move the declarations of OTcValx variables out of the
initCustomLayer() as they are not used in there. This is how you should have done it:
void updateCustomIn()
{
double OTcVal0 = 0;
double OTcVal1 = 0;
double OTcVal2 = 0;
double OTcVal3 = 0;
//read all thermocouple inputs
OTcVal0 = mcc134_t_in_read(BAddress0,TcAddress0,TcVal0);
OTcVal1 = mcc134_t_in_read(BAddress0,TcAddress1,TcVal1);
OTcVal2 = mcc134_t_in_read(BAddress0,TcAddress2,TcVal2);
OTcVal3 = mcc134_t_in_read(BAddress0,TcAddress3,TcVal3);
//write TC data to these inputs so OpenPLC can read
if (int_input[1] != NULL) *int_input[1] = (uint16_t)OTcVal1;
if (int_input[2] != NULL) *int_input[2] = (uint16_t)OTcVal2;
if (int_input[3] != NULL) *int_input[3] = (uint16_t)OTcVal3;
}
As you can see, it's just a matter of following the example code from the comments
Hi @thiagoalvez, i am trying to implement an i2c Custom Layer to read a ITG/MPU accelerometer. I am a bit confused by the code provided by cactus5 in this discussion. We read our sensors values in updateCustomIn() and then, for us to be able to acces those values in our PLC programs we have to write them in the int_input vector.
Q1)
if we write -------------------> int_input[1] = 53;
then i am writing 53 to the %IW1 .... but for raspberryPi the is no %IW1 input pins when i look on the OpenPLC I/O mapping for the Raspberry Pi header.
in this case: is %IW1 just a label i use in my PLC program to get my data unrelated to I/O pins?
Q2) If so
Can I send by i2c multiple sensor values using only 2 I/O pins and then accesing them by writing something like this?
if (int_input[1] != NULL) *int_input[1] = (uint16_t)OTcVal1;
if (int_input[2] != NULL) *int_input[2] = (uint16_t)OTcVal2;
if (int_input[3] != NULL) *int_input[3] = (uint16_t)OTcVal3;
Q3)
If so
Is there a limit for that?
Thank you in advance Thiago. I think your hole work here is awsome 