Urgent:Serial Port Read/Write
Hi all,I'm new to python and facing issue using serial in python.I'm facing the below error ser.write(port,command)NameError: global name 'ser' is not defined Please find the attached script and let me know whats wrong in my script and also how can i read data from serial port for the same script. Best Regards,Chandan. import time import os import serial import glob ER_Address = [[0x0A,0x01,0x08,0x99,0xBB,0xBB,0xBB,0xBB,0xBB,0xBB,0xBB]] """ Function Name: RunSequence Function Description: - A RunSequence function has Multiple calls to the RunSuite function, each call is a single testcase consisting of all the parameters required by the RunTesSuite. - """ def WriteSerialData(command): ser.write(port,command) def SendPacket(Packet): str = chr(len(Packet)) + Packet #Concatenation of Packet with the PacketLength print str WriteSerialData(str) def CreateFrame(Edata): evt = chr(0x12) evt = evt + chr(Edata[0]) for i in range (1, len(Edata)): evt = evt + chr(Edata[i]) return evt def SetRequest(data): print data new = [] new = sum(data, []) Addr = CreateFrame(new) SendPacket(Addr) print "SendPacket Done" ReadPacket() def OpenPort(COMPort,BAUDRATE): """ This function reads the serial port and writes it. """ comport=COMPort BaudRate=BAUDRATE try: ser = serial.Serial( port=comport, baudrate=BaudRate, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=10, xonxoff=0, rtscts=0, dsrdtr=0 ) if ser.isOpen(): print "Port Opened" ser.write("Chandan") string1 = ser.read(8) print string1 return ser else: print "Port CLosed" ser.close() return 3 except serial.serialutil.SerialException: print "Exception" ser.close() if __name__ == "__main__": CurrDir=os.getcwd() files = glob.glob('./*pyc') for f in files: os.remove(f) OpenPort(26,9600) SetRequest(ER_Address) #SysAPI.SetRequest('ER',ER_Address) print "Test Scripts Execution complete" -- http://mail.python.org/mailman/listinfo/python-list
Verifying Variable value
Hi , Is there a way to validate variable values while debugging any python code.Run below example in debugging mode and i would like to know the value of c (I know print is an option) with any other option other than printing. In C# or some other tools we can verify each statement and values. Is there way to check each statement in python code like in c#. Ex: def method() a = 20 b =30 c = a + b Best Regards, Chanadn-- http://mail.python.org/mailman/listinfo/python-list
Basic Python Query
Hi all, Please see the below code. class Test(threading.Thread): def StartThread(self): Lock = threading.Lock() self.start() class Test1(threading.Thread): def __init__(self): threading.Thread.__init__ ( self ) self.Lock = threading.Lock() self.start() if __name__ == '__main__': instance = Test() instance.StartThread() instance1= Test1() instance1.start() Please clarify the questions below with respect to above code 1.Difference between def StartThread(self) and def __init__(self): 2 instance = Test() ,when this is called ,the code flow goes inside the threading module ,But instance1= Test1() ,the code flow goes inside the class Test1 When we call the both classes in same way ,How does the flow is different for both. 3. Lets say self is passed explicitly for all the methods Like def method1(self) method2() def method2(self): method3() def method(self) method4() def method4(self) What does self holds in method4 ,Is it self argument from method1? Sorry i'm confused with self argument.Please clarify if its valid question. Best Regards, Chandan-- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Python Query
Hi all, Sorry for not explaining question properly.Here Its not about threading and dont worry about any indentations.Please see below example class Call_Constructor(): def __init__(self): print "In __init__ " class Test_Constructor(Call_Constructor): def method(self): print " In Test_Constructor Class" ConstructInstance = Test_Constructor() When an instace is created for Test_Constructor class ,The code flows starts __init__ in Call_Constructor class.Whys is it like that. class Call_Constructor(): def __init__(self): print "In __init__ " class Test_Constructor(Call_Constructor): def __init__(self): print " In Test_Constructor Class" ConstructInstance = Test_Constructor() But for the above case Code flows starts from Test_Constructor(). Whats is the difference for both cases described above. Best Regards, Chandan. On Thu, 22/8/13, Johannes Bauer wrote: Subject: Re: Basic Python Query To: python-list@python.org Date: Thursday, 22 August, 2013, 12:28 AM On 21.08.2013 11:11, Ulrich Eckhardt wrote: > That said, there is never a need for deriving > from the Thread class, you can also use it to run a function without > that. That way is IMHO clearer because the threading.Thread instance is > not the thread, just like a File instance is not a file. Both just > represent handles for manipulating the actual thing. Huh? That I find most curious. I *always* derive from threading.Thread and really like the way that thread setup works (instanciate Thread handle, call start). Very intuitive, never had the problems with clarity that you mentioned. Could you elaborate on your suggestion? I don't seem to quite get it I'm afraid. Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Python Global variable
Hi all, Please see the below code,in which i'm verifying the global value in python. CHK=10 def test1(): print "Value of CHK in test1",CHK def test2(): CHK=40 print "Value of CHK in test2",CHK test1() def test3(): global CHK test2() test3() When i ran above code ,I'm getting vlaue of CHK as 40 in test2 method and 10 in test1 method Can somone explain me why the value of CHK is different in method test1 and test2. Best Regards, Chandan -- http://mail.python.org/mailman/listinfo/python-list
Python Debugger tool
Hi Is any one aware of free ipython debugger tool.How good is this tool for a beginner to use like ,placing breakpoints,checking variables ,call stack (function flow) etc.I don't like to use python PDB . I have heard about wingware ,pycharm which are licensed versions.Used wingware trail version and felt pretty good tool for beginners. Please let know your views on ipython.Let me know about any python free debugger tools Best Regards, Chandan -- https://mail.python.org/mailman/listinfo/python-list
global variable across modules
Hi , I'm trying to understand using global variable across different modules.Here is what i have tried so far without much success.Please ignore any indentation issue in the below code. Filename:Test1.py Debug_Value = " " import Test2 def globalValmethod(): global Debug_Value Debug_Value =10 Test2.globalValTest() globalValmethod() -Execute the method Filename:Test2.py import Test1 from Test1 import * def globalValTest() print "Golabal Value" Debug_Value In Test2.py file I wanted to print the global value ,Debug_Value as 10.I'm not getting expected result.Please can any one point where exactly i'm doing wrong. Similarly , how can i use global variable inside a class and use the same value of global variable in different class?Is that possible?if Yes please give me some pointers on implementing. Best Regards, Chandan -- https://mail.python.org/mailman/listinfo/python-list
Accessing class attribute
Hi , I'm new to python ,please correct me if there is any thing wrong with the way accessing class attributes. Please see the below code .I have inherited confid in ExpectId class, changed self.print_msg to Hello. Now inherited confid in TestprintmsgID class.Now I wanted to print self.print_msg value (which is changed under ExpectId class) as Hello under TestprintmsgID. I end up with error saying TestprintmsgID has no attribute self.print_msg. Atleast i expect the null to be printed. class confid(): def __init__(self): self.print_msg = "" class ExpectId(confid): def __init__(self): self.print_msg = " Hello" def expectmethod(self): print "self.print_mesg = ",self.print_msg class TestprintmsgID(confid): def __init__(self): "Created Instance" def printmsgmethod(self): print "printmsgmethod print_msg val = ",self.print_msg Here is the Attribute error if __name__ == '__main__': ins1 =ExpectId() ins1.expectmethod() ins2 = TestprintmsgID() ins2.printmsgmethod() Best Regards, Chandan -- https://mail.python.org/mailman/listinfo/python-list
Query on Python Compiled source--Urgent
Hi, I'm working on a python project for protocol testing.I need to provide only python compiled source to our customer. Here are the steps followed to take python compiled from actual source. 1.There are 5 different test suites under the project 2..Run all 5 test suite with python sources. 3.After completion of test suite ,just take .pyc files and copied in to seperate folder. 4.Re run test suite for any issues with the .pyc code.I started seeing one issue when it logs the test results in to excel file. This issue occurs sometimes.50% of chances are there to see this issue Below is the error Traceback (most recent call last): File "D:\users\ScriptTestCode\scriptsCompiledCode\ExecuteScripts.py", line 32, in TestManager.execute_scripts(TEST_BUILD) File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", line 764, in execute_scripts File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", line 772, in _execute_all File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", line 924, in _testsuite_950_band File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", line 377, in exec_test_suite File "D:\users\ScriptTestCode\scripts\ResultReporter.py", line 321, in save_test_results _my_doc.save(StackTestData.TEST_REPORT_PATH) File "C:\Python27\lib\site-packages\pyExcelerator\Workbook.py", line 610, in save doc.save(filename, self.get_biff_data()) File "C:\Python27\lib\site-packages\pyExcelerator\CompoundDoc.py", line 554, in save f = file(filename, 'wb') IOError: [Errno 22] invalid mode ('wb') or filename: '.\\TestResults\\TestReport.xls' Now my question is of there any issue with logging to excel it should happen for the first test suite itself,but it occurs in either 2,3,4 or 5 test suite. Some it runs without any issues. Please let me know do i need to follow any sequence when copying compiled source code and whats exactly going wrong here. Best Regards, Chandan.-- https://mail.python.org/mailman/listinfo/python-list
Re: Query on Python Compiled source--Urgent
Hi, Yes ,its not actual logging module.Using pyexcelerator we are storing just test results to excel file. Each test suite has some 25-100 test cases.We are using unit test from python ,after completion of each test case the test result will be stored in excel file.Below is the sample result that is stored in excel file. S.No TestCaseID TestDescription TestResult 1 Test_case_1 SetTransmitPower Pass 2 Test_case_2 Set Frequency fail Nothing is running parallel. Best Regards, Chandan On Monday, 14 October 2013 1:10 PM, Tim Golden wrote: On 14/10/2013 06:41, chandan kumar wrote: > I'm working on a python project for protocol testing.I need to provide > only python compiled source to our customer. > > Here are the steps followed to take python compiled from actual source. > 1.There are 5 different test suites under the project > 2..Run all 5 test suite with python sources. > 3.After completion of test suite ,just take .pyc files and copied in to > seperate folder. > 4.Re run test suite for any issues with the .pyc code.I started seeing > one issue when it logs the test results in to excel file. > This issue occurs sometimes.50% of chances are there to see this issue > > Below is the error > Traceback (most recent call last): > File "D:\users\ScriptTestCode\scriptsCompiledCode\ExecuteScripts.py", > line 32, in > TestManager.execute_scripts(TEST_BUILD) > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 764, in execute_scripts > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 772, in _execute_all > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 924, in _testsuite_950_band > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 377, in exec_test_suite > File "D:\users\ScriptTestCode\scripts\ResultReporter.py", line 321, in > save_test_results > _my_doc.save(StackTestData.TEST_REPORT_PATH) > File "C:\Python27\lib\site-packages\pyExcelerator\Workbook.py", line > 610, in save > doc.save(filename, self.get_biff_data()) > File "C:\Python27\lib\site-packages\pyExcelerator\CompoundDoc.py", > line 554, in save > f = file(filename, 'wb') > IOError: [Errno 22] invalid mode ('wb') or filename: > '.\\TestResults\\TestReport.xls' > > Now my question is of there any issue with logging to excel it should > happen for the first test suite itself,but it occurs in either 2,3,4 or > 5 test suite. Some it runs without any issues. Well, the fact that it works/fails 50% of the time points to a race condition. You don't say how the test suites / tests are running, but if anything's running in parallel, one test's cleanup could be pulling the file out from under another test's writing results. Without knowing more about your test runner, this is really guess-work. Logging to Excel isn't part of the builtin logging module so you've presumably added that functionality yourself. But PyExcelerator is ultimately just opening a file and writing to it so for this purpose it appears to be equivalent to, say, logging a bunch of stuff into a list and then writing that into a file. TJG -- https://mail.python.org/mailman/listinfo/python-list-- https://mail.python.org/mailman/listinfo/python-list
Re: Query on Python Compiled source--Urgent
Hi, Yes ,its not actual logging module.Using pyexcelerator we are storing just test results to excel file.Each test suite has some 25-100 test cases.We are using unit test from python ,after completion of each test case the test result will be stored in excel file.Below is the sample result that is stored in excel file. S.No TestCaseID TestDescription TestResult 1 Test_case_1 SetTransmitPower Pass 2 Test_case_2 Set Frequency Fail Nothing is running parallel. Best Regards, Chandan On Monday, 14 October 2013 1:10 PM, Tim Golden wrote: On 14/10/2013 06:41, chandan kumar wrote: > I'm working on a python project for protocol testing.I need to provide > only python compiled source to our customer. > > Here are the steps followed to take python compiled from actual source. > 1.There are 5 different test suites under the project > 2..Run all 5 test suite with python sources. > 3.After completion of test suite ,just take .pyc files and copied in to > seperate folder. > 4.Re run test suite for any issues with the .pyc code.I started seeing > one issue when it logs the test results in to excel file. > This issue occurs sometimes.50% of chances are there to see this issue > > Below is the error > Traceback (most recent call last): > File "D:\users\ScriptTestCode\scriptsCompiledCode\ExecuteScripts.py", > line 32, in > TestManager.execute_scripts(TEST_BUILD) > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 764, in execute_scripts > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 772, in _execute_all > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 924, in _testsuite_950_band > File "D:\users\ScriptTestCode\scriptsCompiledCode\TestManager.py", > line 377, in exec_test_suite > File "D:\users\ScriptTestCode\scripts\ResultReporter.py", line 321, in > save_test_results > _my_doc.save(StackTestData.TEST_REPORT_PATH) > File "C:\Python27\lib\site-packages\pyExcelerator\Workbook.py", line > 610, in save > doc.save(filename, self.get_biff_data()) > File "C:\Python27\lib\site-packages\pyExcelerator\CompoundDoc.py", > line 554, in save > f = file(filename, 'wb') > IOError: [Errno 22] invalid mode ('wb') or filename: > '.\\TestResults\\TestReport.xls' > > Now my question is of there any issue with logging to excel it should > happen for the first test suite itself,but it occurs in either 2,3,4 or > 5 test suite. Some it runs without any issues. Well, the fact that it works/fails 50% of the time points to a race condition. You don't say how the test suites / tests are running, but if anything's running in parallel, one test's cleanup could be pulling the file out from under another test's writing results. Without knowing more about your test runner, this is really guess-work. Logging to Excel isn't part of the builtin logging module so you've presumably added that functionality yourself. But PyExcelerator is ultimately just opening a file and writing to it so for this purpose it appears to be equivalent to, say, logging a bunch of stuff into a list and then writing that into a file. TJG -- https://mail.python.org/mailman/listinfo/python-list -Inline Attachment Follows- -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Serial Port Issue
Hi, I'm new to python and trying to learn serial communication using python.In this process i'm facing serial port issues.Please find the attached COMPorttest.py file ,correct me if anything wrong in the code.With my code it's always goes in to exception.I noted down the the COM port number from windows device manager list. Operating system: XPPython Ver: 2.5Pyserial: 2.5 Even i tried from python shell passing below commands import serialser=ser=serial.Serial(port=21,baudrate=9600) I observe below error on python shell File "C:\Python25\lib\serial\serialwin32.py", line 55, in open raise SerialException("could not open port: %s" % msg)SerialException: could not open port: (2, 'CreateFile', 'The system cannot find the file specified.') Thanks in advance. Best Regards,Chandan. import serial def checkPort(): """ This function reads the serial port and writes it. """ try: ser = serial.Serial( port=21, baudrate=9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=10 ) if ser.isOpen(): print "Port Open" else: ser.close() print"port closed" except serial.serialutil.SerialException: print "Failed to open port" checkPort() <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Serial Port Issue
Thanks Phil,You are right .with Port=20 it started working. Regards,Chandan. --- On Mon, 22/4/13, Phil Birkelbach wrote: From: Phil Birkelbach Subject: Re: Serial Port Issue To: python-list@python.org Cc: "chandan kumar" Date: Monday, 22 April, 2013, 8:43 PM Have you tried 'port=20'? The documentation says that the port numbering starts at zero. I don't use Windows so I can't test it for you. You could also try port="COM21" Phil On Apr 22, 2013, at 4:34 AM, chandan kumar wrote: Hi, I'm new to python and trying to learn serial communication using python.In this process i'm facing serial port issues.Please find the attached COMPorttest.py file ,correct me if anything wrong in the code.With my code it's always goes in to exception.I noted down the the COM port number from windows device manager list. Operating system: XPPython Ver: 2.5Pyserial: 2.5 Even i tried from python shell passing below commands import serialser=ser=serial.Serial(port=21,baudrate=9600) I observe below error on python shell File "C:\Python25\lib\serial\serialwin32.py", line 55, in open raise SerialException("could not open port: %s" % msg)SerialException: could not open port: (2, 'CreateFile', 'The system cannot find the file specified.') Thanks in advance. Best Regards,Chandan. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
missing- api-ms-win-crt-runtime-|1-1-0.dll
how I download and install api-ms-win-crt-runtime-|1-1-0.dll when I am downloading by googling it is not installable file. -- *Chandan Kumar Abhimanyu* *+91 9876852058* *Department of Management Studies,* *Indian Institute of Technology (ISM), Dhanbad, * *Jharkhand- 826004, India.* -- https://mail.python.org/mailman/listinfo/python-list