1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. KUKA Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

ASCII Characters and string variables

  • SkyeFire
  • February 3, 2009 at 7:20 PM
  • Thread is Resolved
  • SkyeFire
    Reactions Received
    1,051
    Trophies
    12
    Posts
    9,426
    • February 3, 2009 at 7:20 PM
    • #1

    Had some odd experiences trying to do hand-coded serial comms in KRL over the past week. Thought I'd share.

    Had to connect a Keyence camera to my KRC2 via RS232. Got the channel working easily enough, but eventually found that I had to append a Carraige Return (ASCII code 13) to my output string before I gave that string to my CWRITE command, as per these threads that I dug up:

    http://74.125.95.132/search?q=cache…lient=firefox-a
    and
    http://www.roboterforum.de/roboter-forum/…t-t2797.15.html

    But there was a snag. The code described as working in the second link... didn't, for me. Any attempt to SWRITE the value of a Carriage Return into the string using a %c conversion code failed with a #FMT_ERR. This is odd, b/c it's been described as working for other people, and judging from the manual, the %c conversion code should do exactly that.

    Trying UNIX-Style "\n|" or "\r" inside the format string didn't work, either.

    Eventually, someone suggested doing this: STRING[first_clear_position] = 13
    It sounded crazy to me, since string variables (char arrays, really) in KRL are always fussy and hard to work with, but what the heck, I gave it a shot...
    And it worked. It would appear that assigning a single element of a CHAR[] array the value of an INT variable will put the ASCII equivalent of that INT value into the CHAR[] array.
    One other thing I found interesting: I had the String variable logged in the .dat file, so I was able to look at it later. It's appearance in the .dat file was STRING] = "T1'H0D'"
    Note the single quotes inside the double quotes. 'Hxx' is the standard KRL notation for Hexadecimal values, and 'H0D' is the hex equivalent of 13, so my guess is that KRL uses this technique to store non-alphanumeric ASCII characters (like Carriage Return, Line Feed, etc) inside string variables.

    While my code now works, I'm interested in seeing if anyone wants to chime in with their own experiences and/or tricks for handling string variables, ASCII values, and serial comms. It's probably a rich topic for discussion, and I suspect I'll be doing more of this stuff before long.

  • Pavel_Yakubov
    Trophies
    3
    Posts
    3
    • October 23, 2011 at 8:37 PM
    • #2

    It is really interested for me! I plan to use KUKA with the camera together. Thanks for the info.

    But I will have OMRON camera (not KEYENCE). It is the same or not?

    Edited once, last by Pavel_Yakubov (October 24, 2011 at 2:00 PM).

  • py_programmer
    Trophies
    3
    Posts
    2
    • February 3, 2012 at 9:45 PM
    • #3

    This is the way it works in C. Chars are just 8 bits. If you read the same 8 bits as an INT, you get a number.

  • watchcat
    Trophies
    3
    Posts
    20
    • November 20, 2014 at 10:27 PM
    • #4

    hello I am writing sofware for robot communication over RS232 and I want to send messages coded in hex, like sendiing number 33.62 with ESC and STX at the start and EST ETX at the end , should give something like 1B 02 33 33 2C 36 32 1B 03 (without spaces)

    ESC ; Hx 1B
    STX ; Hx 02
    ETX ; Hx 03
    3 ; Hx 33
    . ;Hx 2C
    6 ;Hx 36
    2 ;Hx 32

    I cant try it now on the robot unfortunatelly, but I was thinking about writing something like this:
    decl char val[5]
    val="33.62" ;
    offset=0
    SWRITE(Send[], State, Offset, "%x", val) ;

    or like that
    SWRITE(Send[], State, Offset, "%x, %x, %x,%x,%x", val[0], val[2], val[3], val[4], val[5]) ; (later on parametriazing by loop for i =0 to strlen)

    and then adding ESC and STX and ETX later on.
    Could any of it work?

    Edited once, last by watchcat (November 20, 2014 at 10:40 PM).

  • SkyeFire
    Reactions Received
    1,051
    Trophies
    12
    Posts
    9,426
    • November 21, 2014 at 12:49 AM
    • #5

    You can do something like this rough code:

    Code
    DECL CHAR ETX[1]
    DECL CHAR STX[1]
    DECL CHAR ESC[1]
    
    
    ESC='H1B'
    STX='H02'
    ETX='H03'
    
    
    StrAdd (Send[],ESC)
    StrAdd (Send[], STX)
    StrAdd (Send[], ETX)
    Display More

    That's very rough, but something along those lines will work. Assigning an integer value to a single-character CHAR variable will encode that CHAR variable as the ASCII character for that value. I've used a variation on this for adding CR and LF on the end of RS232 transmission strings.

  • watchcat
    Trophies
    3
    Posts
    20
    • November 21, 2014 at 9:37 AM
    • #6

    jep later on, I was thinking about it before falling asleep. I will have to do all the ASCII2Intiger converter function and then of course express it in hex.

    It just I have my old backup and then when I added just intiger Kuka showed it like that:

    SWRITE(Send[], State, Offset, "%f %g", $axis_act.a1, $axis_act.a2) ;
    Offset = (( StrLen (Send_Command[])) +1 )
    Send[Offset]=ETX ;
    // output invariable was Send[]="38.627579 -77.7795'H03'"

    And I am not sure if it is sending it with ' and H at the begging? becouse this is what warries me...
    Now I am thinking about something like

    V_ESC = 'H1B'
    V_STX ='H02'
    V_ETX ='H03'
    V_3='H33'
    V_. ='H2C'
    V_6='H36'
    V_2='H32'

    SWRITE(Send[], State, Offset, "%x, %x,%x,%x, %x,%x,%x", V_ESC, V_STX,V_3, V_., V_6,V_ETX ,V_ESC ) ; for "ESC STX 3.6 ETX ESC" ="1B02332C36031B"

    or am I complicating it too much with %x? :] :uglyhammer2:

  • SkyeFire
    Reactions Received
    1,051
    Trophies
    12
    Posts
    9,426
    • November 22, 2014 at 2:38 PM
    • #7

    The 'H' is not part of the number. 'Hxxx' is KRL coding to represent a hexidecimal number, just like 'Bxxxx' is the binary representation. So 15 = 'HF' = 'B1111'.

    If you simply used Variable=1111, that would be One Thousand, One Hundred Eleven. Variable='B1111' would assign the variable a value of 15 (decimal).

    Using SWrite is going to convert the integer value, regardless of how it is encoded, into a text string. So using SWrite (string[], "%x", 'H03') is going to write a simple integer 3 into the string as a string.

    I have a small example module called Serial located at kuka.skyefire.org where I do this, although I did use decimal integers rather than hex. But KRL should not differentiate between them -- check the .DAT file values for CR and LF to see what I mean.

    Edited once, last by panic mode (November 22, 2014 at 11:37 PM).

  • Online
    panic mode
    Reactions Received
    1,280
    Trophies
    11
    Posts
    13,080
    • November 22, 2014 at 11:38 PM
    • #8

    sorry, just fixed typo
    ' Variable='B111' would assign the variable a value of 15 (decimal).'
    to
    ' Variable='B1111' would assign the variable a value of 15 (decimal).'

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • watchcat
    Trophies
    3
    Posts
    20
    • January 21, 2015 at 9:49 AM
    • #9

    finally I have time to sum up things here so that somebody else might use it.
    Different kind of coding numbers (hex, bin dec) was not a problem for me. I was just worried that the robot could send the mark H before it. But it didn't as you have written. It just sent a numbers so that I could decode it partner device.
    As about code - I made a function to change char into proper digit to calculate checksum, but I was sending chars to the open port as a "%s" type: first by SWRITE, and then into the opened serial by CWRITE.

    temp_data2bsent[j]="7"
    int_data2bsent[j]=ASCII2INT(temp_data2bsent[j]) ;for checksum calculation
    (...) ; rest of the data
    SWRITE(Dane_toSent[], CH_State, Offset, "%s", temp_data2bsent[]) ; make a string

    COPEN (:SER_3, Handle) ; open serial port COM3
    CWRITE (Handle, TX_State, Mode, "%s", Dane_toSent[]) ; send TX string
    WAIT SEC 0.1 ;
    CCLOSE (Handle, CH_State);


    What was strange, I had to add a little delay before closing serial port it because the message was not complete without. In documentation there was structure to check the CWRITE status value on #CMD_OK, but I didn't decide to use it. I could make "wait for #CMD_OK" as it might hang the communication and other values were not significant for me as if the partner device don't receive proper message, the whole communication looped anyway.
    Thanks for help! :smiling_face:

  • Ammu
    Trophies
    3
    Posts
    23
    • November 19, 2019 at 8:02 AM
    • #10

    hi Watchcat

    i am having the same problem. can you send me the explain for sending hex string

  • SkyeFire
    Reactions Received
    1,051
    Trophies
    12
    Posts
    9,426
    • November 19, 2019 at 3:51 PM
    • #11

    That question is far too vague. Unless you expect someone to write an entire manual for you, you need to provide much more detail.

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download