Post Reply 
Program "project" structure - how to use?
09-10-2023, 07:17 PM
Post: #1
Program "project" structure - how to use?
In the new program/project structure, you can have additional files with program code, graphic data (images), and binary assets. Does anyone know how to use it? Can such data only be read, or maybe is it possible to modify it as well (for binary assets)?
Tim mentioned such a possibility, for example, here: https://www.hpmuseum.org/forum/thread-19...#pid169882 and here: https://www.hpmuseum.org/forum/thread-16...#pid148289 but I can't find a single example anywhere. The only thing that worked for me was an additional file with source code (PPL/Python), but I can't reference the other types of files.
Tim?

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
09-10-2023, 07:51 PM
Post: #2
RE: Program "project" structure - how to use?
(09-10-2023 07:17 PM)komame Wrote:  In the new program/project structure, you can have additional files with program code, graphic data (images), and binary assets. Does anyone know how to use it? Can such data only be read, or maybe is it possible to modify it as well (for binary assets)?
Tim mentioned such a possibility, for example, here: https://www.hpmuseum.org/forum/thread-19...#pid169882 and here: https://www.hpmuseum.org/forum/thread-16...#pid148289 but I can't find a single example anywhere. The only thing that worked for me was an additional file with source code (PPL/Python), but I can't reference the other types of files.
Tim?

You're not the only one who's confused. I, too, have been looking for the instructions on how to build a module including multiple files, etc.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
09-10-2023, 08:06 PM (This post was last modified: 09-11-2023 03:27 AM by komame.)
Post: #3
RE: Program "project" structure - how to use?
I found the answer! When you're in the program editor, go to the "More" menu, and with "Files" highlighted, press the "Help" key. It will display description on how to use it. As you can see, there is a "Resource" command that allows you to reference these resources.

Resource
Resource("name")
Resource("name", pos)
Resource("name", start, end)
Resource("name"):={data}
Resource("name", start):={data}
Resource("name", pos):=data


So, this means that you can also modify these resources.
Perfect!

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
09-10-2023, 08:27 PM
Post: #4
RE: Program "project" structure - how to use?
I've tested it.
Unfortunately, it's not very stable (sometimes it causes crashes), but in some cases, it can be used. Tomorrow, I'll check it a bit more thoroughly and let you know what to watch out for.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
09-11-2023, 12:00 AM
Post: #5
RE: Program "project" structure - how to use?
Are you not talking about AAngle, ADigits, AFilesB, ANote, AVars, AFiles, AProgram etc, that are all described in the Manual? Would these App tools not do what you want anyway?
Find all posts by this user
Quote this message in a reply
09-11-2023, 05:12 AM (This post was last modified: 09-14-2023 05:48 PM by komame.)
Post: #6
RE: Program "project" structure - how to use?
What I'm talking about in this thread is a much younger mechanism than the application, but I don't think anyone has fully used it yet. Probably because no one thought to read the description hidden under the [Help] key when the |Files| item is currently highlighted in the |More| upward-expanding menu Wink
Tim mentioned this new mechanism several times, but he never showed an example, and no one knew what it was about (while there was some information about it in the beta notes, there's nothing like a good example of applying the new mechanism in some practical solution). The HP Prime app has its own icon, and you run it from the Application Librabry, while a "project" is something visible on the list in the Program Catalog. The resource mechanism allows you to store multiple files under one entry in the Program Catalog. For example, you can split one program into several PPL source code files (Python as well, but that's a slightly different story). This makes it easy to edit them because they are smaller and functionally divided, and during compilation, all of them are verified at once, not just the one currently open. In the project, you can also have graphic files. Additionally, binary files are also available, which can be edited directly on the Prime using hexadecimal codes. The files in a specific project are visible only to that particular project (similar to AFilesB, but here it pertains to programs in the Program Catalog), and they are not reset after using |Check|, so you can use them, for example, to save the current state of the program and then load it to continue its operation during the next run.

When you have multiple files within a project, you can switch between them (and create new files) while editing the program using the |More| => |Files| menu.
Of course, these additional files are also visible during program editing directly in the Connectivity Kit, where you can also manage these files.

Best regards,
Piotr

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
09-11-2023, 08:57 AM
Post: #7
RE: Program "project" structure - how to use?
Bonjour à nouveau

J'ai personnellement récemment réussi à intégrer une image, dans le logiciel de connectivité.
Il faut créer un fichier de type Jpg image.
Un icone de fichier apparaît au dessus de l'onglet.
En cliquant dessus on peut télécharger une image Jpeg.
Vous pouvez ensuite renommer l'onglet, mais pas avant.
Pour ensuite utiliser cette image dans vôtre programme, il suffira d'écrire
Gx:=Resource("nom de l'onglet").

Hello again

I recently managed to integrate an image into the connectivity software.
You need to create a Jpg image file.
A file icon appears above the tab.
By clicking on it you can download a Jpeg image.
You can then rename the tab, but not before.
To use this image in your programme, simply write
Gx:=Resource("tab name").

