By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

How to write ctrl-z to a serial port

P: 2
Dear All,

I am new to python. I need to write ctrl-z to a serial port to signal the end of input. This is required by the message format. I use:
Expand|Select|Wrap|Line Numbers
  1. ser = serial.Serial(port=COMPORT,baudrate=BAUDRATE,bytesize=8,parity='N',stopbits=1,timeout=3,xonxoff=0,rtscts=0,)
  2. ser.open()
  3. ser.write("testing\x1A")
But the ctrl-z (ascii 26) doesn't seem to be written to the serial port. The firmware still waiting for message input because it can't see the ctrl-z. Is there something special in python to handle ctrl-z?

Thank you for your help!
Aug 21 '07 #1
Share this Question
Share on Google+
3 Replies


bartonc
Expert 5K+
P: 6,596
Dear All,

I am new to python. I need to write ctrl-z to a serial port to signal the end of input. This is required by the message format. I use:
Expand|Select|Wrap|Line Numbers
  1. ser = serial.Serial(port=COMPORT,baudrate=BAUDRATE,bytesize=8,parity='N',stopbits=1,timeout=3,xonxoff=0,rtscts=0,)
  2. ser.open()
  3. ser.write("testing\x1A")
But the ctrl-z (ascii 26) doesn't seem to be written to the serial port. The firmware still waiting for message input because it can't see the ctrl-z. Is there something special in python to handle ctrl-z?

Thank you for your help!
Since you have the ascii code in Python correctly represented, I must ask:
So, can you confirm that the characters preceding the ctrl-z actually arrive?
Can you cause characters to be sent from the device (with (say) a reset), which you could then try to ser.read()?
On your platform (which is info that you should give) is COMPORT defined well enough to actually point to a com port device?
Aug 21 '07 #2

P: 2
Since you have the ascii code in Python correctly represented, I must ask:
So, can you confirm that the characters preceding the ctrl-z actually arrive?
Can you cause characters to be sent from the device (with (say) a reset), which you could then try to ser.read()?
On your platform (which is info that you should give) is COMPORT defined well enough to actually point to a com port device?
Barton,
Thank you very much for looking into it! I figured it out it needs to add '\r\n' at the end to flush the ctrl-z into the port. I am not sure if this is the real cause. But it works by doing:
ser.write("testing\x1A\r\n")
Aug 21 '07 #3

P: 3
Try this.

Chr(26) is the "CTRL-Z" code of ASCII/ISO646 keyboards

I use this in my program
MainForm.UserPort1.WriteToComPort(Chr(26))

Hope this helps.
Nov 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.