gmoccapy pins
- Moutomation
- Offline
- Premium Member
Less
More
- Posts: 135
- Thank you received: 11
07 Aug 2024 11:32 - 07 Aug 2024 11:40 #307169
by Moutomation
Replied by Moutomation on topic gmoccapy pins
It's very nice, it works very well, thank you very much.
Last edit: 07 Aug 2024 11:40 by Moutomation.
Please Log in or Create an account to join the conversation.
07 Aug 2024 11:42 #307170
by Aciera
Replied by Aciera on topic gmoccapy pins
File path is defined in this line in the python code of the user component above:
eg change to:
file_path = 'file.txt'
eg change to:
file_path = '/home/<user_name>/<your_path>/<your_file>'
The following user(s) said Thank You: Moutomation
Please Log in or Create an account to join the conversation.
- Moutomation
- Offline
- Premium Member
Less
More
- Posts: 135
- Thank you received: 11
07 Aug 2024 12:45 #307172
by Moutomation
Replied by Moutomation on topic gmoccapy pins
thaks a lot
Please Log in or Create an account to join the conversation.
- Moutomation
- Offline
- Premium Member
Less
More
- Posts: 135
- Thank you received: 11
09 Aug 2024 07:40 #307299
by Moutomation
Replied by Moutomation on topic gmoccapy pins
I created a folder shared between Windows and Linux. I saved the File.txt file in this folder in Windows. When I open the file.txt file on the Windows side, make changes to it and save it, the g code changes directly in Linuxcnc. Everything is fine up to this point. However, while the Python code is running, I cannot send the new file.txt file with the same name to this folder, I receive a no permission warning. If I close Linuxcnc and the Python code does not work, I can replace the new file with the old file. There is no problem in going into the file.txt file, making changes and saving it. There is only a problem when replacing the old file.txt with the new file.txt.
I tried to do it, I tried to add time to the Python code, but I couldn't. I don't know if adding time is a solution anyway.
I tried to do it, I tried to add time to the Python code, but I couldn't. I don't know if adding time is a solution anyway.
Please Log in or Create an account to join the conversation.
09 Aug 2024 08:18 #307302
by Aciera
Replied by Aciera on topic gmoccapy pins
Not sure as I cannot test updating the file remotely but if you want to add a time delay between file checks you could try this modified python component.
#!/usr/bin/env python3
import os
import time
import hal
import linuxcnc
h = hal.component("file-check")
h.newpin("file-changed", hal.HAL_BIT, hal.HAL_OUT)
h.ready()
# create a connection to the status channel
s = linuxcnc.stat()
# this is the file being checked for updates (example looks for 'file.txt' in the config folder)
file_path = 'file.txt'
# wait time in milliseconds between file checks
check_interval = 5000
# length of output pulse in milliseconds
pulse_length = 1000
last_modified = os.path.getmtime(file_path)
check_timer_start = round(time.time()*1000)
h['file-changed'] = False
try:
while 1:
s.poll()
# see if it is time to check the file
if round(time.time()*1000) >= check_timer_start + check_interval:
# we don't want to reload when program is running
if s.task_mode == 2 and s.state == 1: # ie AUTO-mode and 'RCS_DONE'
current_modified = os.path.getmtime(file_path)
if current_modified != last_modified:
print("File has changed!")
h['file-changed'] = True
pulse_timer_start = round(time.time()*1000)
last_modified = current_modified
if h['file-changed'] and pulse_timer_start + pulse_length <= round(time.time()*1000):
h['file-changed'] = False
# restart the timer for file checking
check_timer_start = round(time.time()*1000)
except KeyboardInterrupt:
raise SystemExit
The following user(s) said Thank You: Moutomation
Please Log in or Create an account to join the conversation.
- Moutomation
- Offline
- Premium Member
Less
More
- Posts: 135
- Thank you received: 11
09 Aug 2024 14:44 - 09 Aug 2024 14:45 #307363
by Moutomation
Replied by Moutomation on topic gmoccapy pins
When I go into the file.txt file, make corrections manually and save it, there is no problem. But I cannot replace it with a new file.txt file, I get the error that the file is in use.
While the python code is running it won't let me replace it with a file of the same name
While the python code is running it won't let me replace it with a file of the same name
Last edit: 09 Aug 2024 14:45 by Moutomation.
Please Log in or Create an account to join the conversation.
- Moutomation
- Offline
- Premium Member
Less
More
- Posts: 135
- Thank you received: 11
10 Aug 2024 06:49 #307403
by Moutomation
Replied by Moutomation on topic gmoccapy pins
I think I found a solution. When Linuxcnc first opens, we must wait for a while and delete the file.txt file with Python. Then we must constantly check whether the file exists. Once the file is in the folder, we must activate the change button.
Please Log in or Create an account to join the conversation.
10 Aug 2024 08:18 #307405
by Aciera
Replied by Aciera on topic gmoccapy pins
This will delete the file on startup:
#!/usr/bin/env python3
import os
import time
import hal
import linuxcnc
h = hal.component("file-check")
h.newpin("file-changed", hal.HAL_BIT, hal.HAL_OUT)
h.ready()
# create a connection to the status channel
s = linuxcnc.stat()
# this is the file being checked for updates (example looks for 'file.txt' in the config folder)
file_path = 'file.txt'
# wait time in milliseconds between file checks
check_interval = 5000
# length of output puls in milliseconds
pulse_length = 1000
last_modified = os.path.getmtime(file_path)
check_timer_start = round(time.time()*1000)
h['file-changed'] = False
# delete the file if it already exists
if os.path.exists(file_path):
print("The file exists, deleting it.")
os.remove(file_path)
else:
print("The file does not exist")
try:
while 1:
s.poll()
if round(time.time()*1000) >= check_timer_start +check_interval:
# we don't want to reload when program is running
if s.task_mode == 2 and s.state == 1: # ie AUTO-mode and 'RCS_DONE'
current_modified = os.path.getmtime(file_path)
if current_modified != last_modified:
print("File has changed!")
h['file-changed'] = True
pulse_timer_start = round(time.time()*1000)
last_modified = current_modified
if h['file-changed'] and pulse_timer_start + pulse_length <= round(time.time()*1000):
h['file-changed'] = False
check_timer_start = round(time.time()*1000)
except KeyboardInterrupt:
raise SystemExit
Please Log in or Create an account to join the conversation.
- Moutomation
- Offline
- Premium Member
Less
More
- Posts: 135
- Thank you received: 11
10 Aug 2024 08:46 - 10 Aug 2024 08:48 #307408
by Moutomation
Replied by Moutomation on topic gmoccapy pins
thank you very much.
Last edit: 10 Aug 2024 08:48 by Moutomation.
Please Log in or Create an account to join the conversation.
10 Aug 2024 19:55 #307435
by rodw
Replied by rodw on topic gmoccapy pins
It seems like you guys need to build a folder watcher,
The operating system has methods to do something if the contents of a folder changes.
Python has an interface to this. There are a number of examples on the web. Here is one to get you going
thepythoncorner.com/posts/2019-01-13-how...-filesystem-changes/
The operating system has methods to do something if the contents of a folder changes.
Python has an interface to this. There are a number of examples on the web. Here is one to get you going
thepythoncorner.com/posts/2019-01-13-how...-filesystem-changes/
The following user(s) said Thank You: Aciera, Moutomation
Please Log in or Create an account to join the conversation.
Time to create page: 0.078 seconds