Programming error on the physical calculator only
08-31-2014, 02:38 AM
Post: #1
 gabrieljcs Junior Member Posts: 18 Joined: Apr 2014
Programming error on the physical calculator only
I'm a newbie to the HP Prime (and programming itself), so I wrote a little snippet to better learn its programming language. Since I use Linux, I've installed the emulator and Connectivity Kit on a VM, and wrote the code there. The problem is my VM won't find the calculator, so I had to type it directly to my physical calculator.
But when I try to verify it, it gives me the following errors (works fine on the emulator, though):

EXPORT MOUSEDISPLAY(CSIZE)
BEGIN
LOCAL X,Y;
RECT;
REPEAT
X := MOUSE(0);
Y := MOUSE(1);
IF ((MOUSE(0) != X) OR (MOUSE(1) != Y)) THEN
RECT;
TEXTOUT_P("X: " + RIGHT(LEFT(STRING(SETBASE(X,| 3)), 4), 3) + ", Y: " + RIGHT(LEFT(STRING(SETBASE(Y, 3)), 4), 3), 110, 220, 4, #000000h);
LINE_P(X - CSIZE,| Y, X + CSIZE, Y, #FF0000h);
LINE_P(X,| Y - CSIZE, X, Y + CSIZE, #FF0000h);
END;
UNTIL GETKEY == '4';
END;

Software version: 2014 3 31 (6030) A
Emulator is 6031. I can't update because, as said before, I'm running Linux and the VM doesn't recognize my calculator.

What am I missing?
08-31-2014, 08:33 AM (This post was last modified: 08-31-2014 09:25 AM by jebem.)
Post: #2
 jebem Senior Member Posts: 1,234 Joined: Feb 2014
RE: Programming error on the physical calculator only
Did you try to delete those 3 extra "|" symbols in the physical HP Prime editor?

I have the same software and firmware versions and it passes the validation with no errors. I have:
-started the HP Connectivity kit;
-started the HP Prime virtual calculator (Rev. 6031);
- connected the HP Prime machine (s/w 6030) into a USB port on my PC (both calculators appears in the HP Connectivity kit inventory;
-copied your posted text program into a new program named "MOUSEDISPLAY" in the HP Prime virtual calculator;
- got the same errors as you report, but after deleting the extra "|" symbols it was ok;
-drag and drop the HP Prime virtual calculator "MOUSEDISPLAY" program into the HP Prime Programs folder;
- on the HP Prime machine went for Programs, Edit, Check and got no errors.

My Prime setup is:
HP Prime in Function App, Home mode, setting Radians, number format standard, digit grouping 123456.789, entry textbook, integers Hex 32, Complex a+b*i checked.

EDIT:
Concerning the VM problems not seeing the physical Prime:

1. There are some issues reported by many people with the way the HP Connectivity kit handles the USB interface, even without involving virtualization in the process: Not every USB port is compatible with the HP software, so I would recommend to use another USB port (USB v3 can give issues; also USB hub ports can be a problem if they are powerless);

2. If running Windows inside a VM, I would recommend VMware Player 6 (freeware) for Linux, as it can redirect the physical USB port to the VM's USB virtual h/w device to be presented to the Guest OS; if you have the time to try it, maybe you would like to check the following links:
Using VMware Player
VMware Player documentation
VMware KB: Automatically connecting USB devices at virtual machine power on (1648)

P.S. - Aquele Abraço!

Jose Mesquita

08-31-2014, 02:07 PM (This post was last modified: 08-31-2014 02:09 PM by gabrieljcs.)
Post: #3
 gabrieljcs Junior Member Posts: 18 Joined: Apr 2014
RE: Programming error on the physical calculator only
I used those "|" symbols only to show where the cursor goes when I check the syntax. I then comment the line with the error and check again, so it can show me all the errors.

I'm using VMware Player, I'll try to change the USB port.

On another program I made I get odd errors too, e.g.:
Code:
EXPORT ...() BEGIN LOCAL R, S, T;  // error here ... END;

Code:
EXPORT ...() BEGIN LOCAL R;  // no errors LOCAL S; LOCAL T; ... END;

Sometimes it handles the commas (like my first post), sometimes it doesn't. What the hell?

EDIT: Maybe it's worth saying that I'm using Portuguese as language.
08-31-2014, 02:23 PM
Post: #4
 Tim Wessman Senior Member Posts: 1,830 Joined: Dec 2013
RE: Programming error on the physical calculator only
I am not seeing errors with local like you are saying with your examples. Now if you have more then 8 locals on 1 line you would see that since the limit to any single function internally is 16 arguments.

TW

Although I work for the HP calculator group, the views and opinions I post here are my own.
08-31-2014, 02:40 PM (This post was last modified: 08-31-2014 02:58 PM by jebem.)
Post: #5
 jebem Senior Member Posts: 1,234 Joined: Feb 2014
RE: Programming error on the physical calculator only
(08-31-2014 02:07 PM)gabrieljcs Wrote:  On another program I made I get odd errors too, e.g.:
Code:
EXPORT ...() BEGIN LOCAL R, S, T;  // error here ... END;

Code:
EXPORT ...() BEGIN LOCAL R;  // no errors LOCAL S; LOCAL T; ... END;

Sometimes it handles the commas (like my first post), sometimes it doesn't. What the hell?

EDIT: Maybe it's worth saying that I'm using Portuguese as language.

EDIT: I see that the correct answer was given by Tim.
I'm not sure what can cause that behavior, maybe some other folks here with a better understanding of this calculator can help you.

On my calculator I can define those variables from your specific example using the two syntax modes without issues.

You are declaring the built-in system global real variables (A,..,Z) in your code as local scope vars.
While this should not create any problems, can you try to use local variables defined with custom names like "Res" or "Sur" instead of "R" and "S" to see if it behaves differently?

Also, may I recommend these two small excellent articles from Han that may help here:
HP Prime Programming: Variable types and their priorities
HP Prime Programming: An Introduction

And Joe Horn has published a list of reserved names that should not be used to name user defined variables (just in case...):
Reserved Variables on the HP Prime

Jose Mesquita

08-31-2014, 03:01 PM (This post was last modified: 08-31-2014 03:19 PM by gabrieljcs.)
Post: #6
 gabrieljcs Junior Member Posts: 18 Joined: Apr 2014
RE: Programming error on the physical calculator only
Ok, I managed to connect it by changing the USB. First thing the Connectivity Kit asked was to update the firmware. I said "Yes", it gave me an error (104) and I'm now stuck on the recovery mode.

EDIT: Ok, I'm seeing in a lot of other threads that I'd need to run updater.exe. The problem is I still get the same error. I don't really want to install Windows just for that, and I'm pretty sure the update didn't start (no progress bar was shown). Is there a way to just reboot it in normal mode? Is it safe to reset it from the button on the back? Remove the battery, perhaps? I also read that the Connectivity Kit is completely brick-safe because it doesn't mess with the boot loader. So, if I reset it I'll still be able to at least enter to Recovery Mode, right?
08-31-2014, 03:17 PM
Post: #7
 jebem Senior Member Posts: 1,234 Joined: Feb 2014
RE: Programming error on the physical calculator only
(08-31-2014 03:01 PM)gabrieljcs Wrote:  Ok, I managed to connect it by changing the USB. First thing the Connectivity Kit asked was to update the firmware. I said "Yes", it gave me an error (104) and I'm now stuck on the recovery mode.

That can be caused by USB connectivity issues, as I mentioned before.
Why did you update your unit?

Anyhow, plenty of information to reset your calculator in this forum (be aware that by doing this procedure you can expect the worst case scenario concerning your data and programs - it will wipe the calculator to factory reset):

1. Press and hold down the 3 keys letters "C", "F" and "O".
2. While holding the CFO keys, use a paperclip into the RESET hole in the back of the Prime.
3. The diagnostic menu will show up and now you can release the CFO keys.
4. From the Menu, use key 4, then key 3, and then Enter. This will reset the calculator to factory defaults.
5. Wait for the next menu and press Esc key and at last the key 9.

Jose Mesquita

08-31-2014, 03:29 PM
Post: #8
 gabrieljcs Junior Member Posts: 18 Joined: Apr 2014
RE: Programming error on the physical calculator only
GOD BLESS YOU, jebem!

Your instructions worked flawlessly. Thanks a lot! I'll rewrite the programs and see if I keep getting those errors.
08-31-2014, 03:40 PM (This post was last modified: 08-31-2014 03:40 PM by jebem.)
Post: #9
 jebem Senior Member Posts: 1,234 Joined: Feb 2014
RE: Programming error on the physical calculator only
(08-31-2014 03:29 PM)gabrieljcs Wrote:  GOD BLESS YOU, jebem!

Your instructions worked flawlessly. Thanks a lot! I'll rewrite the programs and see if I keep getting those errors.

DEUS é grande, meu amigo! (GOD is great, my friend!)

But the credits go to Joe Horn, Han, Tim and others experts from this forum, I just try to learn a little from them

Jose Mesquita

08-31-2014, 03:47 PM (This post was last modified: 08-31-2014 03:49 PM by gabrieljcs.)
Post: #10
 gabrieljcs Junior Member Posts: 18 Joined: Apr 2014
RE: Programming error on the physical calculator only
Ok, I renamed the variables but still get the odd behavior. I'm pretty sure I'm missing something really dumb, because this doesn't make sense.

Code:
EXPORT TamanhoMantissa() BEGIN   LOCAL SIZE, AUX0, AUX1;   SIZE := 20;   REPEAT     SIZE := SIZE + 1;     AUX0 := 1/2^SIZE;     AUX0 := AUX0 + 1;     AUX1 := AUX0 - 1;   UNTIL AUX1 == 0;      MsgBox("O tamanho da mantissa é de " + SIZE + " bits");   RETURN SIZE; END;

Attached File(s) Thumbnail(s)

08-31-2014, 04:03 PM (This post was last modified: 08-31-2014 04:05 PM by jebem.)
Post: #11
 jebem Senior Member Posts: 1,234 Joined: Feb 2014
RE: Programming error on the physical calculator only
(08-31-2014 03:47 PM)gabrieljcs Wrote:  Ok, I renamed the variables but still get the odd behavior. I'm pretty sure I'm missing something really dumb, because this doesn't make sense.

Code:
EXPORT TamanhoMantissa() BEGIN   LOCAL SIZE, AUX0, AUX1;   SIZE := 20;   REPEAT     SIZE := SIZE + 1;     AUX0 := 1/2^SIZE;     AUX0 := AUX0 + 1;     AUX1 := AUX0 - 1;   UNTIL AUX1 == 0;      MsgBox("O tamanho da mantissa é de " + SIZE + " bits");   RETURN SIZE; END;

Achei!
I believe I found the problem.
Maybe you are using the comma "," as the decimal separator...?

I ask this because if I choose "Agrupamento de dígit" = 123456,789 from the Home Settings, I get your Prime behavior.
And this is not a problem with the Prime Language settings, it will happen in English as well.

This looks like a "bug" to me, but maybe Tim can give some extra information here.

Jose Mesquita

08-31-2014, 04:28 PM
Post: #12
 Thomas_Sch Member Posts: 284 Joined: Dec 2013
RE: Programming error on the physical calculator only
You could try to add the special '#pragma' feature to your programs.
Code:
#pragma mode( separator(.,;) integer(h64) )