LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 08-22-2014, 08:56 PM   #1
anchorman
LQ Newbie
 
Registered: Dec 2013
Location: USA
Distribution: UBUNTU 12.04
Posts: 14

Rep: Reputation: Disabled
Ubuntu 12.04 using serial port with python 2.7


Using the Serial Terminal Program, with the same port, I can send data to the micro and it works as expected. But, when attempting to use a Python script and pyserial module, no data is
transmitted to the micro. This verified using a scope on the micro's receive data RS-232 line. Using the
Serial Teminal Program, the micro displays the correct information and also is observed at the receive data line as just mentioned.

I can not figure out what else must be done to allow data to be transmitted using the python script.
The script is based on example(s) from different online searches and the pyserial web site.

I am using Ubuntu 12.04 and python 2.73.



#!/usr/bin/bin/env/ python
import serial
import os

ser = serial.Serial('/dev/ttyUSB0',9600, timeout =1)
ser.open()



print ser.portstr # check which port was really used
#### ser.portstr prints /dev/ttyUSB0 ####
s="1234\n"

#Note: neither ser.write sends data to module.
ser.write("1234\n") # write a string
ser.close() # close port



""" Note: I have a micro based external hardware module that displays numerical data received
at the external device serial port. It test excellent using a serial term program. I would have thought this would be a simple write ?
"""

I tried to use the ICONS in the posting menu but they don't respond .

Last edited by anchorman; 08-24-2014 at 02:19 PM. Reason: attemting to add code tags, didn't work ????
 
Old 08-28-2014, 02:05 PM   #2
ventsyv
Member
 
Registered: Apr 2006
Posts: 57

Rep: Reputation: 3
I don't think you need to call open - the constructor will open the port. Try:

Code:
ser = serial.Serial('/dev/ttyUSB0',9600, timeout =1) 
ser.write("1234\n")
ser.close()
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Serial terminal connected to USB Serial Port on Ubuntu 12.04 809areacode Linux - General 3 07-18-2013 10:06 PM
Is a USBtty (USB serial port) treated the same as tty (normal serial port) in C? spudgunner Programming 1 11-12-2010 01:19 PM
How do I install an old-school serial port printer on Ubuntu 9.04 judoka Linux - Hardware 1 07-22-2009 05:21 PM
Serial port problem on Ubuntu Feisty estratos Linux - Hardware 4 08-03-2007 08:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 02:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration