-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serial port getting engaged after reading single command in python. #20
Comments
You mean it doesn't exit the p.s. please, fix the formatting of the code block in your message |
@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. 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. |
Try to change the write command to this:
And fix the formatting, please. "edit" your message and wrap the whole code block into ``` |
hi @desprit yes, the above mentioned ser.write pattern works fine. Below is the attached code
hope this looks fine. |
https://pyserial.readthedocs.io/en/latest/shortintro.html#readline
Not sure why timeount didnt work for you. |
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. |
What did you mean when you said
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. Then create a "writer" script that will connect to the serial, write a message and exit. Then, show me the result. |
@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. |
@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. @desprit -it will be great help if you me on this? |
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. |
thanks for support. i will try this and confirm you on the results. |
I am making a connection with python using pyserial with a UART port. As I send the command using serial.write my output is received but my serial port does not break connection. As I need to send a second command also to receive the output. Please guide me on this.
I have also used ser.close still I am not able to close the port.
import serial
ser = serial.Serial(
port='COM5',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout= 10)
print("connected to: " + ser.portstr)
ser.write(b'\reeprom\r')
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
ser.close()
Can you please guide what is going wrong. I am expecting that I should get my output of the fired command to UART and then code should exit rather than continue running. Also I wanted to know if this works can I again make connection and fire the second command to UART. Please help me on this.
@desprit - I have take this cutting of code from your stack overflow contribution. Can you help me guide what is wrong at my end that i am not able to release port.
The text was updated successfully, but these errors were encountered: