
convert number to character

randomz_raf
I'm make a simple program using Igor to converting number to character then display the value on command window..
This is my Procedure/Function :
#pragma rtGlobals=1 // Use modern global access method. Function Test(ctrlName) : ButtonControl String ctrlName Variable a,b,c,d String test,charA,charB,charC,charD a=0x86 b=0x00 c=0x83 d=0x00 charA=num2char (a) charB=num2char (b) charC=num2char (c) charD=num2char (d) test= charA+charB+charC+charD Print "test:",test End
but i have some problem with my program. When I execute my function, I did not get a character for my 'charC'. This is the result that i got on the windows command : test: †
So can any of you help me slove this problem?
the problem is that you are embedding ASCII 0, num2char(0x00), into your string. And this marks in C, and also for a few Igor functions, the end of the string. Therefore everything behind that is discarded.
Try
Here the first gives you the expected string, the second is cutoff at num2char(0x00).
Why do you want to insert ASCII 0 into a string in the first place?
April 20, 2011 at 05:41 am - Permalink
Dear thomas_braun,
Thank you for your reply. Actually I try writing my Igor program for my TDC Histogram. In my program I need to set null character for the four parameters (d,e,b,c) to initialize the TDC device. Then I will put the four parameters into one string (test) and use the string for as a buffer in my NI4882 ibwrt function.
So is it possible it will send the null (0 ASCII) to the device during ibwrt or it will set as end of string?
April 25, 2011 at 09:26 am - Permalink
Yes, that should work because NI4882 ibwrt treats the string as a black box, not as a C string.
You could also use NIGPIBWriteBinary2.
You could also use NIGPIBWriteBinaryWave2:
April 25, 2011 at 09:59 am - Permalink
Thank you for your help. Which one is much more better to use, NI4882 ibwrt or NIGPIBWriteBinary2?
April 25, 2011 at 10:11 am - Permalink
It does not matter. I consider the NI488 operation to be low-level and I use the higher level operations when possible. I would tend to use NIGPIBWriteBinary2 for this situation.
April 25, 2011 at 02:26 pm - Permalink