Write variables of TwinCAT 2 PLC via ADS remotely - c#

The reason why I am asking a question is because I am having issues writing variable values of a TwinCAT 2 system remotely (but reading variables works fine).
The setup what I am trying to make working is the following: There is an avreage PC where the I would like run my .NET 6 based application TwinCAT.Ads 6.0.129 included, and the 3.1 4024.29 build of TwinCAT 3 runtime is installed. The remote system an industrial assambly station based on (PC-165552) TwinCAT 2 runtime version 2.11 build 2126. The way why I trying to get acces to the variables of the TwinCAT 2 system is CreateVariableHandle, then use the ReadAny, and WriteAny methods. I tried other ways as well but this looks the easiest for me.
I have tested my code to running a test TwinCAT runtime PLC on my localhost, and get acces to the variables of test runtime. The whole data exchange worked fine I could read and write variables, but somehow if I change to remote and I try to acces to the remote PLC variables I can only read thier values, but not write them.
I tried several ways to indentify the problem. I installed the TwinCAT engineering and tried to analyse the ADS communication via the integrated ADS Monitor tool. I sent a Write Request with the ADS Command test tool to the certain variable but even taught the transfer was succesfull the variable did not changed. I also monitored the process with ADS monitor so I had a possibility to check the conctent of the Request and Response messages and they looked absolutely fine with no error. I studied all the available documentation, but I couldent find anything what could cause the mentioned issue.
Since the C# code works fine on local host, and I cant even write those variables remotely on the given target station even with the built in Beckhoff tools. My conclusion is some sort of settings must be wrong on the TwinCAT 2 target station (maybe firewall or something).
Could you please give me some hints where and what settigns I suppose to look around.

The issue was the certain variable was overwriten cyclically on the remote (PLC) side. Unfortunatelly I did't have acces to the source code of the PLC, therefore I did't have a possibility to verifly it myself.
I was expecting something like that because the I didn't received any error during the write request. So it was succesfull but right after the variable was overwriten.
I just swithed the PLC to stop to stop the porgram execution, and after I tried to write the variable.

Related

C# application which installs and allows for global command line

I would like to build a simple .NET application that installs on a windows machine which will allow the end user to open a command prompt and type "google test" which will open google and search for test. But I'm not sure how to install a global "keyword" such as "google". Is this down via Environment variables? How does this link up to my .NET application?
Any advice or pointers is appreciated.
Thanks
This is beyond a .NET application and belongs into the Area of Setup programms. Visual Studio used to have a Installer Project, but as there are so many 3rd party ways this was removed.
Having "google test" parsed as a google search for "test" is tricky, but possible. However it depends entirely on how the commandline is parsed in a Windows. Wich is pretty much the way it was parsed since DOS 1.0.
If you just enter a word like "google", the commandline will look if there is a Excetuable file (.exe, .com, .bat) of that name in the current folder (working directory). It will then look into all the folders defined in the path variables. However using path variables is so dated, I could find only a single entry in my Windows Path variable now. And it is for MS backward compatibility: "%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;"
Most starting of programms is done via file associations with a specific type. And protocoll associations with a protocoll (like http, https, steam). Indeed my advise would be to make a .NET Programm named "google" whose sole purpose is to to format the proper URL, then send it to console parsing via ProcessStart. And let Windows solve wich programm to use from there.
Edit: And as I only realized after wirting this, apparently Windwos finally supports commandline aliases. https://learn.microsoft.com/en-us/windows/console/console-aliases
Apparently they even added a way to make them via the WinAPI in Windows 2000. However that requires moving to unmanaged code. And I have no experience, but it appears those aliases might only be valid for one console instance. So you might have to put it into a place like hte autoexec.bat to be called everytime a console is created.

Looking to launch a local exe on a remote machine without having the resurces on the remote machine

