PLC CONNECTION HELP NEEDE

255 views
Skip to first unread message

Rushil sevak

unread,
May 10, 2020, 2:29:17 PM5/10/20
to pymodbus
Thank you in Advance.

I am very good in PLC logic & programming, but new to python.

I have mitsubishi make PLC which is GOC35.
want to connect via mosbustcp using python pymodbus library.

i am already test this PLC connection via Tcpip modbus with SCADA.
but now want to connect using python script & pymodbus library.

I started this but not getting any response from PLC & also check ping from PLC in CMD it is working ok.
below is my code.


from pymodbus.client.sync import ModbusTcp lient

client = ModbusTcpClient('192.268.1.11')
client.read_holding_registers(0,3).registers


it gives me 'modbusioexception' & registers in not module.

Please guide me to solve this.

so, please guide me where to start.

Akash Banaulikar

unread,
May 10, 2020, 2:39:49 PM5/10/20
to pymodbus
Hello rushil
You can use
client = ModbusTcpClient(host='192.268.1.11',port=)
register=client.read_holding_registers(address=0,count=1,unit=1)
registerstore=register.registers[0]

In your case you need to provide proper count value and plc unit number and client. read_holding_registers reads multiple registers and stores in a list so use .registers[0]
This will display content of register at position 0.
And in connection string provide proper port number.
You can go to www.nakshautomation.live for more details

Rushil sevak

unread,
May 11, 2020, 1:06:56 AM5/11/20
to pymodbus
Sure Mr. Akash  i will check & get back t you Thank you for your prompt reply.

Rushil sevak

unread,
May 11, 2020, 1:43:34 AM5/11/20
to pymodbus

error_1.png

By doing this i am getting this error also attached screen short here please guide me.


On Monday, 11 May 2020 00:09:49 UTC+5:30, Akash Banaulikar wrote:
error_1.png

Akash Banaulikar

unread,
May 11, 2020, 1:51:50 AM5/11/20
to pymodbus
For pymodbus to read ypur plc tags you must provide address, count, unit of plc.
register=client.read_holding_registers(address=0,count=1,unit=1)
Like this.

Akash Banaulikar

unread,
May 11, 2020, 1:54:51 AM5/11/20
to pymodbus
client = ModbusTcpClient(host='192.268.1.11',port=502)
And put host = which is missing in tour case

Rushil sevak

unread,
May 11, 2020, 2:05:50 AM5/11/20
to pymodbus
Thank you very much Sir,
i got out put which is attached but i want to know something more about address, count & unit.

can you please explain me it in detail ?
Screenshot (1149).png

Akash Banaulikar

unread,
May 11, 2020, 2:16:10 AM5/11/20
to pymodbus
register=client.read_holding_registers(address=0,count=1,unit=1)
address is the modbus address of plc which you want to read.
Count is number of registers you want to read.
For eg. You are reading data from modbus address 0 and count value is 1 then you will get the value of only 0th modbus address and suppose count is 3 then you will get data from modbus address 0,1,2 and it will be stored in a list

For direct PLC supporting Modbus/TCP, set the Unit ID to zero (or
one). The PLC likely ignores it.

Rushil sevak

unread,
May 11, 2020, 5:06:04 AM5/11/20
to pymodbus
Thank you,

now can i connect this script with mysql database?

Akash Banaulikar

unread,
May 11, 2020, 5:07:45 AM5/11/20
to pymodbus
yes you can use sqlserver.
Please visit www.nakshautomation.live
There are tutorials for sending plc data to database via pymodbus

Rushil sevak

unread,
May 11, 2020, 7:15:25 AM5/11/20
to pymodbus
I go to website but unfortunately advertisement not open any tutorial sir.

if possible please give steps overhyere or suggest other link.

Thank you.


Akash Banaulikar

unread,
May 13, 2020, 2:48:08 PM5/13/20
to pymodbus
okay.
You can use sql server database.
conn = pyodbc.connect("Driver={ODBC Driver 11 for SQL Server};"
"Server=LAPTOP-CNL636HF\SQLEXPRESS;"
"Database=pyscada;"
"Trusted_Connection=yes;")
# connection start
cursor = conn.cursor()
now=datetime.now()
formatted_date=now.strftime('%Y-%m-%d %H:%M:%S ')

# to insert data into database
cursor.execute('insert into pytb2(datetime,count) values(?,?)', (formatted_date,regs1) )
conn.commit()
conn.close()
Reg1 stores plc register value
To know which driver server to use to make connection please visit
https://www.nakshautomation.live/pyhmi#top

Rushil sevak

unread,
May 23, 2020, 2:11:44 AM5/23/20
to pymodbus
Ok sir,


i got this from your side, Thank you very much for that,

now i want to get data from the modbus serial communication using python so can you suggest me from where i have to start.


i started but get following errors i also attached pic of that over here please guide me sir,,


Thank you in advance.
Screenshot (2).png
Reply all
Reply to author
Forward
0 new messages