View topic - PtSetArg & byte

Page 1 of 1

PtSetArg & byte

PostPosted: Thu Jun 03, 2010 11:17 am
by d1gger
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 :/
PtSetResources(pole,1,arg);

RE: PtSetArg & byte

PostPosted: Thu Jun 03, 2010 9:25 pm
by stevenlougheed
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().

PostPosted: Fri Jun 04, 2010 6:52 am
by d1gger
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" ??

PostPosted: Fri Jun 04, 2010 11:03 am
by mario
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.

PostPosted: Sun Jun 06, 2010 6:01 pm
by d1gger
Thanks you for your help, it works :)