You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 14th, 2017, 09:52 AM   #1
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 9
Help!!! convert code javascript to python

Hi all ;
if someone here can help me to convert this code to python

code:

public static libnodave.daveOSserialType fds;
public static libnodave.daveInterface di;
public static libnodave.daveConnection dc;
public static int res;
public static byte plcValue;
public static int memoryRes;
public static byte[] memoryBuffer = new byte[16];

public static void connectTo()
{
//fds.rfd = libnodave.openSocket(0, "192.168.X.X");
fds.rfd = libnodave.openSocket(102, "192.168.X.X");

fds.wfd = fds.rfd;
di = new libnodave.daveInterface(fds, "IF1", 0, libnodave.daveProtoISOTCP, libnodave.daveSpeed187k);
res = di.initAdapter();
dc = new libnodave.daveConnection(di, 0, 0, 3);
res = dc.connectPLC();
if (res==-1)
{
System.Windows.Forms.MessageBox.Show("Erreur de connexion");
}
else
{
//memoryRes = dc.readBytes(libnodave.daveFlags, 0, 0, 1, memoryBuffer);
memoryRes = dc.readBytes(libnodave.daveFlags, 172, 0, 1, memoryBuffer);
plcValue = memoryBuffer[0];
}

dc.disconnectPLC();
di.disconnectAdapter();
libnodave.closePort(fds.rfd);
  Reply With Quote
Old November 14th, 2017, 10:07 AM   #2
azetou
Member
Algeria

azetou is offline
 
Join Date: Mar 2010
Location: Algeria
Posts: 9
Hi,

I suggest that you try in here https://python.developpez.com/ it is a very good programming community.

good luck.
  Reply With Quote
Old November 14th, 2017, 10:08 AM   #3
gclshortt
Member
Canada

gclshortt is offline
 
gclshortt's Avatar
 
Join Date: Dec 2014
Location: Cobourg
Posts: 2,128
Use a online converter for this:
https://github.com/PiotrDabkowski/Js2Py

http://piter.io/projects/js2py

Regards,
__________________
Garry
http://www.accautomation.ca
Connect with us on Facebook: facebook.com/accautomation/
  Reply With Quote
Old November 14th, 2017, 10:24 AM   #4
mts5096
Member
United States

mts5096 is offline
 
Join Date: May 2013
Location: Dallastown, PA
Posts: 12
That's not Javascript, it looks more like Java. But the System.Windows.Forms call means it's probably C#.

What are you actually trying to do?
  Reply With Quote
Old November 14th, 2017, 10:33 AM   #5
BryanG
Member
United Kingdom

BryanG is offline
 
Join Date: Feb 2005
Location: Manchester
Posts: 1,130
According to his other post he is trying to get Python to work with Libnodave. Libnodave is a library that allows you to read/write data from/to a lot of Siemens PLCs.

Never tried it but here is a Python wrapper for Libnodave:
https://github.com/netdata/python-libnodave

and another:
https://pastebin.com/p6q0te6R
  Reply With Quote
Old November 14th, 2017, 10:50 AM   #6
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 9
Quote:
Originally Posted by mts5096 View Post
That's not Javascript, it looks more like Java. But the System.Windows.Forms call means it's probably C#.

What are you actually trying to do?
trying to get Python to work with Libnodave. Libnodave is a library that allows you to read/write data from/to a lot of Siemens PLCs
  Reply With Quote
Old November 14th, 2017, 10:51 AM   #7
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 9
Quote:
Originally Posted by BryanG View Post
According to his other post he is trying to get Python to work with Libnodave. Libnodave is a library that allows you to read/write data from/to a lot of Siemens PLCs.

Never tried it but here is a Python wrapper for Libnodave:
https://github.com/netdata/python-libnodave

and another:
https://pastebin.com/p6q0te6R
Exactly man wanna trying to do communication python with PLC
  Reply With Quote
Old November 14th, 2017, 10:55 AM   #8
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 9
Quote:
Originally Posted by gclshortt View Post
Thank u
  Reply With Quote
Old November 14th, 2017, 11:02 AM   #9
babido10
Member
Morocco

babido10 is offline
 
Join Date: Nov 2017
Location: rabat
Posts: 9
Quote:
Originally Posted by gclshortt View Post
Quote:
Originally Posted by azetou View Post
Hi,

I suggest that you try in here https://python.developpez.com/ it is a very good programming community.

good luck.
Thank u
  Reply With Quote
Old November 14th, 2017, 04:15 PM   #10
damica1
Member
United States

damica1 is offline
 
Join Date: Aug 2015
Location: Illinois
Posts: 258
I know nothing about Siemen's Plc's. But do they have a MQTT Driver? Open Automation does I know.

My point is Python has some very good examples of subscribing to MQTT Brokers and doing just about anything you want with the data.
__________________
David M. Camp
Automation Engineer
Marshall Electric / www.mei-tech.com

PLEASE READ: https://www.prlog.org/12642091-marsh...-industry.html
  Reply With Quote
Old November 14th, 2017, 05:31 PM   #11
boneless
Lifetime Supporting Member + Moderator
United States

boneless is offline
 
Join Date: Feb 2008
Location: OKC
Posts: 1,298
Quote:
Originally Posted by damica1 View Post
I know nothing about Siemen's Plc's. But do they have a MQTT Driver? Open Automation does I know.

My point is Python has some very good examples of subscribing to MQTT Brokers and doing just about anything you want with the data.
You made me google it... https://github.com/RoanBrand/MQTT-Siemens-S7-300

I guess anything is possible if you create the correct program . Never even thought about doing this with Siemens.. I use it all around the house for sensor nodes and my sprinkler system (NodeMCU & Arduino).

Now I know what my next project is going to be . Thanks
  Reply With Quote
Old November 15th, 2017, 03:41 AM   #12
BryanG
Member
United Kingdom

BryanG is offline
 
Join Date: Feb 2005
Location: Manchester
Posts: 1,130
The bit that didn't come across from his other post is that he is using a USB connected MPI cable. I think I would split the problem in to two parts, first work in libnodave to make sure that the USB connected MPI cable connection can work with libnodave. Then try to get libnodave to work with Python. There are some simple test MPI programs in the libnodave Dot.NET folders that I converted to get working with PPI to an S7-200. If you search here on plctalk.net for libnodave you will find at least one working program that uses libnodave.

Just found this note in the libnodave usb2mpi-Linux-2.6 folder:
Quote:
siemens-mpi.ko is a module that allows to use the USB to MPI adapter 6ES7-972-0CB20-0AX0
from Siemens under Linux. It was written for kernel 2.6 and tested under 2.6.13.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Been asked to review some code, looking for a sanity check with pump/valve control defcon.klaxon LIVE PLC Questions And Answers 7 November 6th, 2016 06:39 PM
Bar code reader and PLC dayanyan LIVE PLC Questions And Answers 8 December 27th, 2010 11:11 PM
S5 to s7 conversion, but the code is locked!!! mo_mesbah LIVE PLC Questions And Answers 43 August 7th, 2010 02:56 PM
How To Convert Leader To Hex Code (Please help..) genhits LIVE PLC Questions And Answers 5 July 3rd, 2002 08:00 AM
How to simulate a FOR..NEXT loop? New2PLCs LIVE PLC Questions And Answers 26 May 9th, 2002 12:36 PM


All times are GMT -5. The time now is 11:54 AM.


.