BYTES in 'C'

Camerart

Member
Hi,
I'm using a PIC that READs a GBS module.

I'm having difficulty 'talking' to the GPS, and being helped by the Ublox forum. They have given me an example STRING ARRAY of BYTES to send to the GPS: Chr(b5h) + Chr(62h) + Chr(01h) + Chr(07h) + Chr(00h) + Chr(00h) + Chr(08h) + Chr(19h) + CrLf [This is how my system sends ARRAYs]
So far I haven't succeded.
They use 'C' and I would like to know if 'C' would use C.S.V.s to send BYTEs like this?
Cheers, Camerart
 

Cromewell

Administrator
Staff member
Kind of. That specific sequence would be:
unsigned char data[10] = {0xb5, 0x62, 0x01, 0x07, 0x00, 0x00, 0x08, 0x19, 0x0D, 0x0A};
 

Camerart

Member
Kind of. That specific sequence would be:
unsigned char data[10] = {0xb5, 0x62, 0x01, 0x07, 0x00, 0x00, 0x08, 0x19, 0x0D, 0x0A};
Hi C,
I note that you show commas between each BYTE. where with the CODE I use it doesn't have them.

I'm using a digital analyser to intercept messages from the Ublox programmer, which uses Serial DATA, and it doesn't show commas. I'm wondering if the analyser is a representation, so even though there are commas, it isn't showing them.
does this seem plausible.

The reason, I'm going into detail, is that I've tried the above, and what the Ublox forum suggests, neither has commas.

I hope you follow?
C.
 

Cromewell

Administrator
Staff member
C does not have the concept of strings. The closest you can get is a char array. If it is an actual string, C 'string' functions will do bad things if the char array is not null terminated.

In code, initializing a char array with the sequence from your post would be done as I have above. The commas are simply the code representation of separation of elements. On the wire, you will not see commas.
 

Camerart

Member
C does not have the concept of strings. The closest you can get is a char array. If it is an actual string, C 'string' functions will do bad things if the char array is not null terminated.

In code, initializing a char array with the sequence from your post would be done as I have above. The commas are simply the code representation of separation of elements. On the wire, you will not see commas.
Hi C,
Ok,
Coding is a mystery to me, although I spend a lot of time trying. I get lots of help like this, but it's just something that doesn't 'stick'.

I'm trying to program GPS modules with SPI, but so far I've failed, even with lots of forum input. I'll give it a last try tomorrow, with commas, between each BYTE.
Cheers, C.
 

Cromewell

Administrator
Staff member
I should have written the first part better.

Using my array declaration above:
unsigned char data[10] = {0xb5, 0x62, 0x01, 0x07, 0x00, 0x00, 0x08, 0x19, 0x0D, 0x0A};
If I were to do this:

printf("%d", strlen(data));

The program would print 4, not 10 as you might expect. But say I had a different 'string':

unsigned char data[10] = {0xb5, 0x62, 0x01, 0x07, 0x02, 0x03, 0x08, 0x19, 0x0D, 0x0A};

printf("%d", strlen(data));

I am not sure what it would print now, but it would almost assuredly be greater than 10. The program would walk past the end of memory mapped to data until it found a byte that happened to be null (0).

I could likely be using a char as well, instead of unsigned char.
 

Camerart

Member
I should have written the first part better.

Using my array declaration above:

If I were to do this:

printf("%d", strlen(data));

The program would print 4, not 10 as you might expect. But say I had a different 'string':

unsigned char data[10] = {0xb5, 0x62, 0x01, 0x07, 0x02, 0x03, 0x08, 0x19, 0x0D, 0x0A};

printf("%d", strlen(data));

I am not sure what it would print now, but it would almost assuredly be greater than 10. The program would walk past the end of memory mapped to data until it found a byte that happened to be null (0).

I could likely be using a char as well, instead of unsigned char.
Hi C,
As I only read BASIC, this doesn't mean much to me, apart from LEN, which is used in conjunction with the ?STRING? of BYTES I posted, where LEN counts the number of BYTES and a FOR NEXT loop reads them in turn.
C.
 
Top