Page 1 of 1

PostPosted: Wed Sep 25, 2002 1:53 pm
by ris12345
Following code snippet generates run time error "string index out of range"

string csum1;

csum1@[0] = serrecv();
csum1@[1] = serrecv();
csum1@[2] = serrecv();
csum1@[3] = serrecv();
csum1@[4] = '\00';

What I am trying to do here is read 4 characters in from the serial port and load them into a string and then null terminate it. I have tried initialising the string variable to a "12345678" to ensure it is at least 8 chars long but this doesn't seem to make a difference

Any help gratefully received


Richard Stone

PostPosted: Wed Sep 25, 2002 9:46 pm
by shayneham
Can you use serrecva? This is all in my head cause I'm at work and all my pocketC code is at home, but if I remember correctly I do something like this....

string csum1;
char mychars[5];


I may have variables and what not in the wrong place but it should be enough to get you started....

Shayne Hamel
Quote Software

PostPosted: Thu Sep 26, 2002 9:20 am
by ris12345
Thanks for that - basically what you said works once I'd sorted out the syntax. However I am still confused why my original code generated the error!

PostPosted: Thu Sep 26, 2002 3:29 pm
by shayneham
I think what is going on is you are putting chars(the actual ascii value) into the string ie. a number from 1-255, so it may work if you instead did (string)serrecv();

Just a guess :)

Shayne Hamel
Quote Software

PostPosted: Fri Sep 27, 2002 6:45 am
by ris12345
Quite possibly Shane. To be honest this is nowthe least of my problems with using the serial port - I'm composing another post now with additional problems! Thanks for your help

PostPosted: Fri Sep 27, 2002 6:17 pm
by shayneham
I also am currently working on serial port stuff, check out my post under the Development. Check out my post over at...

All Forums
2. Development Discussion
PocketC on Palm OS
Need suggestions for some of my Serial code

Maybe we can help each other :) since none of the regular users seem to be interested...

Shayne Hamel
Quote Software

PostPosted: Mon Sep 30, 2002 9:08 am
by ris12345
Hi Shane,

What is frustrating me is that IMHO the PocketC documentation is lacking in detail. I don't expect to have to experiment to find out how functions work! I want it spelling out particularly when you have paid out for a product.

I have extensive experience of programming in C on microcontrollers where you have access to all the information you need about serial port functionality plus the ability through the lanquage to get at all the flags, registers etc. so I find it frustrating when you have to second guess how something works all the time

I guess serial port stuff is a bit of a minority interest on this forum which is why you don't get many replies.

Amyway enough whinging for now! I'll look at your stuff asap and try and assist