char2num or str2num
randomz_raf
ibrd ud, recvbuffer, 4
lsb2& = Asc(Left(recvbuffer, 1))
lsb1& = Asc(Right(Left(recvbuffer, 2), 1))
msb2& = Asc(Right(Left(recvbuffer, 3), 1))
msb1& = Asc(Right(Left(recvbuffer, 4), 1))
In Igor, how it should be write?
like this:
NI4882 ibrd={ud,4}
recvbuffer=S_value
lsb1=char2num (Rdbuffer[0])
lsb2=char2num (Rdbuffer[1])
msb1=char2num (Rdbuffer[2])
msb2=char2num (Rdbuffer[3])
recvbuffer=S_value
lsb1=char2num (Rdbuffer[0])
lsb2=char2num (Rdbuffer[1])
msb1=char2num (Rdbuffer[2])
msb2=char2num (Rdbuffer[3])
or
NI4882 ibrd={ud,4}
recvbuffer=S_value
lsb1=str2num (Rdbuffer[0])
lsb2=str2num (Rdbuffer[1])
msb1=str2num (Rdbuffer[2])
msb2=str2num (Rdbuffer[3])
recvbuffer=S_value
lsb1=str2num (Rdbuffer[0])
lsb2=str2num (Rdbuffer[1])
msb1=str2num (Rdbuffer[2])
msb2=str2num (Rdbuffer[3])
When I tried to print the values by using str2num or num2char I just got 'NaN' for each of the value instead of '0'
in your function or by using the Igor debugger:
char2num returns the numeric code for a single character. str2num converts a string containing text formatted as a number to a numeric value. My guess is that you want the numeric value of a single byte. For that you should use char2num.
I don't think this your situation, but, if S_value contains a number in ASCII format, you can do this:
May 25, 2011 at 01:05 pm - Permalink
There is a mistake in my program. I forgot to change the Rdbuffer to recvbuffer. The actual program is suppose to be like this:
recvbuffer=S_value
lsb1=char2num (recvbuffer[0])
lsb2=char2num (recvbuffer[1])
msb1=char2num (recvbuffer[2])
msb2=char2num (recvbuffer[3])
May 30, 2011 at 05:19 am - Permalink