JarvisSan22 / OPC-N3_python

Python repository for OPCN3 and OPCN2 on RPI3
GNU General Public License v3.0
12 stars 8 forks source link

"self" variable in OPC-N3_rec.py #4

Open lildevilx opened 2 years ago

lildevilx commented 2 years ago

Hello,

Inside the OPC-N3_rec.py, a lot of the def includes two variable (self, somethingelse). however when ever they are called in the main loop, it only has one variable. As well as there is something called "self.initOPC(ser)" What exactly does it do as this is not found in the OPC-N3_test.py.

Is it something that is required? I"m looking to just run just the OPC-N3 on my pi and finally getting the test version to work, it seemed quite promising.

Thanks!

JarvisSan22 commented 2 years ago

Hello thanks for your message. Self is a variable used inside classes in python to call itself. This is used when you want to set initial variables for the class. self.initOPC does just that. It turns on the OPC and sets the initial variables. THis can also be called multiple times inside the same class, as it also inside the self. This is used for restarts inside the OPC-N3_rec.py code

If you set up the variable.py file with your OPC port location and run start.py should all work. Did you test this code ?

kind regards

2022年4月14日(木) 23:08 RS @.***>:

Hello,

Inside the OPC-N3_rec.py, a lot of the def includes two variable (self, somethingelse). however when ever they are called in the main loop, it only has one variable. As well as there is something called "self.initOPC(ser)" What exactly does it do as this is not found in the OPC-N3_test.py.

Is it something that is required? I"m looking to just run just the OPC-N3 on my pi and finally getting the test version to work, it seemed quite promising.

Thanks!

— Reply to this email directly, view it on GitHub https://github.com/JarvisSan22/OPC-N3_python/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKZBQTA6JS2QDD3FTELLAIDVFARFPANCNFSM5TN4QNSA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

lildevilx commented 2 years ago

Ahhh I didn't think the OPC-N3_rec.py relied on running start.py, I'd figured that it since the test worked normally, I could've ran the _rec.py the same way.

I haven't tried the start.py yet as there was a ton of syntax issue I ran into, For example, for some reason my pi had a bunch of grief with the spacing/intents for the code.

I gave start.py and I'm running into more syntax and name errors like the following,

File "/home/pi/OPC-N3_python/AQ/OPCscripts/start.py", line 131 if MODE=="GPS": or MODE=="TEST" #if GPS or a TEST add the time in mins to the file name ^ SyntaxError: invalid syntax Traceback (most recent call last): File "/home/pi/OPC-N3_python/AQ/OPCscripts/start.py", line 16, in <module> MODE=V.MODE AttributeError: module 'variables' has no attribute 'MODE'

I'll try to go through it and hopefully not break it anymore.

Thanks!

lildevilx commented 2 years ago

Inside start.py I noticed this error File "/home/pi/OPC-N3_python/AQ/OPCscripts/start.py", line 134, in <module> f=initFile(startime.strtime('%Y%m%d-%H%M%S'),RPI,FOLDER,LOCATION,R) NameError: name 'startime' is not defined the variable should be starttime as per the rest the program.

Traceback (most recent call last): File "/home/pi/OPC-N3_python/AQ/OPCscripts/start.py", line 134, in <module> f=initFile(starttime.strtime('%Y%m%d-%H%M%S'),RPI,FOLDER,LOCATION,R) AttributeError: 'datetime.datetime' object has no attribute 'strtime' I believe its suppose to be strftime

The last thing is I can't seem to figure out how to fix this, however if i commented it out I was able to get it to run Traceback (most recent call last): File "/home/pi/OPC-N3_python/AQ/OPCscripts/start.py", line 152, in <module> newdata=pro.getData(p,r) File "/home/pi/OPC-N3_python/AQ/OPCscripts/opcn3_rec.py", line 383, in getData if data["period"]==0 or data["check"]==0: #error check added 04/09/2019 TypeError: string indices must be integers Thanks!