Serial plugin, questions

Questions regarding plugin development and publish plugins

Serial plugin, questions

Postby ogaland » Sun Apr 14, 2019 4:29 am

Hello,

I ordered my goverlay screen and i'm happy of this, it work like a charm, but I would like to monitor custom sensors.
I would need any advice to make the work easier, I posted in plugins sections, as I guess I must write a plugin for that.

Application is to display water temperature, and flow value on a dual-loop watercooled computer.
To be short the 4 customs sensors (2 temp and 2 waterflow) will be plugged to an arduino and communication with PC will be done using the COM port.
(simplest way I found to solve the issue as I can't directly plug the sensor on the motherboard)

For this I'm currently working on an arduino sketch, I'm currently able to display water temperature, and I'm working to read correctly water flow sensor.
I did a very basic interface on COM port which can return datas on releveant commands (which i can customize on will) :

Example : Send GET on COM port will return the sensors current values like : FLOWA:0.00|FLOWB:0.00|TEMPA:26.73|TEMPB:26.94

I did a quick look on current plugins and I guess it would be possible to make it work (hwinfo plugin seems to retrieve new sensors from an external application, this looks like close to what i want to do)

All I need would be to create a basic application on the PC that will query the arduino and provide data to the goverlay plugin.
But which method could I use ? Storing values in a file ? hwinfo plugin (I checked very quickly) seems to use a MemoryMappedFile (I don't know that), is it the good way of doing it ? any alternate way ?

Thanks for reading me.

Olivier,France
Last edited by ogaland on Sun Apr 21, 2019 4:29 am, edited 1 time in total.

ogaland
 
Posts: 4
Joined: Sun Apr 14, 2019 4:00 am

Re: Arduino plugin, questions

Postby ogaland » Mon Apr 15, 2019 3:31 am

Replying to myself after some work on that dev.

Looks like I missed the easy solution : do the COM connection inside the plugin. After reading plugin doc and checking a few example, it seems to work well. I can display the data gathered by the arduino on goverlay.

I will probably publish the result once I have sorted and cleaned my mess, I don't know if many people would have the same need.

ogaland
 
Posts: 4
Joined: Sun Apr 14, 2019 4:00 am

Re: Arduino plugin, questions

Postby TheLaGmAn » Wed Apr 17, 2019 1:04 pm

Yes, you can make a plugin and connect directly to the com port, that should work.
Other alternative is to make a separate windows application that would write to a .INI file and use goverlay to load the data from the file, but you would need this additional app to be running along with GOverlay, its better to use a plugin if you can make one.
If you will make it and pubish it, let me know if you get stuck with anything and i can give you a hand.
User avatar
TheLaGmAn
Site Admin
 
Posts: 967
Joined: Wed Feb 26, 2014 8:32 pm

Re: Serial plugin, questions

Postby ogaland » Sun Apr 21, 2019 5:04 am

Hello TheLaGmAn

Thanks for your answer, I also saw you did the work on the HWInfo plugin, congrats as I use it to display my computer sensor (OpenHM unfortunately don't detect them) and I took lots of inspiration from it to write my plugin.

I created a github repository with the project, feel free to have a look and add any comment on change I could/should do. https://github.com/OlivierGaland/Octave
I'm partially satisfied with the result, the plugin option allow to choose COM port/speed/timeout, there is also an option to select refresh rate for the query/request on COM port (I was not sure It would handle 1 trx/sec).

My main questions are about how to deals with all the possible use case regarding the COM connection (cannot open at start, com connection temporarly loss during session, change plugins options) and as I never developped under VBnet I have no expertise on the possible solution.

I tried several use case like unplugging the arduino during use, changing options that need to restart the COM connection, and went for the following logic :

- Create the COM connection when AvailableSensors is called and keep the object (pluginsOptions available here)
- Check if connection need to be restarted (com port number change or speed change ...) in ... DisplayOnLCD (!) (as pluginsOptions is available here, I would have prefered to do it in Callback, but iI cannot grab pluginsOptions in this call)

I also need for each COM exchange to disconnect after to prevent error if I stop goverlay abruptly and restart it, or change options, so any COM exchange is enclosed in a Connect (that check is the connection is opened) then a Disconnect. (I don't like that but I din't find another way)

Here is currently the final result on LCDsys 3"5 (the arduino sensor are visible at the bottom (water temp -implemented- and water flow -pump are actually not running as the computer is currently under construction-)

Image

ogaland
 
Posts: 4
Joined: Sun Apr 14, 2019 4:00 am

Re: Serial plugin, questions

Postby TheLaGmAn » Wed Apr 24, 2019 12:22 am

Looks very good and thanks a lot for sharing.

You shouldnt need anything on the function "DisplayOnLCD" since its only called when the sensor is a custom draw one, and all sensors are not custom drawing.

On every run, if at least one sensor of your plugin will be used, the callback with "willrequestvalues" will be called, this is where you should connect/fetch values and save them into memory, and i see thats what you are doing so that logic is okay.
On the first run or every time the user gets into the profile tabs, goverlay will call "AvailableSensors" to get the current sensors, so you also should intiate the connection here, as you do.

- Create the COM connection when AvailableSensors is called and keep the object (pluginsOptions available here)

This is correct, before doing anything goverlay needs to know the available sensors so this will be the first thing called.

- Check if connection need to be restarted (com port number change or speed change ...) in ... DisplayOnLCD (!) (as pluginsOptions is available here, I would have prefered to do it in Callback, but iI cannot grab pluginsOptions in this call)

Uhm, DisplayOnLCD shouldnt be called, are you sure your code is getting here?


To access the plugin options anywhere where you dont have the pluginOptions variable, use

Dim optionSpeed = objHost.AccessHost("retrieve", "plugin_options", Name(), "speed")
Dim optionPort = objHost.AccessHost("retrieve", "plugin_options", Name(), "port")
It shouldnt affect performance but its best if you grab this data not too often (ex on every sensor request), so you dont call goverlay a lot of times for this, but doing it once per draw is probably okay
User avatar
TheLaGmAn
Site Admin
 
Posts: 967
Joined: Wed Feb 26, 2014 8:32 pm

Re: Serial plugin, questions

Postby ogaland » Fri Oct 04, 2019 8:16 pm

Hello,

Sorry for long time without news. And thanks for the informations.
The computer is online since a few weeks and works fine.

However I noticed that on auto-start goverlay serial plugin fail randomly (consequence : sensor not displayed)

This issue can be fixed by manually shutting down goverlay and restarting it.
I strongly suspect this is due to windows startup procedure, in short the COM port may not be online when goverlay exe is started. (arduino must boot, and serial connection must init on usb input)
I tried to install a delay at startup (3rd party software) on goverlay and notice it works better if there is a wait (30sec for instance) before starting goverlay.
But there are still cases where it fails (went to 1min delay, which start to be long).

If you have any idea how to fix that ... I guess one would be to check for port availability with a max retry and a wait between each retry, but It should have an impact in the init procedure of goverlay (tiemout ? takes too long ?)

Regards,
Olivier

ogaland
 
Posts: 4
Joined: Sun Apr 14, 2019 4:00 am

Re: Serial plugin, questions

Postby TheLaGmAn » Sat Oct 05, 2019 5:52 pm

From what i see in your code, you have a check to open the connection if its not available on willrequestvalues, which is the correct place, that will be called on every goverlay render, so, as you do, you should connect or re-use the connection there.
My guess is that there is an issue somewhere in the code on which it throws an error and dies or at some point it doesnt try to reconnect.
Have you added some debug text in there, to ensure it goes over that function and tries to connect?
User avatar
TheLaGmAn
Site Admin
 
Posts: 967
Joined: Wed Feb 26, 2014 8:32 pm

Re: Serial plugin, questions

Postby Alexadam » Tue Aug 18, 2020 10:18 am

Thanks for posting about this, I would love to read more about this topic.

Alexadam
 
Posts: 1
Joined: Tue Aug 18, 2020 10:10 am
Location: Karachi, Pakistan


Return to Plugins Releases and Development



Who is online

Users browsing this forum: No registered users and 1 guest

cron