473,385 Members | 1,396 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,385 software developers and data experts.

How to send CTRL-S & CTRL-X over serial port

Hello -

I'm trying to wite these control characters to the serial port w/o
success.

I've tried sp.Write((Keys.ControlKey & Keys.X).ToString());
sp.Write((Keys.Control & Keys.X).ToString());

char[] temp = { Convert.ToChar(Keys.Control), Convert.ToChar(Keys.X)
};
sp.Write(temp, 0, 2);

and other screwy variations.

Any suggestions how to do this?

Thanks, Tom
Sep 27 '08 #1
3 9334
On Sat, 27 Sep 2008 11:00:54 -0700, Blip <bl**@krumpli.comwrote:
Hello -

I'm trying to wite these control characters to the serial port w/o
success.

I've tried sp.Write((Keys.ControlKey & Keys.X).ToString());
sp.Write((Keys.Control & Keys.X).ToString());
What's "sp"? Is that an instance of the SerialPort class?

The bottom line here is that you are trying to mix the user-input data
structures associated with keyboard input with the ASCII used to represent
that input.

The first non-zero byte values for ASCII are reserved for control input.
By convention, the letters are assigned in sequence, with Control-A being
1, Control-B being 2, etc. Control-S would be 19. You can probably
figure out Control-X on your own. :)

Just send the correct byte value. You aren't going to get anywhere trying
to use values from the Keys enumeration, as that's tied to the keyboard,
not ASCII.

Pete
Sep 27 '08 #2
"Blip" <bl**@krumpli.comwrote in message
news:3a********************************@4ax.com...
I'm trying to wite these control characters to the serial port w/o
success.

I've tried sp.Write((Keys.ControlKey & Keys.X).ToString());
sp.Write((Keys.Control & Keys.X).ToString());

char[] temp = { Convert.ToChar(Keys.Control), Convert.ToChar(Keys.X)
};
sp.Write(temp, 0, 2);

and other screwy variations.

Any suggestions how to do this?

You can use the numeric value of the control character: Ctrl-A is ASCII
1, Ctrl-B is 2, Ctrl-C is 3, and so on.

SerialPort sp = ...;
....
char ctrlS = (char)('S'-'A'+1);
char[] charsToWrite = new char[]{ctrlS};
sp.Write(charsToWrite, 0, 1);
Sep 27 '08 #3
MC
To make the same point Pete did, a little more explicitly:

Serial ports don't transmit keys. They transmit bytes, which are normally
the ASCII representations of characters.

"Keys.ControlKey & Keys.X" has to do with sensing what is going on on a PC
keyboard. But serial ports do not transmit the whole state of the keyboard.
For instance, the F keys and the arrows are entirely outside the ASCII
system.

An ASCII chart will tell you that, for instance, Ctrl-A is 1, Ctrl-B is 2,
'A' is 65, and so on.

Sep 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
0
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
6
by: John J. Hughes II | last post by:
I have a service that needs to send e-mail alerts. I have been attempting to use the System.Net.Mail function from .NET but this seems to require the IIS be installed and running. Since some of...
13
by: Manfred Braun | last post by:
Hi All, I am trying to understand the blocking method socket.Send(). The call blocks as expected, but does this mean, it returnes after the underlying TCP layer got a confirmation, that the send...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
3
by: ultr | last post by:
Hello, I have read that send() may not send whole message and returns the nuber of bytes sent, so that we can handle the rest of the message. Is it true, because i have tested sending even 1MB...
11
by: hazz | last post by:
smtpClient.Send(message) is causing me problems as per specifics in the trace below. Email is sent but not without this error typically upon sending the second email, but sometimes when running...
15
by: cj | last post by:
How can I get a button in VB to send the contents of a text box via email in a manner similar to the "Send To\Mail Recipient" functionality that you can select via right clicking a file in Windows...
4
by: =?Utf-8?B?dHBhcmtzNjk=?= | last post by:
I have a web page that at the click of a button must send a bunch (1000+) emails. Each email is sent individually. I have the code working fine, using Mail Message classes and smtp and all that. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.