PtSetArg & byte

Hi How Can I display one byte variable type char in PtText ?

char pgmData;

printf(“pgmData = %d %d %d %d”,pgmDatap[0],pgmDatap[1],pgmDatap[2],pgmDatap[3]);

display in console: pgmData = 0 1 0 1 ; // and it is correct
and now how can I set one byte in PtText ?

PtSetArg(&arg[0],Pt_ARG_TEXT_STRING,pgmData[0],0); //doesn;t work :confused:
PtSetResources(pole,1,arg);

You’ve attempted to set a text string to the null character. pgmData[0] is the number 0, not the ascii string ‘0’.

You’ll need to convert your number to ascii string before you can use Pt_ARG_TEXT_STRING. There are a multitude of different ways to accomplish this, the easiest is probably using itoa() or sprintf().

Thanks you for your reply.
Ok it’s work but not quite.

I create thread with function which change value(bytes) pgmData for 1 second.
pgmData value = 1000
next = 0100
next = 0010
and so on …

And i write my function which should display current value:

void *displayValue(void *arg){
args[0];
char buf[50];

while(true){
sprintf( buf, “%d”, pgmDatap[0])
PtSet(&args[0],Pt_ARG_TEXT_STRING,buf,0);
PtSetResources(pole,1,args);
sleep(1);

}
}

pthread_create(NULL,NULL,displayValue);

It works but set only one values and next i get error “Memory fault (core dumped)”
What is wrong ? . I should run “displayValue” in new thread or maybe invoke in “main” ??

Photon is not thread safe, you need to wrap the calls with PtEnter and PtLeave. It`s also best if you post the real code, the second line “args[0]” is wrong.

Thanks you for your help, it works :slight_smile: