deathwish88 / modbus-tk

Automatically exported from code.google.com/p/modbus-tk
Other
0 stars 0 forks source link

server error: could not open port COM1: [Error 5] Access is denied. #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When running example rtuslave_example.py get the following error

server error: could not open port COM1: [Error 5] Access is denied.

rtumaster_example.py seems to open serial port ok - have no modbus device
so get time out...

C:\Temp\_py\modbus-tk-0.3.0\examples>python.exe rtumaster_example.py
2009-11-09 09:45:38,700 INFO    rtumaster_example.<module>      MainThread
connected
2009-11-09 09:45:38,700 DEBUG   modbus.execute  MainThread      ->
1-3-0-100-0-3
-68-20
2009-11-09 09:45:43,730 DEBUG   modbus.execute  MainThread      <-
Traceback (most recent call last):
  File "rtumaster_example.py", line 32, in <module>
    logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 100, 3))
  File "build\bdist.win32\egg\modbus_tk\utils.py", line 28, in new
modbus_tk.modbus.ModbusInvalidResponseError: Response length is invalid 0

using:
modbus-tk-0.3.0
python26
windows xp
new to python

Thank you
Regards
Michael

Original issue reported on code.google.com by michael....@gmail.com on 9 Nov 2009 at 9:49

GoogleCodeExporter commented 8 years ago
Hello,
Can you please provide more information? Can you make sure that COM1 is free 
(try to
open it with Hyperterminal before running the slave)
Thanks

Original comment by luc.jean@gmail.com on 30 Nov 2009 at 5:10

GoogleCodeExporter commented 8 years ago
Hello

Yes COM1 is free and does work.
COM1 on PC
I also have other COM ports via USB/Serial devices and these show the same issue
Thanks

Original comment by michael....@gmail.com on 30 Nov 2009 at 7:43

GoogleCodeExporter commented 8 years ago
Can you try the following codes in a python console and see if you have the same
problems 

import serial
s = serial.Serial(port="COM1", baudrate=9600)
s.close()
s = serial.Serial(port=0, baudrate=9600)
s.close()
s = serial.Serial(port=0)
s.close()

Original comment by luc.jean@gmail.com on 1 Dec 2009 at 5:06

GoogleCodeExporter commented 8 years ago
Hello

Created test code (added print "Test" lines) - runs ok

Command Prompt dump:

C:\Temp\_py\modbus-tk-0.3.1\examples>python.exe mk_serialtest.py
Test 1
Test 2
Test 3

Running rtumaster_example.py (with port=0) gives the following:

C:\Temp\_py\modbus-tk-0.3.1\examples>python.exe rtumaster_example.py
2009-12-02 13:06:38,644 INFO    rtumaster_example.<module>      MainThread
connected
2009-12-02 13:06:38,644 DEBUG   modbus.execute  MainThread      -> 1-3-0-100-0-3
-68-20
2009-12-02 13:06:43,660 DEBUG   modbus.execute  MainThread      <-
Traceback (most recent call last):
  File "rtumaster_example.py", line 32, in <module>
    logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 100, 3))
  File "build\bdist.win32\egg\modbus_tk\utils.py", line 28, in new
modbus_tk.modbus.ModbusInvalidResponseError: Response length is invalid 0

Running rtuslave_example.py (as supplied) gives the following:

C:\Temp\_py\modbus-tk-0.3.1\examples>python.exe rtuslave_example.py
running...
enter 'quit' for closing the server
server error: could not open port COM1: [Error 5] Access is denied.
quit
bye-bye

C:\Temp\_py\modbus-tk-0.3.1\examples>

Maybe slave is running ok?

Thanks

Original comment by michael....@gmail.com on 2 Dec 2009 at 1:13

GoogleCodeExporter commented 8 years ago
I didn't succeed to simulate the problem but I am using virtual COM ports 
(com0com)
so it may be a difference. 
Do you see the "Access denied" at the very beginning?

Can you try to open the serial port in rtu_slave with serial.Serial(port=0,
baudrate=9600, bytesize=8, parity='N', stopbits=1, xonxoff=0)

I 've also committed a new version with more print logs (only modbus_rtu.py has 
been
modified) can you try to get it and send me what is printed for both Master and 
Slave?

Best

Original comment by luc.jean@gmail.com on 3 Dec 2009 at 6:17

GoogleCodeExporter commented 8 years ago
Hello

Yes - Access Denied come up at start

Copied file from svn browser.
results are the same see below: (changed Serial()) also)

C:\Temp\_py\modbus-tk-0.3.1\examples>python.exe rtuslave_example.py
running...
enter 'quit' for closing the server
server error: could not open port COM1: [Error 5] Access is denied.
quit
bye-bye