So I have built some code, it's quite simple basically it stops all active input from keyboard and mouse until a text file of a certain name appears in the C:\Temp directory. It also has a manifest file to run it as administrator on start up.
So I found something that on the surface looks like it fulfils my needs of being able to do this task however upon running it I found out that the project has been compiled in x86 and does not run on my x64 machine. Here is the reference to the project if anyone would like to look into it, it's a very smartly designed piece of code that does an interesting objective. It also explains clearly enough what I am trying to accomplish.
So after implementing this (and failing) I have setup a couple other avenues to try, one is VBA through excel with the VBA copying itself to and from the machines in a list and running itself, then there is using VBS to write the entire code as a txt file on the target machine change the extension and then execute it remotely. I have just started researching these but I imagine the problems of running as an administrator amongst other things will crop up again to be dealt with. To be honest though I would really prefer to do this in C# only as that is the language I'm trying to go further in so I'm interested in this challenge. If anybody knows of a similar library of code or application I could look into to achieve what I'm trying I would appreciate being pointed in the right direction.
I would try and be more specific about what libraires/API's im trying to implement but the truth is I don't know what libraries I need to even interact with to get what I want. My goal is to have C# executable code on my machine and a tool that can run that executable on another machine.
Thanks
Thanks to the help in comments from #Nick.McDermaid I was able to correctly open and build the project I was trying to download. Unsure what caused the issue previously with me not being able to open and interact with the code but now I have it I shall pursue this avenue further to accomplish my goal.
As an addendum one other avenue I tried for executing code remotely was through VBS where I used
set svcproc=getobject("winmgmts:{impersonationLevel=impersonate}!\\"&MachineName & "\root\cimv2:win32_process")
scmd="""C:\Program Files\Internet Explorer\iexplore.exe"" -framemerging ""https://gifyu.com/images/Boo-Ghost-Gif.gif"""
'scmd="C:\Windows\notepad.exe"
iret=svcproc.create(scmd,null,null,pid)
set svcproc=nothing
to execute something that existed on the remote machine but I ran into a LOT of security policy issues where I could launch the process but I couldn't bring it to the foreground as the Malware tracker on the machine thought it was an attack and quashed it immediately.

Should I use ini or registry to store parameters for application in C# for Windows 7

I'm writing a Windows application in C#.
Its an application that when called outputs data to a printer and com port. It has to be invisible to the user, so I have a separate application to set up the printer and com port parameters that the application reads every time it is started. The application starts, runs for a couple of seconds and then closes, until it is executed again, which will haven periodically every few minutes. So, unless I hard code the printer and com port settings, I guess I need to have them read every time the application is started.
So is it faster to read from, an ini, XML, or registry/local machine?
Speed is my main deciding factor.
Is there any other way to the variables between executions? In Linux i might use environment variables, is that a feasible option in windows?
Thanks
How about using an AppSetting?
This will read an <appsettings> entry that you can put in either the .config for the project or in the machine.config in the Microsoft .NET folder on the machine.
Then in the code You can just reference ConfigurationManager.AppSettings["printer"] anywhere you need to. You can edit the appsetting at any time.
I will warn you though, be very careful when messing with the machine.config, you can really mess up your pc or environment if you use incorrect syntax or forget a closing /> For this reason, I would highly recommend using the .config of your project.
Check this link for more info

Mono/Linux and wininet.dll

I've got a commandline C# program that compiles and runs fine using Visual C# 2010 and Windows 7. It also compiles and starts fine on Linux/Mono (2.10), but then sits there. (The program is using a 3rd party DLL to fetch data from a remote server.)
Running it in the debugger, I saw it seemed to be waiting for a DNS lookup. So I did the DNS lookup for it, pasted in the IP address. But it still hangs, and breaking into the debugger shows three threads all sitting there waiting:
System.Threading.Monitor.Wait (timeout set to -1)
System.Threading.Thread.Sleep
System.Threading.WaitHandle.WaitOne
I used MoMA to analyze the DLL. I'm not sure how accurate that is, because it matches against Mono 2.8, and I'm using 2.10.8.1, but it says Socket.Dispose() is a missing method. Then 32 [MonoTodo] items, 30 of which are Type.op_Equality or Type.op_Inequality. The other two are CredentialCache.get_DefaultCredentials() and MemoryMappedFile.CreateOrOpen().
But what got my attention was, at the bottom of the report, there are two entries for GetWindowsSocksProxy, which turns into SingleServerConnection.InternetQueryOption, and the P/Invoke library is wininet.dll. Could this be related?
So, is there anything I can do? E.g. can I copy that DLL from a windows machine to my linux machine? If so, where do I put it?
P.S. I wondered about connectivity issues. So I made a quick test Mono using WebClient, which worked fine. But one interesting difference is the non-working script loads "/usr/lib/mono/gac/Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll [External]" at the point where it first needs to connect to something. But my WebClient never did that.

How to Record an RTMP Stream?

I need to record an RTMP stream (video) from a remote server.
I know the FluorineFX solution but it includes a flash slave that does publish to local host.
Because the DLL will run on a production server I need this solution to be Pure c#
Do you know how can I do it?
I don't actually need code samples I just need a pointer to an open source solution that I can reconfigure, refactor and publish.
again, the solution needs to be pure c# with no extra Flash or anything else.
preferably open source but a symbolic fee is also OK.
I just stumbled upon this library and looks as if they have the details covered.
http://www.broccoliproducts.com/softnotebook/rtmpclient/rtmpclient.php

Categories