Cruisers Forum
 


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 07-04-2022, 06:48   #61
3cp
Registered User

Join Date: Jul 2016
Posts: 10
Re: JavaScript Plugin

I never got the code from flyspray so i reply here.
I'm on windows 11 and OCPN 5.6.
If you look at the code above it works perfect until the OCPNpushNMEA(result); statement. OCPN seem to enter an infinite loop and after some time, crashes.
I wonder if it has to do with the checksum.
The exambles from the manual involving the same OCPNpushNMEA(result); statement, crashes the same way.
OCPN has made a crash log file (saying nothing about the error) but no crash report.
3cp is offline   Reply With Quote
Old 07-04-2022, 07:37   #62
Registered User
 
Antipole's Avatar

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

@3cp… I need the crash report/log, please.
I am away from my computer abroad and unable to test until the weekend. Your script looks valid although unnecessarily complicated.
Can you narrow it down to a simple

Code:
sentence = “$ABCDEF,…..”;
OCPNpushNMEA(sentence);
If so, let me have the sentence.
You can private message me to avoid cluttering this thread.

You are setting splut[1] to a number rather than string.
I need to know what the sentence is that you push.
You could try
Code:
splut[1] = direction.toFixed(4).toString();
Antipole is offline   Reply With Quote
Old 07-04-2022, 19:43   #63
Registered User
 
Antipole's Avatar

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

@3cp…. Still not been able to test myself, but I note that, as written, your script is pushing a sentence with the same HDG identifier as it received, and the script will probably process its own output and get into a loop, I suspect.

To avoid this, you should use a different sender ID So include, say,
Code:
splut[0] = “$JSHDG”;
And only process sentences with the original sender ID.

To stop your instruments getting confused, you should set OpenCPN to drop the sending of the original HDG sentence.
Antipole is offline   Reply With Quote
Old 08-04-2022, 07:09   #64
3cp
Registered User

Join Date: Jul 2016
Posts: 10
Re: JavaScript Plugin

I am allso away from my boat at the moment. I will try tha surgested things in a couple of days.
Thanks.
3cp is offline   Reply With Quote
Old 10-04-2022, 06:18   #65
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 286
JavaScript Plugin OCPNpushNMEA hang

@3cp... I have been able to confirm that, as written, your script causes a hang.
The issue is that the NMEA sentence pushed out is immediately processed by the script, which sends out another, ad infinitum, causing a loop I will add a warning to the documentation not to do this.

The solution is to use a different sender ID for the output and not process that on receipt. The following script processes only $HCHDG sentences but generates a $JSHDG sentence, which avoids the loop.

Code:
OCPNonNMEAsentence(processNMEA);

function processNMEA(input){
	if (input.OK){
		sentence = input.value;
		if (sentence.slice(0,6) == "$HCHDG")
			{
			splut = sentence.split(",");
			splut[0] = "JSHDG";
			splut[1] = splut[1] + 30;
			result = splut.join(",");
			print(result, "\n");
			OCPNpushNMEA(result);		
			}
		}
	OCPNonNMEAsentence(processNMEA);
	};
However, for this to be useful, the recipient instrument or process would need to only act on the modified sentence, which is out of the JavaScript plugin's control.

I understand you are trying to add deviation to your HDG sentence. The official place for this is in the next field, so your sentence should look like:

Code:
$JSHDG, 123.45, 30.0
Antipole is offline   Reply With Quote
Old 21-04-2022, 12:02   #66
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 286
Note on the JavaScript Plugin & Layers

This post documents a feature of OpenCPN that could be encountered by scripts if you are using layers. I will describe it here as seen in JavaScripts but it will apply to any plugin making the underlying API calls.

When a script requests all the GUIDs for waypoints or routes or tracks, it is given them all - including any in layers.

Although layers are said to be immutable, this is by design of the user interface rather than by inhibiting the APIs from making the changes. A plugin can in fact change a layer object and that will be reflected in the displayed chart. However, these changes are not saved when OpenCPN closes, so they will then be lost.

At present, there is no way for a plugin to distinguish between a layer object and a non-layer one. This can cause unwanted complications. For example, a layer might include many waypoints with the same name. This would be picked up by a script such as Housekeeper, which will offer to make them unique. It can do this but the fix will not last beyond an OpenCPN restart.

I have raised a FlySpray request FS#2864 for a future version of OpenCPN to allow a plugin to determine whether an object is in a layer. Please vote for this. Meanwhile, if you encounter this problem, a work around is to modify the data in your layer to include a flag in object names, such as '#Layer' and your script can check for that.
Antipole is offline   Reply With Quote
Old 19-05-2022, 05:24   #67
Registered User
 
rgleason's Avatar

