Comments (11)
but my serial port does not break connection
You mean it doesn't exit the for c in ser.readline():
loop?
p.s. please, fix the formatting of the code block in your message
from pystlink.
@desprit yes sir,
i am not sure is it the loop or the python issue as i can see at some serial ports pages and links.
That py-serial no more works with v2.6 and further. i am here using python 3.7
what i am really facing is i am able to send the command from the above mentioned code which is i am sending in bytes format [ ser.write(b'\reeprom\r')] and receive the response on my console but what further i am facing is port stays engaged and script continues to run
what i am trying to achieve is send the command what i am already doing and then get the response from the command that i fired and then the port should break and i should be able to fire the second command to the serial port or by other way i could just make connection once and able to fire two-three commands continuously and get response for the individual commands fired by me and then break the connection from the serial port.
@desprit i am really not able to why i am in this situation . it will be very kind if you can provide some guidance.
from pystlink.
Try to change the write command to this:
ser.write(b'\reeprom\r\n')
And fix the formatting, please. "edit" your message and wrap the whole code block into ```
from pystlink.
hi @desprit
yes, the above mentioned ser.write pattern works fine.
Below is the attached code
import ctypes, sys
import mysql.connector
from xlwt import Workbook
import pyvisa as visa
import serial
import os
import click
import logging
import time
import mysql.connector
import pymysql
if click.confirm('Do you want to flash the self test cli?', default=True):
os.system("st-link_cli -ME")
print("FLASHING THE SELF TEST CLI ON THE BOARD")
#os.system("st-link_cli.exe -P D:/nishant/Self_Test_CLI_Application.hex 0x08000000 ske skpv -V while_programming")
os.system("st-link_cli.exe -P D:/nishant/CLIv1.9_9600BPS-8N1_28-11-2019_fx.hex 0x08000000 ske skpv -V while_programming")
####Device getting reset after flashing#######
os.system("st-link_cli -Rst")
if click.confirm('Do you want to test board?', default=True):
#os.system("st-link_cli -Rst")
print("Mcu is Reseting to give test board results")
logging.basicConfig(filename='D:/nishant/acc20.txt', level=logging.DEBUG)
ser = serial.Serial(
port='COM5', \
baudrate=9600, \
parity=serial.PARITY_NONE, \
stopbits=serial.STOPBITS_ONE, \
bytesize=serial.EIGHTBITS, \
timeout= 1)
print("connected to: " + ser.portstr)
ser.write(b'\r1\r\n')
#ser.write(b'\reeprom\r\n')
#ser.write(b'\r1\n\r')
# this will store the line
seq = []
count = 1
while True:
for c in ser.readline():
seq.append(chr(c)) # convert from ANSII
joined_seq = ''.join(str(v) for v in seq) # Make a string from array
if chr(c) == '\n':
print("Line " + str(count) + ': ' + joined_seq)
seq = []
count += 1
break
ser.close()
hope this looks fine.
from pystlink.
https://pyserial.readthedocs.io/en/latest/shortintro.html#readline
Be careful when using readline(). Do specify a timeout when opening the serial port otherwise it could block forever if no newline character is received. Also note that readlines() only works with a timeout. readlines() depends on having a timeout and interprets that as EOF (end of file). It raises an exception if the port is not opened correctly.
Not sure why timeount didnt work for you.
from pystlink.
i have gone through this and same i explained in my first snippet . As they have mentioned it doesn't work for python versions above 2.6 . They have also mentioned for using io module . do you have idea how to use that.
the above mentioned code is cutting of your code on stack overflow.
@desprit what you suggest me to do in this case. can you give some idea how below can be achieved.
what i am trying to achieve is send the command what i am already doing and then get the response from the command that i fired and then the port should break and i should be able to fire the second command to the serial port or by other way i could just make connection once and able to fire two-three commands continuously and get response for the individual commands fired by me and then break the connection from the serial port.
@desprit it will be great help. if you can support me on this . i have been stuck since a week in this issue.
from pystlink.
What did you mean when you said
yes, the above mentioned ser.write pattern works fine.
It seems like you need two separate scripts. One will read data coming on the serial port and another one that should occasionally write data.
The "reader" is exactly as shown on stackoverflow.
Launch it in a separate window and let it keep running.
Then create a "writer" script that will connect to the serial, write a message and exit.
Then, show me the result.
from pystlink.
@desprit - first of all apologies for the late reply as office hours were over.
it was only a acknowledgement that this way writing ser.write( ) also works fine.
Thanks above mentioned suggestion is also very nice and i can find clues for it easily for doing this way on google but there is also issue regarding one serial port for two script simultaneously.
Also point is tere is need of single script . As we are saving every response in the database for future records of each every arduino connected and we are going to run the script through UI. so it is necessary that script should be single which is running in the background.
Also i am watching despite my using ser.close The port is not getting closed. what could be the possible and same thing is happening with timeout in the script.
If we can catch anything on ser.close or timeout by your help . i think it will be achievable or by any of your suggested way which could serve the purpose.
from pystlink.
@desprit I have made some changes at firmware level.
now current problem is i dont need to fire multiple commands . I will just be sending one particular command and then will gets its output which is working.
The only thing remains stuck is i am not able to close port. can you suggest something on that. ?
@desprit -it will be great help if you me on this?
from pystlink.
You should communicate with your code to understand the source of the problem. Add debug messages on every step of the loop and see where it stuck.
First of all, make sure it exits from the for c in ser.readline():
loop.
When done, make sure to exit while True:
. Right now I don't see anything that would stop the while True:
. It loops forever and thus never gets to ser.close()
.
from pystlink.
thanks for support. i will try this and confirm you on the results.
from pystlink.
Related Issues (20)
- Would it be possible to extend this program to access STM8's? HOT 3
- pystlink as a library HOT 2
- question: nu-link programmer HOT 1
- getting I/O error(13): Permission denied while flashing the new credentials into mcu through python
- STM32FP - direct flashing is reverted HOT 13
- Detecting disconnect between ST-Link and target HOT 1
- stm32l151zDT6 not supported. Check protection error HOT 5
- Reset does not work with ST-LINK/V3
- STM32G0x devices are missed HOT 1
- Issue running flash HOT 1
- Timeout error
- flash erase command can't suport STM32H7 HOT 1
- Support for STM32G0B1RET6
- *** Supply voltage is 0.01V, but minimum for FLASH program or erase is 2.0V *** HOT 2
- Have you supported to configure option bytes? HOT 2
- Wont run HOT 4
- *** ST-Link/V2 is not connected *** HOT 15
- *** USB Error: [Errno 32] Pipe error *** HOT 3
- flash:erase:verify:address:bin will raise *** Parameter error: 16384 *** when writing bin file to address which already contain data HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pystlink.