Cruisers Forum
 

Go Back   Cruisers & Sailing Forums > Seamanship, Navigation & Boat Handling > OpenCPN
Cruiser Wiki Click Here to Login
Register Vendors FAQ Community Calendar Today's Posts Log in

Reply
  This discussion is proudly sponsored by:
Please support our sponsors and let them know you heard about their products on Cruisers Forums. Advertise Here
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 26-01-2023, 06:39   #1
Moderator
 
Pete7's Avatar

Cruisers Forum Supporter

Join Date: Aug 2009
Location: Solent, England
Boat: Moody 31
Posts: 18,466
Images: 22
JavaScript Plugin V2 Thread (after 25 Jan 23)

This is a continuation of the previous thread which became outdated. Should you wish to view the previous JavaScript Plugin Thread it can be found here:

JavaScript Plugin Thread
Pete7 is offline   Reply With Quote
Old 26-01-2023, 08:28   #2
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
JavaScript Plugin v2

The JavaScript plugin allows you to run JavaScript in one or more consoles and to interact with OpenCPN.
The manual page is available here.

Version 2.0 of the plugin is now available. It has many improvements to make it easier to use, especially with multiple consoles/scripts. There is now a built-in Help page with links to the documentation. Please consult this before raising queries.

When I am on passage, I usually have three scripts running and use a fourth between cruise legs. The screen got a bit cluttered. Now this is much easier and you can avoid cluttering the OpenCPN canvas by parking the consoles out of the way.

There are full details of all new features in the updated Users Guide. In summary:

Load script
The plugin now keeps a list of the ten most recently loaded script files.
Load now displays a dialogue in which you can select a file from the list or you can choose Other... which opens a file selection dialogue.
You can also move a recent file to a list of favourites, which will always be offered, or you can remove a favourite.

Consoles
  • The script and output panes are now more flexible and better optimise their space, including when resized.
  • The splitter sash between the script and output pane now shows adjustments while being moved.
  • Consoles can now be reduced to a minimal size just showing the console name.
  • Consoles can be parked in the frame top bar using the Park button. A script can park its own console or another console.
  • The parking page of the tools allows you to set your own parameters for console parking, including the location of the park.
  • The consoles page of the tools now allows you to change the name of a console.

Extended API
readTextFile(fileString) - fileString can now be a URL and text will be read from that location, if OpenCPN is on-line.

New APIs
  • onContextMenu() - create context menu item and handle it with a function. Opens many possibilities!
  • consoleName() - set the console name from a script
  • consolePark() - park this or another console
  • messageBox() - display message and wait for a response
  • OCPNsoundAlarm() - sound alarm

Other
  • JavaScript engine updated from v2.5.0 to 2.7.0. Performance improvements and bug fixes only.
  • OCPNpushNMEA( ) now checks the sentence starts "$.....,"
  • Extensive rationalisation of plugin code, especially regularising processing after execution of some JavaScript. Whether or not an onExit script is called has changed and is now documented.
Antipole is offline   Reply With Quote
Old 15-04-2023, 01:59   #3
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
JavaScript Plugin updated to v2.1

The v2.1.4 update is for OpenCPN v5.8 and later. It is not relevant to earlier versions of OpenCPN.

OpenCPN uses wxWidgets 3.2. This has changed the behaviour of windows, particularly for MacOS. This version of the plugin has reworked its windows management to take this into account.

Console parking
Parking is now relative to the screen and no longer relative to the OpenCPN frame.
Parking now holds good when entering or leaving full screen mode.

Keeping the consoles on top
The consoles and the tools are now floated on top of the OpenCPN frame rather than on top everything. Other applications can overlay them.
For those who prefer that the consoles do not stay on top of OpenCPN, there is an option in the Consoles tab of the plugin tools to turn this off.

Getting GUIDs
Prior to this version, getting the GUIDs of waypoints, routes or tracks returned them all, regardless of whether they were 'ordinary' ones or in a layer. There was no way of distinguishing between them.
Now, by default, layer GUIDs are not included. This is a change in behaviour. You can request layer GUIDs or both types as an option.

Routes
The route attributes now include the route description and its visibility and these can be updated by a script.

Windows scaled displays
MacOS automatically manages screen resolution. On other systems, such as Windows, the screen resolution has to be taken into account. The plugin now makes the necessary adjustments.

See the Help tab of the Tools for reporting of any issues.