C:\Temp\_py\modbus-tk-0.3.1\examples>python.exe rtumaster_example.py
2009-12-03 19:56:40,148 INFO    rtumaster_example.<module>      MainThread
connected
2009-12-03 19:56:40,148 DEBUG   modbus.execute  MainThread      -> 1-3-0-100-0-3
-68-20
2009-12-03 19:56:45,148 DEBUG   modbus.execute  MainThread      <-
Traceback (most recent call last):
  File "rtumaster_example.py", line 32, in <module>
    logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 100, 3))
  File "build\bdist.win32\egg\modbus_tk\utils.py", line 28, in new
modbus_tk.modbus.ModbusInvalidResponseError: Response length is invalid 0

Both programs are setup for COM1, there is nothing connected to COM1

Thanks

Original comment by michael....@gmail.com on 3 Dec 2009 at 8:01

GoogleCodeExporter commented 8 years ago
Hello Michael,

I think that you didn't reinstall teh new version. You must make a setup.py 
install
in order to see the new modbus_rtu taken into account. Then you'll see a new 
line
printed on the console which gives the name of the port and the status.

"Both programs are setup for COM1, there is nothing connected to COM1". One 
must be
on COM1 and the other on COM2. The 2 serial ports must be connected with a 
cross-over
RS232 cable. An alternative to the cross-over cable is using com0com.
make sure that both programs are NOT on the same port. If so, it is the cause 
of the
"Access Denied"

I hope it helps

Original comment by luc.jean@gmail.com on 3 Dec 2009 at 8:23

GoogleCodeExporter commented 8 years ago
Hello

I run each program on its own. (The sequecence shown in the command line dumb 
is what
I try). 

In the "C:\Temp\_py\modbus-tk-0.3.1\" folder I now have run setup.py install
Do I need to do something else ?
Will go get com0com and try that
Orginally looking for a modbus slave via COM1 (have master device/non pc)

Thanks

Original comment by michael....@gmail.com on 4 Dec 2009 at 10:05

GoogleCodeExporter commented 8 years ago
Any news on this problem?

Original comment by luc.jean@gmail.com on 5 Jan 2010 at 6:22

GoogleCodeExporter commented 8 years ago
No news on this issue. I guess that it was a bad usage.

Original comment by luc.jean@gmail.com on 11 May 2010 at 9:49

GoogleCodeExporter commented 8 years ago
I have the same issue, with the same symptoms as above.  Hardware is a Moxa
UPort1250, which works OK with Hyperterminal, RealTerm, PuTTY and same result 
with
RTU master example.

Would you like me to run any other tests or the instrumented/debug version you
mention above, if so how can I get it?

Original comment by orr.syst...@gmail.com on 21 May 2010 at 3:46

GoogleCodeExporter commented 8 years ago
Also tested with built in port COM1 with same results, so not specific to Moxa.

Opening the port with serial.Serial("COM2") works fine and can stream data out, 
so
guess it's related to the way rtuslave_example.py opens it.

Original comment by orr.syst...@gmail.com on 21 May 2010 at 3:49

GoogleCodeExporter commented 8 years ago
Modified RtuServer as attached to check for open port before opening.  This has
stopped the Access Denied message, so is hopefully the source of the problem?

May com0com lets you reopen already-opened ports, if you didn't see it when 
testing
previously?

Do you know of other MODBUS tools which will work over com0com?  I have been 
trying
modpoll.exe and QModbus but both seem to fail to recognise com0com.

Original comment by orr.syst...@gmail.com on 21 May 2010 at 4:27

Attachments:

GoogleCodeExporter commented 8 years ago
Hello,
Thanks for the fix. I think that it is the right thing to do.
I'll look in detail and try to simulate the pb with and without. but I guess 
that
your fix is Ok

I 've succeed to use ModbusDoctor with com0com. I think that you must create a 
pair
COMx and COMy manually.

Original comment by luc.jean@gmail.com on 21 May 2010 at 8:01

GoogleCodeExporter commented 8 years ago
I am looking more in details to your fix. Maybe I misunderstood but you 
mentionned a
problem with the RTU master and fixed in the RTU slave!!

Can you please clarify?

Best

Original comment by luc.jean@gmail.com on 21 May 2010 at 8:16

GoogleCodeExporter commented 8 years ago
Fault was noted in RTU slave example, fix was in RTU server, which is part of 
RTU
slave- lines 26-28 of rtuslave_example.py are:

if __name__ == "__main__":
    #Create the server
    server = modbus_rtu.RtuServer(serial.Serial(0))

Change was made in RtuServer within modbus_rtu.py

Hope that is clearer, thanks for the prompt response.

Original comment by orr.syst...@gmail.com on 24 May 2010 at 8:07

GoogleCodeExporter commented 8 years ago
Ok, I understand better. 

Your fix is valid but I think is different from the original problem. 

The 'access denied' may be a pure pyserial issue because modbus_tk doesn't open 
the
port itself in most cases. He takes and use a valid serial.Serial object. 

I've experienced a similar problem caused by the debug server of bottle. It can 
try
to open the port twice and cause the error.

I've added some test cases to make sure that the port can be reopened. see rev 
110.

I hope it helps

Original comment by luc.jean@gmail.com on 26 May 2010 at 3:06