472,958 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 33506
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

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

Similar topics

10
by: chirs | last post by:
I have a code to disable ctrl-v (paste) on the 2nd box. The problem is that when I type ctrl-v, the text shows, then disappear after I release ctrl-v. How can I make it not to show in the box. In...
13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
3
by: Greg | last post by:
I want to be able to capture the user pressing Ctrl+S. I know that the IE browser has a key binding for Ctrl+S but is there any way that I can be notified of this key press anyway. I have found...
6
by: Paul Gorodyansky | last post by:
Hi, Question about event.altKey event.ctrlKey event.shiftKey If I need to catch when a user does say Ctrl+Alt+G - somehow event.altKey is not working, i.e.:
3
by: Glen Hong | last post by:
I have set up a hotkey using RegisterHotKey API function for Ctrl-Tab. Firstly, I can rap this when Ctrl-Tab is pressed however if I want to add an addition hotkey how can I distinguish between...
2
by: s99999999s2003 | last post by:
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some...
14
by: cage | last post by:
hello can i write a eof to a file descriptor without closing it? like: fd.write(EOF) or something grts, ruben
11
by: Bookham Measures | last post by:
Hello As above, my Ctrl + Spacebar for intellisense is not working in VI 6.0. I have checked keyboard assignments and Ctrl + Space is listed for Edit -> CompleteWord. I added Ctrl + Shift +...
21
by: Zytan | last post by:
Instead of Ctrl+Y redoing what's stored in 'future history', it REPLACES that information (which will then be forever lost) with a new command: delete current line. This shortcut is so ridiculous...
12
by: arnuld | last post by:
WANTED: Even if I do Ctrl-C in the middle of fgets(), fwrite() should write the previously entered data to a file (except if I hit the file-size limit) PROBLEM: If I do a Ctrl-C in the...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.