471,325 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

How to write ctrl-z to a serial port

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
3 32269
bartonc
6,596 Expert 4TB
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
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
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.

Similar topics

10 posts views Thread by chirs | last post: by
13 posts views Thread by Kai Grossjohann | last post: by
3 posts views Thread by Greg | last post: by
6 posts views Thread by Paul Gorodyansky | last post: by
3 posts views Thread by Glen Hong | last post: by
2 posts views Thread by s99999999s2003 | last post: by
14 posts views Thread by cage | last post: by
11 posts views Thread by Bookham Measures | last post: by
12 posts views Thread by arnuld | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.