baobao

Dear thiagoralves,

I am a novice of OpenPLC, and I have learned that OpenPLC can drive Arduino or other types of boards through modbus protocol, but there is no TI-OMAPL138 board to be used in our laboratory, so I want to add an TI-OMAPL138 board to the support type of OpenPLC.

I have been reading the source code for some time and have been looking for information in this BBS for a long time. Here is what I know now:

1. The operation of the hardware in the main function in the /Webserver/core directory is mainly divided into three parts: 
    a.initializeHardware, 
    b.updateBuffersIn,
    c.updateCustomOut, 
and the three functions are all in a file which is in the Hardware_layers directory.

2. I found some scripts in the process of reading the source code files, such as Change_hardware_layer. Sh, the file appears to be based on user selection in the Hardware options, to replace the actual operation of the program are referenced hardware_layes. 
The CPP, but appeared such statements in the file, 
"
   echo win > ../scripts/openplc_platform
  echo blank > ../scripts/openplc_driver
"
I can't find openplc_platform and openplc_driver where these two files will be used.

3. I found a pages.py file in the Webserver directory, which seems to output the HTML/CSS/JAVAScript string through the python language, thus setting up the localhost web interface.In the hardware section, however, I found only the hardware_head and hardware_tail sections, and the subject section in the middle appears to be generated dynamically by calling CodeMirror. FromTextArea (custom_layer_code,options).However, I have not found such file named "custom_layer_code" .Also, which files should I modify to make omapl138 appear in the hardware section of the localhost page

In conclusion:

So can I add a board for OMAPL138 in the following steps?

1. Write a similar l138.cpp by imitating the raspberrypi.cpp file in hardware_layers directory

2. Modify the change_hardware_layer. sh file.Replace the l138.cpp I created with hardware_layes.cpp

3. Modify pages.py to generate an option of L138 board in the localhost page

 

The above is what I have learned and the question I would like to ask you. I hope you can help me correct it in your spare time. Thank you sincerely!

Quote 0 0
baobao
I was lucky enough to find the answer on line 1274 of webserver.py on how to generate a new option in the localhost page hardware column.
Here is the source code:

def hardware():
if (flask_login.current_user.is_authenticated == False):
return flask.redirect(flask.url_for('login'))
else:
if (openplc_runtime.status() == "Compiling"): return draw_compiling_page()
if (flask.request.method == 'GET'):
with open('./scripts/openplc_driver') as f: current_driver = f.read().rstrip()
return_str = pages.w3_style + pages.hardware_style + draw_top_div() + pages.hardware_head
return_str += draw_status()
return_str += """
</div>
<div style="margin-left:320px; margin-right:70px">
<div style="w3-container">
<br>
<h2>Hardware</h2>
<p>OpenPLC controls inputs and outputs through a piece of code called hardware layer (also known as driver). Therefore, to properly handle the inputs and outputs of your board, you must select the appropriate hardware layer for it. The Blank hardware layer is the default option on OpenPLC, which provides no support for native inputs and outputs.</p>
<!-- <p>This section allows you to change the hardware layer used by OpenPLC. It is also possible to augment the current hardware layer through the hardware layer code box. -->
<p><b>OpenPLC Hardware Layer</b><p>
<form id = "uploadForm"
enctype = "multipart/form-data"
action = "hardware"
method = "post">
<select id='hardware_layer' name='hardware_layer' style="width:400px;height:30px;font-size: 16px;font-family: 'Roboto', sans-serif;">"""
if (current_driver == "blank"): return_str += "<option selected='selected' value='blank'>Blank</option>"
else: return_str += "<option value='blank'>Blank</option>"
if (current_driver == "blank_linux"): return_str += "<option selected='selected' value='blank_linux'>Blank Linux</option>"
else: return_str += "<option value='blank_linux'>Blank with DNP3 (Linux only)</option>"
if (current_driver == "fischertechnik"): return_str += "<option selected='selected' value='fischertechnik'>Fischertechnik</option>"
else: return_str += "<option value='fischertechnik'>Fischertechnik</option>"
if (current_driver == "neuron"): return_str += "<option selected='selected' value='neuron'>Neuron</option>"
else: return_str += "<option value='neuron'>Neuron</option>"
if (current_driver == "pixtend"): return_str += "<option selected='selected' value='pixtend'>PiXtend</option>"
else: return_str += "<option value='pixtend'>PiXtend</option>"
if (current_driver == "pixtend_2s"): return_str += "<option selected='selected' value='pixtend_2s'>PiXtend 2s</option>"
else: return_str += "<option value='pixtend_2s'>PiXtend 2s</option>"
if (current_driver == "pixtend_2l"): return_str += "<option selected='selected' value='pixtend_2l'>PiXtend 2l</option>"
else: return_str += "<option value='pixtend_2l'>PiXtend 2l</option>"
if (current_driver == "rpi"): return_str += "<option selected='selected' value='rpi'>Raspberry Pi</option>"
else: return_str += "<option value='rpi'>Raspberry Pi</option>"
if (current_driver == "rpi_old"): return_str += "<option selected='selected' value='rpi_old'>Raspberry Pi - Old Model (2011 model B)</option>"
else: return_str += "<option value='rpi_old'>Raspberry Pi - Old Model (2011 model B)</option>"
if (current_driver == "simulink"): return_str += "<option selected='selected' value='simulink'>Simulink</option>"
else: return_str += "<option value='simulink'>Simulink</option>"
if (current_driver == "simulink_linux"): return_str += "<option selected='selected' value='simulink_linux'>Simulink with DNP3 (Linux only)</option>"
else: return_str += "<option value='simulink_linux'>Simulink with DNP3 (Linux only)</option>"
if (current_driver == "unipi"): return_str += "<option selected='selected' value='unipi'>UniPi v1.1</option>"
else: return_str += "<option value='unipi'>UniPi v1.1</option>"
return_str += """
</select>
<br>
<br>
<p><b>Hardware Layer Code Box</b><p>
<p>The Hardware Layer Code Box allows you to extend the functionality of the current driver by adding custom code to it, such as reading I2C, SPI and 1-Wire sensors, or controling port expanders to add more outputs to your hardware</p>
<textarea wrap="off" spellcheck="false" name="custom_layer_code" id="custom_layer_code">"""
with open('./core/custom_layer.h') as f: return_str += f.read()
return_str += pages.hardware_tail

else:
hardware_layer = flask.request.form['hardware_layer']
custom_layer_code = flask.request.form['custom_layer_code']
with open('./active_program') as f: current_program = f.read()
with open('./core/custom_layer.h', 'w+') as f: f.write(custom_layer_code)

subprocess.call(['./scripts/change_hardware_layer.sh', hardware_layer])
return "<head><meta http-equiv=\"refresh\" content=\"0; URL='compile-program?file=" + current_program + "'\" /></head>"

return return_str
Quote 0 0