473,325 Members | 2,671 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,325 software developers and data experts.

in over my head ascii

Hello there,
i need to write a script that can transfer info back and forth with a
data server at so-and-so ip.

i have Programming Python, which covers socket programming. So thats
cool. But what i need to know how to do is make a message in ascii that
is what the server is looking for.

for example , to send a request, the first three bytes have to be ascii
"STX"
then there has to be 4 bytes that show the length of the message
then the actual message
then the last three bytes have to be "ENX"

also all int variables must me unsigned long-int (32 bit).

so here is what i need to know,
1 how do i make something in ascii bytes to send off to this server ?
2 how can i make sure something is a 32bit unsigned long int. ?

If the answers i am looking for are pretty straightforward, please let
me know., If they are long and complicated, please point me to some
good documentation .

thanks for all,
sk

Feb 6 '06 #1
12 3153

<ne*****@xit.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
for example , to send a request, the first three bytes have to be ascii
"STX"
then there has to be 4 bytes that show the length of the message
then the actual message
then the last three bytes have to be "ENX"

also all int variables must me unsigned long-int (32 bit).

so here is what i need to know,
1 how do i make something in ascii bytes to send off to this server ?
Python strings are full 8-bit byte strings. Whether you should retrict
bytes to ASCII bytes only depends on the situation. According to what you
said above, the server wants the number in binary rather than as ascii
digits.

Other than that, send "STX", the number, your message, and "ENX"
2 how can i make sure something is a 32bit unsigned long int. ?


Look at the struct and/or array modules. I suspect that you may have to
pay attention to whether the server want the binary in big or little endian
format.

Terry Jan Reedy

Feb 6 '06 #2
i think like byte 1 = 'S'
byte 2 = 'T'
and byte 3 = 'X'

still new at this, and thanks for the references

-sk

Feb 6 '06 #3
ok, part of what i have to do is know how many bytes will be sent. in
ascii is it one byte per character ?
like "password" would be 8 bytes long?

Feb 6 '06 #4

ne*****@xit.net wrote:
ok, part of what i have to do is know how many bytes will be sent. in
ascii is it one byte per character ?
like "password" would be 8 bytes long?


Yes, but when someone says ASCII STX, they usually mean
the single byte control character. This is a non-printable character
that you can create with chr(2). And ETX would be chr(3) (as
mentioned by DLB, there is no such thing as ASCII ENX).

Feb 6 '06 #5
i know that those characters exist, the docs say that the server does
not want the special "ETX" and "STX" characters, but the 3 ascii
characters "STX" and "ENX" i am not sure why.

Feb 6 '06 #6

ne*****@xit.net wrote:
i know that those characters exist, the docs say that the server does
not want the special "ETX" and "STX" characters, but the 3 ascii
characters "STX" and "ENX" i am not sure why.


What do you bet the server software was written by someone
who thought ASCII STX meant literally the characters "STX"?

I've seen stupider things.

Feb 7 '06 #7
me********@aol.com wrote:
What do you bet the server software was written by someone
who thought ASCII STX meant literally the characters "STX"?
Wouldn't explain the "ENX" instead of "ETX".
I've seen stupider things.


I give it 25% probability of being what you said, and 75% probability
that they didn't want to send any characters that couldn't be printed
in plaintext.

I've seen literally dozens of this kind of roll-your-own serial
protocol in the past few years, and they're all indicative that no two
are alike. Ever read the ARINC 429 documents? They'll curl your toes.

--Blair
"It's protocols all the way down."

Feb 7 '06 #8
i'm not sure, but its kinda been a pain in the hinder for a newbie like
me to find it in their docs.
thanks for all the help guys, let you know how it goes

Feb 7 '06 #9
ok, i am stuck again.

from the docs, the byte stream is supposed to look like this:

'S' 'T' 'X' [length indicator] [message type] [message] 'E' 'N' 'X'

the length indicator it says is a four byte integer number of a value N
( N would be how long the message body is )

the message type comes from a table in the docs. In my case, the
message type is 200. This is also supposed to be sent as a 4 byte
value.

so..... how do i make 200 occupy 4 bytes ?

Feb 7 '06 #10
ne*****@xit.net wrote:
ok, i am stuck again.

from the docs, the byte stream is supposed to look like this:

'S' 'T' 'X' [length indicator] [message type] [message] 'E' 'N' 'X'

the length indicator it says is a four byte integer number of a value N
( N would be how long the message body is )

the message type comes from a table in the docs. In my case, the
message type is 200. This is also supposed to be sent as a 4 byte
value.

so..... how do i make 200 occupy 4 bytes ?


You use the struct module and make sure you specify the correct
"endianness" - bet you didn't bargain for all this when you started!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Feb 7 '06 #11
indeed i did not. thanks for the tip.

Feb 7 '06 #12

ne*****@xit.net wrote:
so..... how do i make 200 occupy 4 bytes ?


Did you double-check that they didn't want "0200" in ascii
in the message?

As in:

STX0200................ENX

Because that's always possible. And, if you're _lucky_, they designed
the innards of the message so that "ENX" can never appear at random.
Though with a length parameter, you shouldn't have to worry about
that...though with a length parameter the ENX is redundant...

Argh!

I'm having flashbacks.

--Blair

Feb 10 '06 #13

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

Similar topics

37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
13
by: bgbauer70 | last post by:
My appologies if this ends up being a duplicate post. For some reason the first post never showed up. I've tried about 300 iterrations of this same ability, and none of them seem to work in...
4
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII...
2
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
31
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...
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...

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.