RobotStudio event

Unpacking rawbytes to string

Hello,

The subject sort of changed on my last thread (https://forums.robotstudio.com/discussion/comment/25839#Comment_25839), so I thought I would just move it to this new subject.
Summary:
I am sending the robot arbitrary robtarget data from LabVIEW via sockets and TCP/IP. I am trying to create a method to check if the target data has any non-numeric characters in it. Best method so far was to convert robtarget to string and parse out bad characters and then convert back to robtarget. The problem with this is, if I unpack everything into robtarget data type, the bad characters turns to a "0" all the other characters after it, into a "0". So I have to unpack the rawbytes into a string before going to robtarget data.
Question:
How can I unpack data being sent to the robot (sent in robtarget format) into a string, or multiple strings (pos string, quaternion string, config string)?

Thanks for any help!
SM

Comments

  • By the way what do you mean with "data being sent to the robot (sent in robtarget format)"? 'RobTarget' is an ABB type right?

    Furthermore, the idea is to convert the received data to string and then to parse the robtarget. Why not directly use the "
    SocketReceive" function?  
    https://forums.robotstudio.com/discussion/comment/25528/#Comment_25528

    Initial all bytes in 'rawbytes' are set to zero. Maybe it is an idea to first send the length of the robtarget (or string) and then send the actual data? 

    Can you show some code how you implement it currently?
  • SteveMob
    SteveMob
    edited September 2016
    John,
    What I mean by "data being sent to the robot (sent in robtarget format)" is that I am sending the target data from LabVIEW like this:
    [X,Y,Z],[Q1,Q2,Q3,Q4],[C1,C4,C6,Cx]. So I unpack the individual elements that make up a robtarget data.

    I am using the SocketReceive function. I send all the data at once from LV, and receive it all on one line in RS:
    SocketReceive clientSocket\RawData:=messageBytes\Time:=25;. I then can unpack the individual elements.

    How could I set all the bytes in rawbytes to zero?

    What portion of code do you need to see? My entire program is almost 600 lines of code... The unpacking process can be seen on my previous thread:
    (https://forums.robotstudio.com/discussion/comment/25839#Comment_25839)
    This is my attempt at unpacking the message into strings, but the numbers are coming out to be completely different than what I was sending RS:
    UnpackRawBytes messageBytes\Network,2,targetx\ASCII:=25;     ! targetx is a string data type
    targetx:=HexToDec(targetx);
    UnpackRawBytes messageBytes\Network,6,targety\ASCII:=25;     ! targety is a string data type
    targety:=HexToDec(targety);
    UnpackRawBytes messageBytes\Network,10,targetz\ASCII:=25;   ! targetz is a string data type
    targetz:=HexToDec(targetz);


    I have also just tried it like this:
    UnpackRawBytes messageBytes\Network,2,targetx\Hex1;    !targetx is a byte data
    targetx1:=HexToDec(ByteToStr(targetx));                                  !targetx1 is a string data type
    UnpackRawBytes messageBytes\Network,6,targety\Hex1;     !targety is a byte data type
    targety1:=HexToDec(ByteToStr(targety));                                  !targety1 is a string data type
    UnpackRawBytes messageBytes\Network,10,targetz\Hex1;   !targetz is a byte data type
    targetz1:=HexToDec(ByteToStr(targetz));                                  !targetz1 is a string data type

    When I do it like either of these methods, I unpack some numbers, but none of them are the correct numbers that I sent...

    I just need to unpack the rawbytes into string(s) instead of unpacking the message into data types like robtarget or num. That's the ultimate goal right now. That way, I don't lose any data in the unpacking process. If I unpack a non-numeric value into say a num data type, the message is parsed a "0" due to some RS internal stuff. But if I unpack it into a string, I don't lose the data, and I can parse out the non-numeric values and then convert that string to robtarget data or num data.

    Also, when unpacking messages into strings, how do I do the indexing for that? With Float4, I was just doing every 4. But I am not sure how to do the indexing with strings.

    Thanks for the help,
    SM



    Post edited by SteveMob on
  • I think the problem is the encoding type you used in LabVIEW. For example if I send the value "a1b2" in UTF-8 format, I receive this string correctly in RS.

    But if I send the values in a different format, for example UTF-16, I get the following value "ÿþa\001\00b\002\00". It looks like it contains 'bad' characters, but the encoding for every digit/character is different. You can also try to create a decoder in RS...

    Furthermore, most of the time you can use directly a string value with the 'SocketReceive' function.

    <div>SocketReceive client_socket &nbsp;\RawData:=revRB;<br></div><div>UnpackRawBytes revRB\Network, 1, revStr\ASCII:=RawBytesLen(revRB);</div>
    <br>SocketReceive client_socket \Str := revStr;

  • SteveMob
    SteveMob
    edited September 2016
    John,

    I am not very good with LV so I cannot say for sure how the data is being sent. However, I tried receiving and unpacking as you mentioned, and yes, the format seemed to be like how you said UTF-16, similar to: "ÿþa\001\00b\002\00". Is this something I can fix on the RS side or do I need to do that on the LV side? Like the decoder you mentioned? I wouldn't even know where to start to do something like that...

    If it helps at all, when I unpack them using Float4, and unpack each element and adding 4 to the index number, my numbers come out correctly (as I sent them). In LV, I am taking each element and putting them into a single, 32-bit real and converting it to a string. All those strings then get concatenated into a 1-D array of strings and then sent to RS. In RS, could I maybe unpack everything into a single float? I'm sorry, I'm not very good with the different data types and such..

    Thanks so much for the help, I feel like we're getting close to the solution
    SM
    Post edited by SteveMob on
  • John,

    I was finally able to unpack the entire message into a single string. I had to go into LabVIEW and alter the method I was sending the message.

    Please go back to my original thread for further questions regarding parsing out the non-numeric characters:
    https://forums.robotstudio.com/discussion/comment/25839#Comment_25839

    Thanks for the help,
    SM