Python Forum
Serial connection connection issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Serial connection connection issue
#11
All look ok.
So next step.
C:\>pip install pyserial
Collecting pyserial
  Using cached pyserial-3.5-py2.py3-none-any.whl (90 kB)
Installing collected packages: pyserial
Successfully installed pyserial-3.5

C:\>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>>
>>> serial.__version__
'3.5'
>>> exit()

C:\>
If this fails look if you have name a file serial.py rename or delete it.
Reply
#12
Hi, yes it has two versions.

How to delete the previous version.

O:\>py -0
Installed Pythons found by py Launcher for Windows
 -3.9-64 *
 -3.8-64
Reply
#13
Dos it work now?
You can uninstall the normal way,it use the right version -3.9-64 * so that other version is there dos nothing.

If i do it.
C:\>py -0
Installed Pythons found by py Launcher for Windows
 -3.9-64 *
 -3.8-64
 -3.7-32
 -3.6-32
 -3.5-32
 -3.4-32
 -2.7-32 
Reply
#14
I just have installed a fresh python on another computer. Now at least I am able to run this code but the problem is that I am not able to receive the line from Microcontroller. I know which line Microcontroller should send when I send the character S but it is not coming.

import serial
ser = serial.Serial("COM7", 9600)
  
# Send character 'S' to start the program
ser.write(bytearray('S','ascii'))
  
# Read line   
while True:
 bs = ser.readline()
 print(bs)
Reply
#15
Now is more like trying different setting like port values.
Do print(ser) you should setting like in image under.
Cross Platform serial communication using Python (PySerial)
[Image: thonny-python-pyserial-comm.jpg]
Search for your type of Microcontroller and Python.
Reply
#16
Do you know for sure that the response includes a newline character (\n)? readline() will wait until it receives one.

The pyserial documentation also warns against using readline() without a timeout. You should configure your connection to have a read timeout and catch the exception that occurs.

https://pyserial.readthedocs.io/en/lates...intro.html

If your device does not terminate lines with a newline I recommend using read_until() instead of readline(). If your device response does not use a termination character use read(number_of_bytes). You should still set a timeout and catch the exception.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I don't know what is wrong (Python and SQL connection) shereen 2 152 11 hours ago
Last Post: menator01
  No Internet connection when running a Python script basil_555 8 443 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Connection LTspice-Python with PyLTSpice bartel90 0 281 Feb-05-2024, 11:46 AM
Last Post: bartel90
  Virtual Env changing mysql connection string in python Fredesetes 0 325 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  Database connection problems [login, PyQt5, PySql] gradlon93 5 620 Dec-15-2023, 05:08 PM
Last Post: deanhystad
  connection python and SQL dawid294 4 585 Dec-12-2023, 08:22 AM
Last Post: Pedroski55
  Input network device connection info from data file edroche3rd 6 913 Oct-12-2023, 02:18 AM
Last Post: edroche3rd
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 3,323 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 679 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Issues with "connection timed out" duckredbeard 0 1,414 Dec-31-2022, 10:46 PM
Last Post: duckredbeard

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020