Cactus5
Hi All, 

I am using an MCC134 Thermocouple hat with Raspberry Pi. I have written a program in the Hardware layer box that sets up the board and retrieves temperature info from each of the 4 thermocouples. I am currently saving that info to a variable within the Loop. How do I take the temp data saved to those variable and make it accessible to the OpenPLC runtime/ Variable within the OpenPLC Editor?

Thanks for your help!
Reply 1 0
thiagoralves
It depends on where you’re saving the data. To be accessible from OpenPLC programs the data must be on the OpenPLC buffers:
int_input[x] (16-bit input variables) = %IWx
bool_input[x][y] (1-bit input variables) = %IXx.y
Reply 0 0
Cactus5

Hi Thiago,
Thanks for your reply! 
(Forgive my ignorance) but if I understand you correctly, I would need to write those int values to up to 4 of the input pins on the board? 

then at that point I could connect the corresponding variable in the ladder logic to those input pins? 

Reply 0 0
Cactus5
Also-if it changes anything-

The MCC134 communicates the temperature data  of the thermocouples to the pi using SPI.

one other thought I had, after reading some of the posts, would this be better achieved as a C extension within the editor so that the variables are more readily available?

Thanks! 
Reply 0 0
Robert Lewczuk
Cactus5 wrote:
Also-if it changes anything-

The MCC134 communicates the temperature data  of the thermocouples to the pi using SPI.

one other thought I had, after reading some of the posts, would this be better achieved as a C extension within the editor so that the variables are more readily available?

Thanks! 


Any luck? I am trying to do similar with MAX31855. I can read the temperature just fine in python but im at a loss how to get it into the PLC....
Reply 0 0
Cactus5
Hi Robert,

Unfortunately none yet- I have a feeling that the libraries for the thermocouple HAT are not being found by the program- though I’m not sure how to diagnose that from the hardware layer, and therefore the code just doesn’t work. 

My next move is to try to use the editor and run the script in the plc editor. Fingers crossed!  

Reply 0 0
thiagoralves
@Cactus5 Did you try the code I sent you on the post below? I'm pretty sure the issue related to errors in your code.

post:  https://openplc.discussion.community/post/syntax-of-hardware-layer-box-code-11038635?pid=1318514558 
Reply 0 0
Cactus5
Hi Thiago, 

Sorry I didn't reply to you sooner, thank you for your time and the help with the code! I did use your corrected code but I was still unable to see any data on that variable while monitoring. I have been reviewing the details on the DAQHATs Gitub page and found that I had a couple further errors in my code - 

(Daqhats gitub: https://github.com/mccdaq/daqhats)

For instance:

 OTcVal3 = mcc134_t_in_read(BAddress0,TcAddress3,TcVal3);

would only return either a 1 or a 0 to the OTcVal3 variable for success or error  - so instead I must use the TcVal3 variable to return the reading from the Thermocouple. However after trying this and a couple other changes to the code I still came up short. Is there a way to see the errors that are returned from this code when it complies? 

I have ignored the following pins to allow SPI Communication (one is different from the code in the other post)

Bool In pins : 6, 7, 10, 15
Bool out pins 5, 7, 12
int In pins 1,2,3,4 

The MCC134 takes GPIO8, 9, 10, 11, 12, 13, 26 pins  - does the above look correct? I cross referenced this with the diagram in the how-to for the OpenPLC editor to get the I/O numbers.

My other concern is also that the DAQHATS code requires the use of the linker option -ldaqhats- 
and I am not sure how to code that into the hardware layer. Would it benefit the system if I moved the location of some of the libraries and .h files to another location within the OpenPLC file tree?

Thanks!
Reply 0 0
thiagoralves
Cactus5 wrote:
However after trying this and a couple other changes to the code I still came up short. Is there a way to see the errors that are returned from this code when it complies? 

Yes. When you click on save changes from the hardware layer page you are directed to a compiling page that shows the output of the compilation process. Pasting it here would be useful to help debug the issue.
Reply 0 0
Cactus5
Errors below:

Internal compiler error in file generate_location_list.cc at line 150.
POUS.c
POUS.h
LOCATED_VARIABLES.h
VARIABLES.csv
Config0.c
Config0.h
Res0.c
Error generating C files
Compilation finished with errors!
Reply 0 0
thiagoralves
It seems that either your installation is messed up or the last program you uploaded is faulty. Try loading the blank program first and save the hardware layer code again
Reply 0 0
Cactus5

Thanks Thiago,


ill give this a try and report back! 

Reply 0 0
Cactus5
Hi Thiago,

I was able to get past those errors above after a fresh install. 

It looks like the code I'm writing in the hardware layer is unable to see the includes for the Thermocouple HAT libraries, See errors below :

/usr/bin/ld: /tmp/ccqOM5sA.o: in function `initCustomLayer()':
hardware_layer.cpp🙁.text+0x6c): undefined reference to `mcc134_tc_type_write'
/usr/bin/ld: hardware_layer.cpp🙁.text+0x88): undefined reference to `mcc134_tc_type_write'
/usr/bin/ld: hardware_layer.cpp🙁.text+0xa4): undefined reference to `mcc134_tc_type_write'
/usr/bin/ld: hardware_layer.cpp🙁.text+0xc0): undefined reference to `mcc134_tc_type_write'
/usr/bin/ld: hardware_layer.cpp🙁.text+0xdc): undefined reference to `mcc134_update_interval_write'

Is there anywhere specific in the OpenPLC files that i should place the include files for the thermocouple HAT? I did put  #include <daqhats/daqhats.h> at the top of the hardware layer code...

Thanks!
Reply 0 0
thiagoralves
I'm not familiar with those daq hats, but I believe that if you add the linker option at the end (-ldaqhats) of the compile line it will work. The compilation script can be found at OpenPLC_v3/webserver/scripts/compile_program.sh. Open the compile_program.sh file on a text editor and change line 108 from this
g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w

to this
g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -ldaqhats -w

As you can see, I just added the -ldaqhats at the end of the compile line before the -w option. If there are other link options to add from the daq hats instructions you can add them here.
Reply 0 0
Cactus5
Excellent, That worked.

I was able to get the hardware layer to compile. However, when I loaded my basic PLC Program - I still received the following errors in the copiler:

Internal compiler error in file generate_location_list.cc at line 150.
POUS.c
POUS.h
LOCATED_VARIABLES.h
VARIABLES.csv
Config0.c
Config0.h
Res0.c
Error generating C files
Compilation finished with errors!

Should I - re-write my PLC program and try again? 

The program is essentially:
1 global variable (TEMP) set to %1W3
1 local variable (TEMP) set to the global variable
1 local variable(TEMPOUT) writing to %MD0.3 to monitor the value of that Variable

Local variable TEMP set as an input variable connected to the TEMPOUT variable set as an Output Variable

SO CLOSE!!
Reply 0 0
Reply