I'm developing some Python code for an embedded GPRS module.
The inside Python interpeter version is 1.5.2+
I had no debugging opportunities on the module
The following code gives some problem and it has to do something with string conversion. -
def calculatecrc( message="" ):
-
remainder = 0
-
data = 0
-
for i in range(0,len(message)):
-
data = message[i:i+1] ^ (remainder)
-
remainder = arr[data] ^ (remainder << 8)
-
SER.send(str(remainder) + '\r\n')
-
The line "data = message[i:i+1] ^ (remainder)" gives the problems.
How can I solve this problem in Python 1.5.2+ interpeter?
5 5670 bvdet 2,851
Expert Mod 2GB
I'm developing some Python code for an embedded GPRS module.
The inside Python interpeter version is 1.5.2+
I had no debugging opportunities on the module
The following code gives some problem and it has to do something with string conversion. -
def calculatecrc( message="" ):
-
remainder = 0
-
data = 0
-
for i in range(0,len(message)):
-
data = message[i:i+1] ^ (remainder)
-
remainder = arr[data] ^ (remainder << 8)
-
SER.send(str(remainder) + '\r\n')
-
The line "data = message[i:i+1] ^ (remainder)" gives the problems.
How can I solve this problem in Python 1.5.2+ interpeter?
The bitwise xor operator '^' can only be applied to integers and long integers. It appears that variable 'message' is a string and you are applying a slice of it to '^'.
I'm developing some Python code for an embedded GPRS module.
The inside Python interpeter version is 1.5.2+
I had no debugging opportunities on the module
The following code gives some problem and it has to do something with string conversion. -
def calculatecrc( message="" ):
-
remainder = 0
-
data = 0
-
for i in range(0,len(message)):
-
data = message[i:i+1] ^ (remainder)
-
remainder = arr[data] ^ (remainder << 8)
-
SER.send(str(remainder) + '\r\n')
-
The line "data = message[i:i+1] ^ (remainder)" gives the problems.
How can I solve this problem in Python 1.5.2+ interpeter?
My friend, bvdet, is correct: The slice syntax used here looks very odd, indeed. But in this particular case, it would work because [i:i+1] has a length of one. This would be a lot cleaner: - #
-
for c in message:
-
data = ord(c) ^ remainder
My friend, bvdet, is correct: The slice syntax used here looks very odd, indeed. But in this particular case, it would work because [i:i+1] has a length of one. This would be a lot cleaner: - #
-
for c in message:
-
data = ord(c) ^ remainder
It looks a lot cleaner, but it didn't work
ord() makes an integer from every character in the string, so I realy don't understand what is going wrong.
It looks a lot cleaner, but it didn't work
ord() makes an integer from every character in the string, so I realy don't understand what is going wrong.
The syntax that I gave is equivalent to the one that you used: -
>>> message = 'hello world'
-
>>>
-
>>> message = 'hello world'
-
>>> for i in range(0,len(message)):
-
... print message[i:i+1],
-
...
-
h e l l o w o r l d
-
>>> for c in message:
-
... print c,
-
...
-
h e l l o w o r l d
-
>>>
So we may need to work on your CRC logic a bit. I'll have a look.
And, perhaps, you could supply some more details of your implementation.
The syntax that I gave is equivalent to the one that you used: -
>>> message = 'hello world'
-
>>>
-
>>> message = 'hello world'
-
>>> for i in range(0,len(message)):
-
... print message[i:i+1],
-
...
-
h e l l o w o r l d
-
>>> for c in message:
-
... print c,
-
...
-
h e l l o w o r l d
-
>>>
So we may need to work on your CRC logic a bit. I'll have a look.
And, perhaps, you could supply some more details of your implementation.
Unless, of course, you are doing this bit-wise, and your message looks like "010100110101". I that case you'd use Sign in to post your reply or Sign up for a free account.
Similar topics
by: Krakatioison |
last post by:
My sites navigation is like this:
http://www.newsbackup.com/index.php?n=000000000040900000
, depending on the variable "n" (which is always a number), it will take me
anywhere on the site......
|
by: Stu Cazzo |
last post by:
I have the following:
String myStringArray;
String myString = "98 99 100";
I want to split up myString and put it into myStringArray.
If I use this:
myStringArray = myString.split(" ");
it...
|
by: John F Dutcher |
last post by:
I use code like the following to retrieve fields from a form:
recd =
recd.append(string.ljust(form.getfirst("lname",' '),15))
recd.append(string.ljust(form.getfirst("fname",' '),15))
etc.,...
|
by: Angus Leeming |
last post by:
Hello,
Could someone explain to me why the Standard conveners chose to typedef
std::string rather than derive it from std::basic_string<char, ...>?
The result of course is that it is...
|
by: Andrew |
last post by:
I have written two classes : a String Class based on the book " C++ in
21 days " and a GenericIpClass listed below :
file GenericStringClass.h
// Generic String class
|
by: zoro |
last post by:
Hi,
I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party
string handling library that includes some very useful string
functions, in particular I'm interested in BEFORE (return...
|
by: Badass Scotsman |
last post by:
Hello,
Using VB and ASP,NET I would like to be able to search a STRING for a
smaller STRING within, based on the characters which appear before and
after.
For example:
String1 = " That was...
|
by: morleyc |
last post by:
Hi, i would like to remove a number of characters from my string (\t
\r \n which are throughout the string), i know regex can do this but i
have no idea how. Any pointers much appreciated.
Chris
|
by: ramu |
last post by:
Hi,
Suppose I have a string like this:
"I have a string \"and a inner string\\\" I want to remove space in
this string but not in the inner string"
In the above string I have to remove...
|
by: drjay1627 |
last post by:
hello,
This is my 1st post here!
*welcome drjay*
Thanks! I look answering questions and getting answers to other!
Now that we got that out of the way. I'm trying to read in a string and...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |