Hi Guys, this is driving me mad. I'm trying to print an array to a Vt100 monitor (simulated at the mo), everything has been working great untill I wanted to print an array. It's almost as if the array has been nulled. See code.
Any help sorting this out would be most appreciated..
dim country(8) as String * 15 dim test as string * 15
test = "Test CHINA "
country(0) = " CHINA "
country(1) = " FRANCE "
country(2) = " INDIA "
country(3) = " PAKISTAN "
country(4) = "UNITED KINGDOM"
country(5) = "UNITED STATES "
country(6) = " U.S.S.R. "
HSerPrintStringCRLF test ' This works
HSerPrintStringCRLF country(0) ' This doesn't work
HSerPrintStringCRLF country(1) ' This doesn't work
There is sommit wierd going on.
Thanks :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
try this line:
Dim country(0),country(1),country(2),country(3),country(4),country(5),country(6) as String * 15
for your line:
dim country(8) as String * 15
You mix up two dim commands, the 8 in your command has to do with the size of the array but not with the number of strings (in this case with the name country)
I understand that this is a littlebit weird because in other Basic languages the implementation of the Dim command is different.
Last edit: Theo 2018-08-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Theo,
Yup tried your suggestion but to no avail im afraid.
Dim country(0),country(1),country(2),country(3),country(4),country(5),country(6),country(7),country(8) as String * 15
country(0) = " CHINA "
country(1) = " FRANCE "
etc
HSerPrintStringCRLF country(0)
etc
still nothing
I am using a pic18f47k42, would that make a difference..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This looks like a casting issue where currently the passing of the string array as a parameter is not passing the string but the first byte value of the string array.
So, use the 'select case' as a workaround.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Theo,
Well I think thats pretty poor of GCbasic where it can't handle string arrays. Even the Oshonsoft can do it quite seemlesly, but unfortunately it cant handle the pic chip in question.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Actually I would be surprised if Great Cow, or any other BASIC, supported String arrays on 8 BIT PIC's.
If you look at the architecture used in the PIC Core there is very little address space allocated to RAM and that available RAM is segmented.
The example code you posted would require 144 Bytes of RAM just to store the array data, I don't think many 8 Bit PIC's have that much contiguous RAM, in fact not many PICs even have that much RAM in total.
Then you have all the working storage needed by the compiler and any other functions you use, such as the serial communications, and you begin to see the problem.
PIC's are fantastic devices for interfacing with hardware and the real world environment. They have a vast array of device independent peripherals available, but they are NOT Computers based on Von Neumann Architecture, they are Interface Controllers based on Harvard Architecture.
As Such they are not intended to manipulate RAM hungry applications like Strings and Floating Point Mathematics.
If Strings are Important to you I would suggest that you use an ATMEL device based on the 8051 core rather than a PIC. But if you want to design and build Controller hardware then the PIC is first choice.
Just My 2c,
Cheers,
Chris
Last edit: Chris Roper 2018-08-29
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Cris, I see where you are coming from with pic chips having limited RAM, which is why I chose the 18F47K42 as it has 128K flash and 8K of RAM which is plenty for my purposes, oh and it runs at 64Mhz, which is quite nippy I think for most things.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stick with the Select-Case. I have routines to automatically create string tables etc etc. I will post a demo when I get time... which I wont for a some time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
studying your first question again I have the following question:
because the command HSerPrintStringCRLF is relatively new, have you tried to use the old command HSerPrint instead?
Do you get the same error(output) as before; if so than the problem is probebly caused by the string variable country(x).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Theo,
I have tried with HserPrint also and it did print zero's, but if you read a little further down, Anobium has found there to be bugs which stops string arrays. Which he is now investigating.
Thanks for the suggestions though. :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In gcb arrays start as array(1) as 1st element , not 0.
country(0) = " CHINA " try country(1) = " CHINA " and so on. Not the problem though.
hserprint Len (country(1)) doesn't work either.
gcb doesn't do multi dimentioned arrays .. which I suppose string arrays are,the chars are just numbers.
Assuming plenty of ram and all countries same length, a string can be 255 chars,
country(n) in the string would be mid(county,n*15+1,15)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Guys, this is driving me mad. I'm trying to print an array to a Vt100 monitor (simulated at the mo), everything has been working great untill I wanted to print an array. It's almost as if the array has been nulled. See code.
Any help sorting this out would be most appreciated..
There is sommit wierd going on.
Thanks :)
As I am not sure, I looked into Help:
Maybe you are not allowed to store Strings in Arrays ?
Hello Phil,
try this line:
Dim country(0),country(1),country(2),country(3),country(4),country(5),country(6) as String * 15
for your line:
dim country(8) as String * 15
You mix up two dim commands, the 8 in your command has to do with the size of the array but not with the number of strings (in this case with the name country)
I understand that this is a littlebit weird because in other Basic languages the implementation of the Dim command is different.
Last edit: Theo 2018-08-29
as addition:
it is not allowed to use the number in your string as index in a loop or a for-next construction.
This not allowed:
For index = 0 to 6
print country(index)
next
BUT this work:
Select Case index
Case 1
print country(1)
Case Else
print country(0)
Give it a try.
Theo.
Hi Theo,
Yup tried your suggestion but to no avail im afraid.
Dim country(0),country(1),country(2),country(3),country(4),country(5),country(6),country(7),country(8) as String * 15
etc
HSerPrintStringCRLF country(0)
etc
still nothing
I am using a pic18f47k42, would that make a difference..
Hi Theo,
If i was to use the select case scenario then i might aswell use:
and do it that way. and abandon the array altogether.
Of course, if you only need to print a string and no further calculations or so than go for it!
This looks like a casting issue where currently the passing of the string array as a parameter is not passing the string but the first byte value of the string array.
So, use the 'select case' as a workaround.
Hi Theo,
Well I think thats pretty poor of GCbasic where it can't handle string arrays. Even the Oshonsoft can do it quite seemlesly, but unfortunately it cant handle the pic chip in question.
Actually I would be surprised if Great Cow, or any other BASIC, supported String arrays on 8 BIT PIC's.
If you look at the architecture used in the PIC Core there is very little address space allocated to RAM and that available RAM is segmented.
The example code you posted would require 144 Bytes of RAM just to store the array data, I don't think many 8 Bit PIC's have that much contiguous RAM, in fact not many PICs even have that much RAM in total.
Then you have all the working storage needed by the compiler and any other functions you use, such as the serial communications, and you begin to see the problem.
PIC's are fantastic devices for interfacing with hardware and the real world environment. They have a vast array of device independent peripherals available, but they are NOT Computers based on Von Neumann Architecture, they are Interface Controllers based on Harvard Architecture.
As Such they are not intended to manipulate RAM hungry applications like Strings and Floating Point Mathematics.
If Strings are Important to you I would suggest that you use an ATMEL device based on the 8051 core rather than a PIC. But if you want to design and build Controller hardware then the PIC is first choice.
Just My 2c,
Cheers,
Chris
Last edit: Chris Roper 2018-08-29
@Phil. Great Cow BASIC does support string arrays. I think, as I have not confirmed, you have discovered an issue. I will investigate and resolve.
Thanks Anobium, trust me to find a bug.. I'm not even that a good a programmer.. LOL
@Cris, I see where you are coming from with pic chips having limited RAM, which is why I chose the 18F47K42 as it has 128K flash and 8K of RAM which is plenty for my purposes, oh and it runs at 64Mhz, which is quite nippy I think for most things.
I fall on my virtual sword. Handling of arrays of any type other than byte needs to be improved.
Use the Select-Case or Tables to create solutions until we have improved.
Hi Anobium,
I think its just select case, as looking as the table's help it says it does not handle strings or decimals.
Stick with the Select-Case. I have routines to automatically create string tables etc etc. I will post a demo when I get time... which I wont for a some time.
Hello Phil,
studying your first question again I have the following question:
because the command HSerPrintStringCRLF is relatively new, have you tried to use the old command HSerPrint instead?
Do you get the same error(output) as before; if so than the problem is probebly caused by the string variable country(x).
Hi Theo,
I have tried with HserPrint also and it did print zero's, but if you read a little further down, Anobium has found there to be bugs which stops string arrays. Which he is now investigating.
Thanks for the suggestions though. :)
I tried the code on a 328 uno and get
@Guys. Please.....
Handling of arrays of any type other than byte needs to be improved. It is not going to work.
Use the Select-Case with the same strings to create solutions until we have improved the compiler.
In gcb arrays start as array(1) as 1st element , not 0.
country(0) = " CHINA " try country(1) = " CHINA " and so on. Not the problem though.
hserprint Len (country(1)) doesn't work either.
gcb doesn't do multi dimentioned arrays .. which I suppose string arrays are,the chars are just numbers.
Assuming plenty of ram and all countries same length, a string can be 255 chars,
country(n) in the string would be mid(county,n*15+1,15)
Handling of arrays of this string type needs to be improved.
Use the Select-Case with the same strings to create solutions until we have improved the compiler.
This works
@Stan. Clever. :-)
The chip arrived and works. Uno to terminal version.