convert number to character

Hi everyone,

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?
Hi randomz_raf,

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
printf "%s,%s,%s", num2char(0x83), num2char(0x00), num2char(0x81)
printf "_%s_\r", num2char(0x83) + num2char(0x00) + num2char(0x83)

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?

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.

 charA=num2char (a)
charB=num2char (b)
charC=num2char (c)
charD=num2char (d)

test= charA+charB+charC+charD

NI4882 ibwrt={ud,test,1}




So is it possible it will send the null (0 ASCII) to the device during ibwrt or it will set as end of string?

 

 

randomz_raf wrote:

charA=num2char (a)
NI4882 ibwrt={ud,test,1}



So is it possible it will send the null (0 ASCII) to the device during ibwrt or it will set as end of string?


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:

 

 

Make/B/U test = {a,b,c,d}
NIGPIBWriteBinaryWave2 test

 

 

 

Hi hrodstein,

Thank you for your help. Which one is much more better to use, NI4882 ibwrt or NIGPIBWriteBinary2?
Quote:
Which one is much more better to use, NI4882 ibwrt or NIGPIBWriteBinary2?


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.