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

Login:
Pass:
 
 

Topic:
Converting data into string
This thread has 5 replies. Displaying all posts.
Post 1 made on Friday December 17, 2010 at 08:09
Elephant
Long Time Member
Joined:
Posts:
December 2010
47
I'm trying to request the status of exact byte via Modbus but when i'm trying to write the incoming string to label text it returns only empty string, the length of response is 10. How can i convert the data into string? when i'm trying to send the same data via java sockets it returns 10 digits : 0000040110
I use the LSys plc and wireless connection.
How to check whether result contains numbers or not?
What format data income from plc to control panel, is it TCPSocket class has a wrapper that changes the data into another type?

var Socket;
var result;
var status;
Socket=new TCPSocket(false);

result = "";

Socket.onConnect = function()
{
// string includes MBAP header and frame data that call a function of reading
// coils (bit)
Socket.write("\x00\x00\x00\x00\x00\x05\x00\x01\x00\x01\x00\x01");
};
Socket.onData = function()
{
result = Socket.read();
status = widget("LAMPSTATUS");// panel widget
status.label += result.toString(10);// returns nothing
Socket.close();

Socket.connect("192.168.0.10",502,3000);

Last edited by Elephant on December 17, 2010 09:25.
Post 2 made on Friday December 17, 2010 at 15:16
BluPhenix
Long Time Member
Joined:
Posts:
December 2008
371
If I'm not mistaking, the result from a tcpip read is already a string. Pronto does communication with strings.

But in that string you can acually have chars that don't from a number or a letter, for example 0x06 is an ACK and not an actual char or number. So if you asign this value to a label the remote will not display anything in the label or for some other chars it might display some quirks.

So what you acually do is:
You receive a string from you equipment: "\x06\x08\x11". Then you try to make it a string again, but with a radix.

So it depends in what code yourequipment responds. If it responds in ascii code then you should have something like:

"\x30\x30\x30\x30\x30\x34\x30\x31\x31\x30"

But in the case it sends byte codes you'll get:
"\x00\x00\x00\x04\x00\x01\x01\x00"

So both are strings only that the first is actually a true ascii string, the other is the result presented with a string.

So if wou want ascii chars from a byte code, you have to break the string apart and recompose it with a parseInt. Or any other way.
Post 3 made on Saturday December 18, 2010 at 13:08
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
Yes, socket.read() returns a string. If you need a byte array, you will have to convert the data.

Please have a look at a communications doc on Barry's website, particularly the last sections.

[Link: the-gordons.net]

You might also want to explore Barry's site:

http://www.the-gordons.net
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 4 made on Monday December 20, 2010 at 01:10
Elephant
Long Time Member
Joined:
Posts:
December 2010
47
thanks a lot for helping!

Last edited by Elephant on December 20, 2010 03:51.
OP | Post 5 made on Monday December 20, 2010 at 03:46
Elephant
Long Time Member
Joined:
Posts:
December 2010
47
.
Post 6 made on Tuesday December 21, 2010 at 19:13
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
TCP transmissions ALWAYS consist of bytes of data. A Byte is a number in the range of 0 to 255.

We humans put "representations" on those bytes to be able to display them on paper and to talk about them. That does not change the fact that they are always bytes (8-bit chunks) of data. Remember I am discussing this in the context of communications not floating point arithmetic!

The most common representations we use are decimal integers, Hexadecimal integers and ASCII Characters. There are others also.

Decimal integers are the easiest, because we are so familiar with them.

To represent a byte as Hexadecimal integers we need to break the byte into two 4 bit quantities, sometimes called nybbles, and for each nibble show its hexadecimal digit. The Hex digits are 0-9, a, b, c, d, e, f; sometimes also expressed as 0-9, A, B, C, D, E, F.

When we represent the bytes as ASCII we are using the ASCII collating sequence of characters. A collating sequence ascribes an ordering to the set of graphic characters (symbols) by associating each valid symbol with an integer value, commonly referred to as its collating sequence index. Standard ASCII only has single symbol representations for the bytes whose values are 32 to 127 (decimal). There are no single character representations for the bytes with values less than 32, nor for those above 127. There are somewhat agreed to multicharacter representatiions for those bytes below index 32 in Ascii, generally referred to as the "Control Characters". For example the carriage return, which has an index of 13, is generally represented textually as CR. When I represent it I show it as "(CR)" without the quote marks.

Now we get into confusions. Looking at a printed sequence of bytes 00 10 45 67 we should always assume them to be decimal values as shown. We need a convention to state that the sequence is not decimal or is a mixture of decimal and hexadecimal reprentations. The widely agreed to notation is \xYY which means interpret YY as hexadecimal symbols not decimal symbols. This means that we always view 45 as decimal 45 but view \x45 as decimal value 69. Conversely if we have the byte with decimal value of 69 we can show it as 69 or \x45 on paper, or even the Ascii symbol "E" (without the quotes).

As further confusion the sequence 00 10 45 67 might actually be the ascii reprentation. If this were the case then the internal byte sequence is

48 48 32 49 48 32 52 53 32 54 55

or as integers in hexadecimal representation

\x30 \x30 \x20 \x31 \x30 \x20 \x34 \x35 \x20 \x36 \x37

Just keep in mind that in memory IT ALWAYS IS A SEQUENCE OF BYTES CONTAINING INTEGERS IN THE DECIMAL RANGE 0 to 255. There is no explicit memory typing in a non tagged architecture. The contents of a memory cell or region (sequence of cells) only has meaning by the operations applied to it, intrinsicly it always is numbers or sequences of numbers.

Last edited by Barry Gordon on December 21, 2010 20:09.


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