Join Date: Mar 2012
Location: Boston, MA
Boat: 1981 Bristol 32 Sloop
Posts: 17,631
Images: 2
Re: JavaScript Plugin

@Antipole Tony, you had a page of messages that you thought should be in the Dev Manual. I have cloned the dev manual as Leamas suggested and am now ready to add the page. Where can I find the material?


PS Found it here https://www.cruisersforum.com/forums...ml#post3617132
rgleason is offline   Reply With Quote
Old 23-01-2023, 10:00   #68
Registered User
 
Antipole's Avatar

Join Date: Oct 2019
Location: Emsworth, UK
Boat: Alubat Ovni 395
Posts: 286
JavaScript plugin version 2.0 available

This update 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 accessed 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
  • 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
  • onContextMenu() - create context menu item and handle it with a function. Opens many possibilities!

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 24-01-2023, 08:19   #69
Registered User

Join Date: Nov 2012
Location: Steinhatchee, FL
Posts: 395
Re: JavaScript Plugin

This is a great plugin and I really like the ability to write one-off scripts to meet an immediate need.



Just one question: how do you close the last console when you are through?
__________________
Bill
"If I were in a hurry, I would not have bought a sail boat." Me
Be Free is offline   Reply With Quote
Old 24-01-2023, 08:40   #70
Registered User
 
Antipole's Avatar

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

Quote:
Originally Posted by Be Free View Post
This is a great plugin and I really like the ability to write one-off scripts to meet an immediate need.
Just one question: how do you close the last console when you are through?
You cannot close the last console by design - else you cannot open one without going via the panel in OCPN Setting.
You could toggle the icon in the toolbar, which will alternately hide or show all consoles. Alternatively, you can now park it in the frame's top bar. from where you can drag it back when next needed.
Antipole is offline   Reply With Quote
Old 24-01-2023, 09:06   #71
Registered User

Join Date: Nov 2012
Location: Steinhatchee, FL
Posts: 395
Re: JavaScript Plugin

Toggling from the toolbar works. I had not tried that. Is the parking in the top frame function in the version in the master catalog? I don't see how to do that with the version I'm running.


Thanks.
__________________
Bill
"If I were in a hurry, I would not have bought a sail boat." Me
Be Free is offline   Reply With Quote
Old 24-01-2023, 09:25   #72
Registered User
 
Antipole's Avatar

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

Quote:
Originally Posted by Be Free View Post
Toggling from the toolbar works. I had not tried that. Is the parking in the top frame function in the version in the master catalog? I don't see how to do that with the version I'm running.
It's in version 2.0, which is in the master catalogue. Maybe you need a catalogue refresh?
When you create an empty console, the version number is in the notional script that comes with a new console.
Alternatively, you can run the one-line script
Code:
print(OCPNgetPluginConfig(),"\n");
If you still have a problem getting the new version 2.0, I suggest raising an issue here to avoid cluttering this topic with trouble-shooting. Thanks.
Antipole is offline   Reply With Quote
Old 24-01-2023, 09:39   #73
Registered User

Join Date: Nov 2012
Location: Steinhatchee, FL
Posts: 395
Re: JavaScript Plugin

The PIM says 2.0.0d. The script says 1.1


I uninstalled and reinstalled. This is the output now (including your extra script).


Hello from the JavaScript plugin v2.0 2023:01:23 JS v20700
{"PluginVersionMajor":2,"PluginVersionMinor":0,"pa tch":0,"comment":"","ApiMajor":1,"ApiMinor":17,"wx Widgets":"wxWidgets 3.1.2","DuktapeVersion":20700,"inHarness":false}
result: undefined


I still don't see how to park the console anywhere.
__________________
Bill
"If I were in a hurry, I would not have bought a sail boat." Me
Be Free is offline   Reply With Quote
Old 24-01-2023, 09:47   #74
Registered User

Join Date: Nov 2012
Location: Steinhatchee, FL
Posts: 395
Re: JavaScript Plugin

Never mind. Found the "parking" button!
__________________
Bill
"If I were in a hurry, I would not have bought a sail boat." Me
Be Free is offline   Reply With Quote
Old 24-01-2023, 09:53   #75
Registered User
 
Antipole's Avatar

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

Be Free... please read the User Guide. It will save exchanges like this. Use the ? button top right to open the Help page which has links to the guide and other documentation.
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 for OpenCPN? Antipole OpenCPN 2 16-02-2022 06:44
OpenCPN PlugIn Development bdbcat OpenCPN 161 04-09-2019 12:50
Plugin development... How to receive chart objects in my plugin? dmartinez OpenCPN 6 04-08-2017 00:56
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

Advertise Here


All times are GMT -7. The time now is 23:47.


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.