Send File Serial Port Python
Python script to read serial port, export to excel csv. I tried to output it, but it just creates a blank file called test.csv. I would also like it to.
Here at I'm following a Robotics course. In the practical part of the exam we have to write some applications to operating some didactics robots we have (Rhino XR-4 and SCARA Robots). Each robot is connected to a Controller (Rhino Mark-4) which can be connected to a PC to send commands to the Controller in order to let the robots do things.
The PC to Controller connection is a serial RS-232 connection. For the practical parts of the exams we need to write applications which, using the RS-232 communication channels, controls the movements of the robots. The professor here suggested to use Java to implement the applications: unfortunately I found the API comm pretty complex in installation and configuration. I looked for different solutions. Surprisingly I found that with the module is a pretty intelligent solution!
I've been able to install and use them (in both Linux and Windows) without problems at all (while my classmates had lot of problems with java and comm apis.). Just follow any guide on the web to install Python on your system and then follow the installation guide. Using the pySerial apis is pretty simple: just have a look at the to have an idea of the apis it gives you. A simple application I give you here a simple application which should let you understand how python serial apis are easy to use. The application is a simple serial terminal which you can use to send commands (and receive output) to a serial connected device. This is the application code: import time import serial # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='/dev/ttyUSB1', baudrate=9600, parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_TWO, bytesize=serial.SEVENBITS ) ser.open() ser.isOpen() print 'Enter your commands below.
R nInsert 'exit' to leave the application.' After a lot of trying I got this to working #!c: Python27 Python.exe import sys, serial sys.stderr = sys.stdout ser = serial.Serial('COM27', 9600) print 'Content-type:text/html n n' print 'Real Time Temperature' print 'Real Time Temperature:' print ' print '%s'% (ser.readline()) print ' #''% ser.readline() # should be cgi.escape(ser.readline())!
Ser.close() sys.exit(0) But this is refreshing the whole page. I want the latest value in my web page only. Secondly using print '' HTML CODE '' is giving me error 500 in my webpage (internal error) can you say why? I am also working in python 2.6 and i want to send SMS to a mobile while my cell phone i.e. Nokia E-72 is connected to PC via Data Cable. The mobile is connected through the serial port and the code prompts the correct port as well and there is no error in the code but still the message is not being sent.
Please help me. My code is as follows: import serial import time phone = serial.Serial() phone.baudrate = 38400 phone.bytesize = 8 phone.stopbits = 1 phone.xonxoff = 0 phone.rtscts = 0 phone.timeout = 0 phone.port = 4 #try different ports here, if this doesn't work. Phone.parity=serial.PARITY_NONE phone.open() print phone.portstr recipient = '+98' message = 'We did it!'
Try: time.sleep(0.5) phone.write(b'ATZ r') time.sleep(0.5) phone.write(b'AT+CMGF=1 r') time.sleep(0.5) phone.write(b'AT+CMGS=' + recipient.encode() + b' r') time.sleep(0.5) phone.write(message.encode() + b' r') time.sleep(0.5) phone.write(bytes([26])) time.sleep(0.5) phone.readall() # print phone.readall(str) finally: phone.close(). All of my problems with PySerial has to do with the release candidate of pyserial-2.5-rc2.win32.exe, which is supposed to be the recent release.
This file definitely has problem locating the installed python and thus never lets you run it. Apparently, you need to run this or you can't do crap with serial communication. Well, I downloaded previous version of this file - pyserial-py3k-2.5-rc1.win32.exe - and it works.
It must have registered all the files. Now, I can open my serial ports. I am using Python 3.1.1 on Windows XP with Pyserial 2.5. It took me all day.
My Python effort is really for my work. We are currently looking to migrate our system using completely different programming language that we can run on many different platform.