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

Reading from serial port & writing to X console

lec
Hi,

I'm trying to write a program to read from the serial port & write
whatever that is read to the X console (/dev/tty7).
For X to recognize the characters sent, I believe you have to send
"scancodes".

Any suggestion is appreciated.

This is my attempt which doesn't work:

#!/usr/bin/python

scancodes =
[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0x1c,0x9c,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0x39,0xb9,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,
0x0b, 0x8b, 0],[0, 2, 130, 0],[0, 3, 131, 0],[0, 4, 132, 0],[0, 5, 133,
0],[0, 6, 134, 0],[0, 7, 135, 0],[0, 8, 136, 0],[0, 9, 137, 0],[0, 10,
138,
0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0x2A,0x1E,0x9E,0xAA],[0x2A,0x30,0xb0,0xAA],[0x2A,0x2e,0xae,0xAA],[0x2A,0x20,0xa0,0xAA],[0x2A,0x12,0x92,0xAA],[0x2A,0x21,0xa1,0xAA],[0x2A,0x22,0xa2,0xAA],[0x2A,0x23,0xa3,0xAA],[0x2A,0x17,0x97,0xAA],[0x2A,0x24,0xa4,0xAA],[0x2A,0x25,0xa5,0xAA],[0x2A,0x26,0xa6,0xAA],[0x2A,0x32,0xb2,0xAA],[0x2A,0x31,0xb1,0xAA],[0x2A,0x18,0x98,0xAA],[0x2A,0x19,0x99,0xAA],[0x2A,0x10,0x90,0xAA],[0x2A,0x13,0x93,0xAA],[0x2A,0x1f,0x9f,0xAA],[0x2A,0x14,0x94,0xAA],[0x2A,0x16,0x96,0xAA],[0x2A,0x2f,0xaf,0xAA],[0x2A,0x11,0x91,0xAA],[0x2A,0x2d,0xad,0xAA],[0x2A,0x15,0x95,0xAA],[0x2A,0x2c,0xac,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0x1E,0x9E,0],[0,0x30,0xb0,0],[0,0x2e,0xae,0],[0,0x20,0xa0,0],[0,0x12,0x92,0],[0,0x21,0xa1,0],[0,0x22,0xa2,0],[0,0x23,0xa3,0],[0,0x17,0x97,0],[0,0x24,0xa4,0],[0,0x25,0xa5,0],[0,0x26,0xa6,0],[0,0x32,0xb2,0],[0,0x31,0xb1,0],[0,0x18,0x98,0],[0,0x19,0x99,0],[0,0x10,0x90,0],[0,0x13,0x93,0],[0,0x1f,0x9f,0],[0,0x14,0x94,0],[0,0x16,0x96,0],[0,0x2f,0xaf,0],[0,0x11,0x91,0],[0,0x2d,0xad,0],[0,0x15,0x95,0],[0,0x2c,0xac,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
def readserial(dev='/dev/ttyS0'):
p = open(dev)
line = ''
line = char = ''
while char <> chr(13):
char = p.read(1)
if char <> '':
line = line + char
print line

# write to /dev/tty7 which is console for X
tty7 = open('/dev/tty7', 'w')
#import FCNTL, fcntl
#import termios, TERMIOS

for ch in line:
for ch1 in scancodes[ ord(ch)]:
if ch1:
tty7.write("%c"%chr(ch1))

tty7.close()
p.close()

if __name__ == '__main__':

while 1:
readserial()


Jul 18 '05 #1
1 3552
In article <ma**********************************@python.org >, lec wrote:
I'm trying to write a program to read from the serial port &
write whatever that is read to the X console (/dev/tty7). For X
to recognize the characters sent, I believe you have to send
"scancodes".


No. You can simply read /dev/ttyS0 and write to /dev/tty7:

In shell:

$ (stty 9600 -paren -ixon -ixoff; cat) </dev/ttyS0 >/dev/tty7

Change the stty parameters as desired.

In Python, just open /dev/ttyS0, /dev/tty7. Read from one and
write to the other.

There are a couple different serial port modules that wrap up
serial ports into objects to hide the nasty termios stuff.

Google the group for terms like PosixSeral PySerial.

--
Grant Edwards grante Yow! Why was I BORN?
at
visi.com
Jul 18 '05 #2

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

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
0
by: per.bergstrom | last post by:
To whom it may concern, The serial port server 'cnhd38' has been terminated (on who's initiative, I don't know). It affects the users of the (at least) following nodes: cnhd36, cnhd44, cnhd45,...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
13
by: Al the programmer | last post by:
I need to access the serial ports on my webserver from an asp.net page. I have no problem accessing the serial ports from a windows form application, but the code doesn't work in asp.net. I have...
8
by: Vivek Menon | last post by:
Hi, I am using a C program to write/read from a serial port. The writing part is working perfectly fine. However, I am not able to read the values correctly and display them. To debug this issue I...
2
by: Nasif | last post by:
Currently I am writing a program which sends and receives messages through serial port to a device. I am using C# and Microsoft Visual studio 2005 for windows program. But my problem is when i try...
9
by: Hal Vaughan | last post by:
I've done a fair amount of Googling for information on reading the serial port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to be an unanswered question, 1 is someone saying,...
6
by: cnixuser | last post by:
Hello, I have a basic application written which is designed to data over a serial cable and then receive a response back. I am not getting any triggers to my data received event. I have tried...
2
by: Tenaious | last post by:
Hi, Sorry about such a ridicules question, but I have no clue what’s going on. I'm Using Visual Studio 08, programming in C++. I have a Serial Port created with: static...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.