Post by jst69 on Python script: Launch Codesys, Execute Script, Exit Codesys
CODESYS Forge
talk
(Post)
Dear all: Question about scripting: I am creating a .NET program that is supposed to Open codesys, open template project, export a bunch of pou, then exit codesys. Launch works, Open project works, Export works, But how do i tell codesys to close itself? I can tell windows to terminate codesys, but i would prefer to do it properly. from __future__ import print_function import sys import System proj = projects.primary # We're interested in POU nodes: POUGuid = Guid("6f9dac99-8de1-4efc-8465-68ac443b7d08") # We collect all POU nodes in that list. pous = [] # From the parent node on, we recursively add POU nodes: def CollectPous(node): if node.type == POUGuid: pous.append(node) else: for child in node.get_children(): CollectPous(child) # Now we collect all the leaf nodes. for node in proj.get_children(): CollectPous(node) # We print everything just to know what's going on. for i in pous: print("found: ", i.type, i.guid, i.get_name()) # And now we export the files. for candidate in pous: # We create a list of objects to export: # The object itsself objects = [candidate] # And sub-objects (POUs can have actions, properties, ...) objects.extend(candidate.get_children()) # And the parent folders. parent = candidate.parent while ((not parent.is_root) and parent.is_folder): objects.append(parent) parent = parent.parent # Create an unique file name: if len(sys.argv) == 1: filename = "parent\\%s.export" % (candidate.get_name()) else: filename = "%s\\%s.export" % (sys.argv[1],candidate.get_name()) # print some user information print("exporting ", len(objects), " objects to: ", filename) # and actually export the project. proj.export_xml(objects, filename) proj.close() print ("script finished.") System.exit(0) // Dont work .NET: public static void Export(string path,string proj) { if (checkSettings()) { var p = new System.Diagnostics.Process(); p.StartInfo.FileName = Properties.Settings.Default.CSVersion +"\\CODESYS\\Common\\CODESYS.exe"; p.StartInfo.Arguments = " --Profile=" + qoute(Properties.Settings.Default.CSProfile) + " --culture=en" + " --project=" + qoute(path + "\\" + proj) + " --runscript=" + Properties.Settings.Default.LastOpenProjectPath + "\\INPUT_DATA\\SCRIPT\\Export.py" + " --scriptargs:" + qoute(path) ; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = false; p.Start(); p.StandardOutput.ReadToEnd(); p.CloseMainWindow(); p.Close(); } }
Last updated: 2024-01-16
Post by alimans on Hex string
CODESYS Forge
talk
(Post)
Hi kdkwhite, for Word you still can use suggested code by using a union structure and crack down your Word to two byte as bellow: TYPE CrackWordToByte : UNION InWord : WORD; OutBytes : ARRAY [0..1] OF BYTE; END_UNION END_TYPE then define your variable as this type: udInput : CrackWordToByte; now assign your Word variable input to InWord and send OutBytes[x] to the mentioned method: udInput.InWord := WordVariableInput; Input := udInput.OutBytes[x]; Regarding your question about the code: actually 48 is ascii code of "0" and while 65 is the ascii code of "A" so in above code 55 + 10 would be 65.
Last updated: 2023-09-20
Post by dhumphries on Toggling Visualizations using HMI Physical Buttons
CODESYS Forge
talk
(Post)
Nothing wrong with ladder, in a lot of applications it is simpler than ST or CFC, you're a lot less likely to have syntax issues in a ladder diagram than in structured text as long as you stick with traditional ladder elements. Your attempt was almost valid, but you tried to change the currentvisu variable using a blend of structured text and ladder, which isn't allowed. You need to use the MOVE operator and define the visualization name as a string on the input side and the visuelems.currentvisu as the target on the output side.
Last updated: 2024-02-28
Post by sumit on Not able to see input data coming from eip adapter on codesys
CODESYS Forge
talk
(Post)
dhumphries, I changed the datatype this time from BYTE to USINT (because that's what my adapter is sending: array of uint8_t). The text "New Help String" you saw in previous screenshots is just the description of the input/s (it can be anything). I also looked into the logs (see attached) for that ! sign next to the device, I found that connection is being timeout. I tried some suggestions from online such as increase the RPI but still got connection timeout issue, also by changing the datatype, I still don't see incoming data from the adapter, although its visible on wireshark. thanks,
Last updated: 2024-03-07
Post by andrej on Write to File on soft PLC winV3x64
CODESYS Forge
talk
(Post)
Hello all, I would like to store some data in text file. I use the soft PLC Win V3x64, on Windows 10. I use the SysFile Library 3.5.17.0. If I store the file directly in the in the directory of the PLC i.e. in '/CODESYSControlWinV3x64/E1FA7ABE/PlcLogic/LogAU.txt' the file is correctly filled with the data. However, If I use an absolute path to a different directory no data is stored in the respective file. Despite the fact that the respective file exists and the Filehandler is correctly opened (see in picture _fdSysFHandle <> -1). // sFileName : STRING := 'LogAU.txt'; // STORES FILE IN ../CODESYSControlWinV3x64/../PlcLogic/LogAU.txt' sFileName : STRING := 'C/Temp/LogAU.txt'// DOES NOT WORK --------------------- // FILE DESCRIPTOR _fdSysFHandle := SysFile.SysFileOpen( szFile:= sFileName,am:= SysFile.AM_APPEND,pResult := ADR(_Result)); Does some have an idea where the problem is, resp. how I can get store a file in an arbitrary directory. Thanks a lot and kind regards Andreas
Last updated: 2023-10-24
How to configure CODESYSControl_User.cfg in order to use a specific network card for OPCUA Server
CODESYS Forge
talk
(Thread)
How to configure CODESYSControl_User.cfg in order to use a specific network card for OPCUA Server
Last updated: 2023-08-28
how to transfer raspberrypi runtime license from sdcard to dongle without the original raspi?
CODESYS Forge
talk
(Thread)
how to transfer raspberrypi runtime license from sdcard to dongle without the original raspi?
Last updated: 2021-04-13
What is the best way to upgrade a project to a new version of Codesys?
CODESYS Forge
talk
(Thread)
What is the best way to upgrade a project to a new version of Codesys?
Last updated: 2022-03-01
I want to use the function of PVT to realize move
CODESYS Forge
talk
(Thread)
I want to use the function of PVT to realize move
Last updated: 2013-05-14
How to intercept a variation in the RetainPerstist variables (for saving to file)
CODESYS Forge
talk
(Thread)
How to intercept a variation in the RetainPerstist variables (for saving to file)
Last updated: 2018-08-03
How to set "Always updatevariables" to "enable 2" by default in DeviceDescription.
CODESYS Forge
talk
(Thread)
How to set "Always updatevariables" to "enable 2" by default in DeviceDescription.
Last updated: 2020-12-10
Specify Input Configuration "OnDialogClosed" Action to only react to certain Dialogs
CODESYS Forge
talk
(Thread)
Specify Input Configuration "OnDialogClosed" Action to only react to certain Dialogs
Last updated: 2023-10-02
Can't connect to my raspberry pi 3 after I tried to adjust CODESYScontrol.cfg
CODESYS Forge
talk
(Thread)
Can't connect to my raspberry pi 3 after I tried to adjust CODESYScontrol.cfg
Last updated: 2021-06-17
How to connect Codesys Control win v3 to an ethercat device
CODESYS Forge
talk
(Thread)
How to connect Codesys Control win v3 to an ethercat device
Last updated: 2021-04-26
How to generate PDO explicit request with RTR flag to TRUE
CODESYS Forge
talk
(Thread)
How to generate PDO explicit request with RTR flag to TRUE
Last updated: 2018-06-13
Codesys closes instantly after I try to download to PLC
CODESYS Forge
talk
(Thread)
Codesys closes instantly after I try to download to PLC
Last updated: 2022-12-21
Unable to get retain variables to work in a specific Raspberry Pi project
CODESYS Forge
talk
(Thread)
Unable to get retain variables to work in a specific Raspberry Pi project
Last updated: 2019-12-03
Cannot convert type 'Unknown type: 'ADR(tabOrderIdArray)" to type 'POINTER TO ARRAY [0..0]OF INT'
CODESYS Forge
talk
(Thread)
Cannot convert type 'Unknown type: 'ADR(tabOrderIdArray)" to type 'POINTER TO ARRAY [0..0]OF INT'
Last updated: 2021-04-26
what to do in case of a writing error to eeprom
CODESYS Forge
talk
(Thread)
what to do in case of a writing error to eeprom
Last updated: 2020-11-26
Beaglebone Black - only one Ethernet port - how to connect to LAN, and EtherCAT?
CODESYS Forge
talk
(Thread)
Beaglebone Black - only one Ethernet port - how to connect to LAN, and EtherCAT?
Last updated: 2022-01-16
Trying to Use Python Script to Exclude Certain Objects from Build
CODESYS Forge
talk
(Thread)
Trying to Use Python Script to Exclude Certain Objects from Build
Last updated: 2019-08-20
Attempt to upgrade a pi 3 from a working V3.5.11 to V3.5.15 fails
CODESYS Forge
talk
(Thread)
Attempt to upgrade a pi 3 from a working V3.5.11 to V3.5.15 fails
Last updated: 2021-07-13
Unable to connect to sensor even after Log says successful connection (Ethernet/IP)
CODESYS Forge
talk
(Thread)
Unable to connect to sensor even after Log says successful connection (Ethernet/IP)
Last updated: 2022-06-29
How to change data format of 'Trend' time data to DT or something else
CODESYS Forge
talk
(Thread)
How to change data format of 'Trend' time data to DT or something else
Last updated: 2021-05-10
Is it possible to send a real value close to 0 through modbus?
CODESYS Forge
talk
(Thread)
Is it possible to send a real value close to 0 through modbus?
Last updated: 2023-02-25
To search for an exact phrase, put it in quotes. Example: "getting started docs"
To exclude a word or phrase, put a dash in front of it. Example: docs -help
To search on specific fields, use these field names instead of a general text search. You can group with AND
or OR
.