Sorry for my english
Find all posts by this user
Quote this message in a reply
09-11-2023, 01:58 PM (This post was last modified: 10-25-2023 06:58 PM by komame.)
Post: #8
RE: Program "project" structure - how to use?
The errors described below pertain to firmware 14730 and may be fixed in subsequent versions.

I conducted more detailed tests. In general, resource files can be created directly on the HP Prime, but sometimes it requires a bit of tinkering, and it's much more convenient to upload them using the Connectivity Kit. You can't create new resource files from the program, but you can modify them. The Resource() instruction (without argument) returns a list of all resource files along with their size and type.
Once a resource file is created on the HP Prime, you can't change its name, but you can copy it to another one with a different name.

Resource files for source code.
You can create additional PPL or Python files. So far, I haven't been able to refer to a program placed in a Python resource file (I tried in various ways, but I always received the message " '_name' is not defined "), so I won't describe it. If someone managed to call a subroutine from an additional Python file in a project, please share that information in this thread. However, an additional PPL file works without any issues, and I'll discuss that.

In the additional PPL file, you should place functions that you can reference from the main file. Each file can have its own #pragma settings, and when a PPL function is called from the main program, it will behave according to the #pragma settings of the file in which it's located. When it return from the procedure to the main program, the #pragma settings of the main program will apply again. This is intuitive and works correctly.
Syntax errors in PPL files are checked during "CHECK," and if there's a syntax error somewhere, the view is automatically switched to that file with the cursor set to the line of the code with the error.

I haven't found any bugs for PPL resource files, at least during my tests. However, that doesn't mean there aren't any. Still, everything worked stably during my tests.

Graphic files.
In the Connectivity Kit, there are three types of files to choose from: png, jpg, and bmp.
Resource files for graphic files can also be created directly on the HP Prime. It's important that the image you want to load into the resource is in G1.
For example, give the following commands in the HOME:
Code:
DIMGROB(G1,20,15,255); //put a blue rectangle into G1

Then create a new .png file in the project, and when you enter that file, choose LoadG1 from the menu. This will load the G1 image into the graphic resource you're in.

If you have a graphic resource, you can assign it to any graphic object G0-G9:
Code:
G1:=Resource("png1");

You can also copy graphic resources between each other:
Code:
Resource("png1"):=Resource("png2");
Unfortunately, such copying often works unstably and sometimes causes crashes. However, there is no problem using these graphic resources as read-only files, as in this scope it works stably and also allows for a significant reduction in the size of the program, especially if someone doesn't want to create a HP Prime App and uses ICON to store graphics within the program code.

Binary assets.
These files allow you to store any binary data, which you can access as lists of bytes. It's very similar to AFilesB.
Creating a file from the Connectivity Kit gives more editing options because you can enter data in both hexadecimal and decimal formats. You can also choose a 1-byte, 2-byte, or 4-byte input mode. If there's even one invalid code, the file simply won't go to the HP Prime, and no message will appear, so you need to verify the data thoroughly before entering it.
Unfortunately, binary assets are the most unstable part of this solution. Sometimes, creating files from the Connectivity Kit works, and sometimes it doesn't (often only the last byte makes it into the file).
Creating binary assets directly from the HP Prime works better, but in this case, you can only enter 1-byte hexadecimal values. Once you've created a binary file, you can change its content from the program, just like with AFilesB.

I've noticed a problem with reading binary asset files into a list.
For example if we have 3 bytes (hex) 010203 in the binary file "B1," you need to call the command to read all the file:
Code:
Resource("B1");
This should read three bytes, but an additional byte appears at the end (garbage).
result: {1,2,3,?} - the '?' is an extra byte that should not appear. It may have various random values.

One of the syntax options says: Resource("name", start, end), so let's try to force reading three bytes (which is the byte range from 0 to 2):
Code:
Resource("B1",0,2);
Result: {1,2,3} - and in fact, we read three bytes, without a garbage byte at the end, but we had to explicitly specify the range for it to work correctly.
However, there is also an issue with this syntax because if we request to read more bytes than are available in the resource, that additional byte will also appear.

So according to this logic, in the third parameter, we need to provide 1 in order to read two bytes:
Code:
Resource("B1",0,1);
Result: {1,2}

What if you want to read 1 byte? I don't know because when the 'start' is equal to the 'end', we receive an empty list as a result. This is a clear bug, at least for Resource("name", start, end) syntax.
As a workaround for reading a single byte, you can temporarily use a different syntax: Resource("name", pos). However, when working with byte ranges, you must use the syntax Resource("name", start, end), and when the range becomes one byte, you'll need to change the call to Resource("name", pos), which can be cumbersome because it requires continuous range length monitoring.

Of course, you can also modify these files:
Code:
Resource("B1"):={100,101,102};
Unfortunately, despite having several syntax options for modifying resources, the one mentioned above is the only one that works, as Resource("name", start):={data} and Resource("name", pos):=data always result in an 'Error: Invalid input'.

An important piece of information is that although resources behave like files, they are actually stored in RAM (so they are not files). This seems to be an interesting solution for storing various large amounts of data, rather than keeping them in the source code.

Tim, thank you for this solution. It seems to be great, but someone still needs to fine-tune it to make it fully functional.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 4 Guest(s)