gmoccapy pins

More
11 Aug 2024 17:37 #307485 by Moutomation
Replied by Moutomation on topic gmoccapy pins
The code written by Aciera works, but I'm having problems with permissions right now. I created a common folder between Windows and Linux. I can't give permission to this folder on the lşnux side, even though I used the chmod 777 command.

Please Log in or Create an account to join the conversation.

More
12 Aug 2024 10:20 #307530 by Moutomation
Replied by Moutomation on topic gmoccapy pins
Aciera, I thank you very much again. The code you wrote works perfectly. I was only having problems because I was trying to do this in the shared folder. I added the following code to the python code and copied the file to another location. Everything is OK now.

import shutil

# Source path
source = "/home/User/Documents/file.txt"

# Destination path
destination = "/home/User/Documents/newfile/file.txt"

# Copy the content of
# source to destination
shutil.copyfile(source, destination)
The following user(s) said Thank You: Aciera

Please Log in or Create an account to join the conversation.

More
12 Aug 2024 11:01 #307537 by Moutomation
Replied by Moutomation on topic gmoccapy pins
We are doing a project by spending a lot of time, writing macros, making a plc program. ethercat.xml file,hal files, how can we protect them from our competitors.

Please Log in or Create an account to join the conversation.

More
20 Aug 2024 05:54 #308189 by Moutomation
Replied by Moutomation on topic gmoccapy pins
Currently, the Windows folder is shared and we can see this folder in Linux. However, sometimes when Linux starts faster than Windows, Windows does not open and the Python code gives an error because it cannot find this file and Linuxcnc does not open. How can we do something here? For example, if it cannot find the file, it does not give an error and Linux starts. Can we do this? Having Linuxcnc open without errors is enough for me. It should be enough that it does not prevent Linuxcnc from starting.
If there is a file, it should read it. If there is no file, it should not prevent Linuxcnc from starting without giving an error.

Please Log in or Create an account to join the conversation.

More
20 Aug 2024 05:56 #308190 by Moutomation
Replied by Moutomation on topic gmoccapy pins
#!/usr/bin/env python3
import os
import time
import hal
import linuxcnc
import shutil

source = "/mnt/taglio/CutDocument.txt"
destination = "/mnt/CutDocument.txt"

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 = '/mnt/taglio/CutDocument.txt'
# wait time in milliseconds between file checks
check_interval = 1000
# length of output pulse in milliseconds
pulse_length = 1000

last_modified = os.path.getmtime(file_path)
check_timer_start = round(time.time()*1000)
h = 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!")
                    shutil.copyfile(source, destination)
                    h = True
                    pulse_timer_start = round(time.time()*1000)
                    last_modified = current_modified
                    shutil.copyfile(source, destination)
                if h and pulse_timer_start + pulse_length <= round(time.time()*1000):
                    h = False
            # restart the timer for file checking
            check_timer_start = round(time.time()*1000)
except KeyboardInterrupt:
    raise SystemExit

 

Please Log in or Create an account to join the conversation.

More
20 Aug 2024 06:05 - 20 Aug 2024 06:06 #308192 by Moutomation
Replied by Moutomation on topic gmoccapy pins
For example, if we can do this, there is always this file in the mnt folder. If there is no this file in the taglio folder, if we copy this file from the mnt folder to the taglio folder, my problem will be solved again.
for example:
#!/usr/bin/env python3
import os
import time
import hal
import linuxcnc
import shutil
source1 = "/mnt/CutDocument.txt"
destination1 = "/mnt/taglio/CutDocument.txt"
if there is no CutDocument
shutil.copyfile(source1, destination1)


source = "/mnt/taglio/CutDocument.txt"
destination = "/mnt/CutDocument.txt"

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 = '/mnt/taglio/CutDocument.txt'
# wait time in milliseconds between file checks
check_interval = 1000
# length of output pulse in milliseconds
pulse_length = 1000
Last edit: 20 Aug 2024 06:06 by Moutomation.

Please Log in or Create an account to join the conversation.

More
20 Aug 2024 06:30 #308193 by Aciera
Replied by Aciera on topic gmoccapy pins
I'm not sure I understand which file needs to go where but you can check for file existance using 'os.path.exists(file)':
if os.path.exists(source1):
   print("The file exists.")
else:
  print("The file does not exis so we copy it from the mnt to the taglio folder") 
  shutil.copyfile(source1, destination1)
The following user(s) said Thank You: Moutomation

Please Log in or Create an account to join the conversation.

More
20 Aug 2024 07:44 #308195 by Moutomation
Replied by Moutomation on topic gmoccapy pins
Great, just what I wanted, thank you very much for your support.
The following user(s) said Thank You: rodw

Please Log in or Create an account to join the conversation.

Moderators: newbynobiHansU
Time to create page: 0.070 seconds
Powered by Kunena Forum