[As of 15th April, the plugin for Flatpak is still on v2.1.3 in which there is no screen scaling. It will be updated as soon as an issue can be resolved.]
Antipole is offline   Reply With Quote
Old 21-04-2023, 01:21   #4
Registered User
 
Gilletarom's Avatar

Join Date: Mar 2010
Location: France
Boat: 10.50 mètres
Posts: 2,989
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

Hello Antipole,

Now with version 2.1.4b and the latest O5.8.0-408+1f9896d from a few hours ago in Bdbcat's cloudsmith, JS is installing and it seems everything is working.

BUT, why is it impossible to translate JS, in Crowdin, into other languages and in particular into French?
Gilletarom is offline   Reply With Quote
Old 21-04-2023, 01:49   #5
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

Quote:
Originally Posted by Gilletarom View Post
Hello Antipole,

Why is it impossible to translate JS, in Crowdin, into other languages and in particular into French?
This issue has been raised before. Please see the discussion starting here.

In brief, while Crowdin could be used to translate the strings in the plugin, this would not change the fact that the JavaScript engine uses English and would not be translated - nor would the various scripts be translated. So you would end up with an unpleasant mix of English and other languages.

I know there is a tendency for English speakers to expect others to speak English. I am not among them, having lived abroad and worked in German. When abroad I should, ideally, speak the language of my hosts.

However, in the case of this plugin, you need to work in English. I am not willing to embark on translating and maintaining not just the plugin but the JavaScript engine and the scripts library. It is all open source. So if you would like to undertake this, you are very welcome to give it a go.
Antipole is offline   Reply With Quote
Old 21-04-2023, 03:37   #6
Registered User
 
Gilletarom's Avatar

Join Date: Mar 2010
Location: France
Boat: 10.50 mètres
Posts: 2,989
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

Ainsi va OpenCPN ..... Evidemment, si un fichier de langue était proposé dans le Crowdin, je me ferai un plaisir à le traduire en Français et même en Italien. D'autres le traduirait en d'autres langues .....
Gilletarom is offline   Reply With Quote
Old 21-04-2023, 04:13   #7
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

Quote:
Originally Posted by Gilletarom View Post
Ainsi va OpenCPN ..... Evidemment, si un fichier de langue était proposé dans le Crowdin, je me ferai un plaisir à le traduire en Français et même en Italien. D'autres le traduirait en d'autres langues .....
Le moteur JavaScript, l'API du plugin et les scripts ne sont pas compatibles Crowdin. Ce serait beaucoup plus compliqué à traduire.
Si vous souhaitez entreprendre cela, ouvrez un sujet où je pourrais vous donner quelques conseils. Mais ce serait une entreprise énorme.
Antipole is offline   Reply With Quote
Old 21-04-2023, 06:11   #8
Registered User

Join Date: Jan 2011
Location: France/UK
Boat: Gib'Sea 402
Posts: 547
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

To get back to English, if you translate the JavaScript code it is no longer valid JavaScript and won't run on anything supporting that language. Don't even think about it!
I guess you could translate any inline comments, but to help who? Any user wanting to develop their own code will have to be able to use the language in English anyway.
hoolie is offline   Reply With Quote
Old 13-10-2023, 07:12   #9
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
JavaScript plugin and Signal K

It is desirable that the JavaScript plugin can be used to work with Signal K. Given the close relationship of both Signal K and JavaScript with JSON, this should be relatively easy to do and use.

I do not have a Signal K set up and am away from my boat for the winter. So I am hoping SKS will work with me to establish this capability. If you are interested in helping with this work, please look at this enhancement issue I have raised.
Antipole is offline   Reply With Quote
Old 15-11-2023, 09:11   #10
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
JavaScript Plugin and Signal K

OpenCPN receives the Signal K messages it is interested in.

Using the JavaScript plugin, it is possible to process any Signal K data, including bits of it not normally made available by OpenCPN. A demonstration script is available here.

I do not use Signal K, so this is just a demonstration in principle. The user needs to adapt this for actual needs.

I am interested in whether it would also be possible to send Signal K data but have no idea what would be meaningful and have no means of testing it. If some Signal K user would like to work with me to test this, please announce this on the plugin issue here.
Antipole is offline   Reply With Quote
Old 01-04-2024, 09:47   #11
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
JavaScript Plugin V3.0 Released

