View topic - PtSetArg & byte

PtSetArg & byte

anything that doesn't fit to other groups.

PtSetArg & byte

Postby d1gger » Thu Jun 03, 2010 11:17 am

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);
d1gger
New Member
 
Posts: 8
Joined: Thu May 27, 2010 7:52 pm

RE: PtSetArg & byte

Postby stevenlougheed » Thu Jun 03, 2010 9:25 pm

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().
stevenlougheed
Active Member
 
Posts: 11
Joined: Thu Oct 15, 2009 3:55 pm

Postby d1gger » Fri Jun 04, 2010 6:52 am

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" ??
d1gger
New Member
 
Posts: 8
Joined: Thu May 27, 2010 7:52 pm

Postby mario » Fri Jun 04, 2010 11:03 am

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.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby d1gger » Sun Jun 06, 2010 6:01 pm

Thanks you for your help, it works :)
d1gger
New Member
 
Posts: 8
Joined: Thu May 27, 2010 7:52 pm


Return to General Programming

Who is online

Users browsing this forum: No registered users and 5 guests