Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Previous page Next page Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Page 2 of 2
Topic:
Hexadecimal string conversion for a RS 232 command
This thread has 23 replies. Displaying posts 16 through 24.
Post 16 made on Sunday June 29, 2008 at 18:20
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
You are welcome. I just had to understand what you wanted to do and what the protocol said.

Be sure to look at my related post for the full RussSound array which automatically adds the F1 inversion code when needed and adjusts the data byte to its compliment form.

Put the array at the activity level so it can be referenced from the pages or wherever and only have to be defined and populated once.
Post 17 made on Sunday June 29, 2008 at 19:42
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
If 0xF1 is required for values > 0x7F, then Barry's function with a lookup table is the better approach.

Lyndel
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 18 made on Monday June 30, 2008 at 02:56
Ericbal
Long Time Member
Joined:
Posts:
December 2007
59
Barry,

I just read your post and I will use the full array. It is true that I was wondering how to handle the inversion code.

As far as Russound protocol is concerned, the array will also need to be used for the checksum control as the number of bytes is the string is taken into account in its calculation.

Thanks again.
Post 19 made on Monday June 30, 2008 at 12:34
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
You can use the array technique any place you need to enter a binary number in the range of 0-255 into the RussSoundProtocol. You could even use it for constants instead of "\xnn" by writing chr[nn] where nn is a number 0-255. remembering that for all values over 127 the inversion will take place so do not use it for the control characters 0xF0 and 0xF7 if they are really desired. There should be no need to explicitly use the inversion control (0xF1) as that is automatically handled.

As a further tip for clarity you might want to define some constants such as:
SOMbyte="\xF0"; EOMbyte="\xF7"; NULbyte='\x00";. . . as needed fo commonly used constants.
You can then build messages as
msg= SOMbyte+chr[i]+chr[j]+NULbyte+. . .
msg+=chr[checksum(msg)]+EOMbyte

In the above msg is a string variable, i and j are integers in the range 0-255, and checksum is a function that computes and resurns the 7 bit checksum as an integer.

It makes it a lot easier to read and understand. The checksum function would look something like this:

function checksum(a)
{var i; var b=a.length; for(i=0; i < a.length; i++;) { b+=a[i]-0;}; b+=127; return b; }

Last edited by Barry Gordon on June 30, 2008 15:14.
Post 20 made on Tuesday December 21, 2010 at 05:21
Elephant
Long Time Member
Joined:
Posts:
December 2010
47
i'm trying to send a data string, where the last byte contain the luminosity parameter value:

sock.onConnect = function()
{
value=parseInt(text.label); //for example value = 31
result="\\x"+value.toString(16);
status.label = result; // it displays \x1f

sock.write("\x00\x00\x00\x00\x00\x05\x00\x10\x00\x05\x00\x01\x02\x00"+ result);

I want to have string:
sock.write("\x00\x00\x00\x00\x00\x05\x00\x10\x00\x05\x00\x01\x02\x00\x1f");


The result differs, it assigns 120 instead of 31.

How can i attach my result parameter to a data string?

Last edited by Elephant on December 21, 2010 05:32.
Post 21 made on Tuesday December 21, 2010 at 11:35
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
If I unerstand you correctly, What you really want is the string in memory to end in a byte that has the decimal value of 31. Lets call everything up to that point FrontOfString which is of type string.

Desired string=FrontOfString+string.fromCharCode(31).

In your specific case :

sock.write("\x00\x00\x00\x00\x00\x05\x00\x10\x00\x05\x00\x01\x02\x00"+string.fromCharCode(31));

or

sock.write(string.fromCharCode(0,0,0,0,0,5,0,16,0,5,0,1,2,0,31))

The last technique being much easier IMHO
Post 22 made on Wednesday December 22, 2010 at 03:53
Elephant
Long Time Member
Joined:
Posts:
December 2010
47
That helped me to minimize my code! Before the solution that you proposed, i used the switch case operator, with 100 case events :

...
if string == "5" write("...\x05")
...

)))
Post 23 made on Wednesday December 22, 2010 at 10:16
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
Do not take this the wrong way. I strongly suggest you buy Flannigan's book and go through it a couple of times. There are whole sections you can skip (e.g. web page construction). By doing this you will acqaint yourself with the various commands and methods available, which you can always look up later. That is what I did. If I need to do something then I use the book as a reference.

The golden rule in code writing is that if what you are doing is simple and takes a lot of code, then there is another better way to do it.

Glad to see you have not given up on postscript!

Last edited by Barry Gordon on December 22, 2010 12:11.
Post 24 made on Wednesday December 22, 2010 at 10:41
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
From Flanagan, Chapters 1-11 and the Javascript Core Reference in back should be all you need.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Page 2 of 2


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse