473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 33764
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.