How am I to express variable as hex to send like-
a='00'
write("\x#{a}") => 0x00
Trying to include received string variable into command string of raw data and passed to com port like –
cmd="\x45\x#{a}\x01"
Send(cmd)
In Ruby
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The String#to_i function takes a base argument, which default to ten – but you can pass in sixteen instead. That’ll get you the number you want as a number, rather than a string. From there, you can use the Integer#chr function to get the value you want – a string containing the character with the binary value represented by the original string.