V3.0 of the plugin is a major update, bringing new capabilities in eighteen areas, including
  • NMEA0183 data can now be listened for by message type and can be pushed out to a specific connection
  • NMEA2000 data can be received and sent. Binary data can be decoded or encoded for any PGN which has a PGN descriptor in the Canboat library. This is independent of decoding built into OpenCPN.
  • File handling - ability to read, write or update text or binary files of any size
  • Centering the canvas and adjusting the zoom level
  • Storing script preferences in an enduring variable
  • Copying to or from the clipboard
  • Parsing formatted positions
More details are in the release notice and full details are in the updated User Guide.

Huge thanks to Mike @rasbats for testing on Linux and for days getting it working on Windows.

Detailed discussions on the plugin discussions forum.
Antipole is offline   Reply With Quote
Old 13-04-2024, 04:26   #12
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
Proposed change to the NMEA2000 object

If you are using or interested in the NMEA2000 JavaScript object constructor, which is part of the plugin v3, please look at this poll about a proposed change.
__________________
If all else fails, read the instructions.
Antipole is offline   Reply With Quote
Old Yesterday, 17:50   #13
Registered User

Join Date: May 2023
Location: Auckland, New Zealand
Boat: Young 88 9m
Posts: 16
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

Hi Antipole,

Thank you for the huge amount of work and time you've obviously dedicated to this cause, I stumbled across your plugin when trying to figure out how to create many routes from a list of waypoints. Our yacht club lists 22 race courses so being able to create the routes automatically would save time, of course I could have entered them manually by now compared to the amount of time I've spent researching this but coding is fun and next time it will be easy :-)

I have a question which I'm sure the answer is pretty obvious I just can't see it...- The user guide has a link to getcode but this is not enabled in the pdf version - is there another way to view the userguide and/or get the code?

I've installed the JavaScript plugin and have managed to list waypoints and guids, I'm not familiar with JavaScript itself but I have a coding background so it's not too difficult. The aha moment was when I came across Build race course in Appendix F of the user guide, this is exactly what I need. However I cant figure out how to implement it.

Thanks in advance!
Jeremy
Jeremy 5426 is offline   Reply With Quote
Old Yesterday, 20:43   #14
Registered User

Join Date: May 2023
Location: Auckland, New Zealand
Boat: Young 88 9m
Posts: 16
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

I've made some progress in that I downloaded the user guide pdf and then the getcode link works, i copied the code into the js console in opencpn and it crashes when run. I notice the code is 3 years old, should it still work on the latest version of ocpn? I'm running 5.8.4.1.

thanks
Jeremy 5426 is offline   Reply With Quote
Old Yesterday, 23:47   #15
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 287
Re: JavaScript Plugin V2 Thread (after 25 Jan 23)

Quote:
Originally Posted by Jeremy 5426 View Post
I've made some progress in that I downloaded the user guide pdf and then the getcode link works, i copied the code into the js console in opencpn and it crashes when run. I notice the code is 3 years old, should it still work on the latest version of ocpn? I'm running 5.8.4.1.

thanks
Thanks for your appreciation.

Relieved you have working links in the guide. I have been assuming that is the case for everyone.

I have just downloaded the race course script and it starts fine for me - displaying the initial dialogues.

Best would be if you ask for further help by starting an appropriately titled discussion (maybe a 'question') on the new JavaScript discussions forum here. Please give details of exactly what happens and the message. If the script is throwing an error, open the Tools -> Diagnostics and select Dump. This will open a separate window with dump information and includ the dump text, which will tell me about your installation and platform.

I am now away from home recommissioning Antipole in Norway and only have a small screen and occasional Internet access. So there may be delays before I can respond.
__________________
If all else fails, read the instructions.
Antipole is offline   Reply With Quote
Reply

Tags
plug, plugin


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript Plugin Antipole OpenCPN 75 26-01-2023 06:47
JavaScript Plugin for OpenCPN? Antipole OpenCPN 2 16-02-2022 06:44
Winlink Express problems with GRIB map and Javascript Slow Boat To... Marine Electronics 0 29-04-2017 14:23
Driving Revenue JavaScript S/V_Surya Forum Tech Support & Site Help 22 06-04-2011 12:26
After Some Friendly Advice, Please - Jan 2011 Caribbean Charter Greg Bader Atlantic & the Caribbean 14 22-07-2010 11:30

Advertise Here


All times are GMT -7. The time now is 17:38.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.