Serial Port In WEB APP

I am hoping to do something very simple, I expected it to be very simple.

The goal is a web app on my house network to serve out the details of a weather station connected to the computer via an RS232 serial port.

in a desktop system this all works perfectly, no issue with the hardware to worry about.

I have messed about with this for many hours now and the solution that I expect to be so simple does not appear to be so forthcoming.
Yes I have searched the forum, some ideas have come up but none appear to resolve what appears to me to be an issue that must have been needed many many times previously.

all I wish to achieve is to have a stand alone web app on my computer that has a serial port connection to the weather station.
that GLOBAL serial connection collects data and loads an APP property with the data (a string) which each instance of the web app will read and display .

what seems utterly impossible is to have a serial port in the project, that serial port is initiated and connects to the hardware, it then downloads the data when the DataAvailable event fires, that data is loaded into the APP string that all sessions can view.

I can add the serial port to the MAIN window of the web app, it is opened up and the data is readable no problem, but obviously that connection is only available in the session that first runs, its not globally available, any subsequent session can not open the port (obviously) so show no data.

I simply need to be able to set the properties of a serial class and have the DataAvailable event accessible in a global method or event.

I have tried modules, classes APP level properties, addhandler, I can instantiate an instance of the serial port.
what I can not do is simply have a serial port instance that I can open up and sit waiting for the DatAvatlble event to fire.

Any ideas how to get a serial port initialised as if it were a global APP level control?

I’d have expected It to work at the app level.
I’m sure I’ve done this before, but I moved to serial over Ethernet so it’s a while back.

Did you disable any code in the session ?
because you can’t have it in both

Hi Russ,

it is a completely clean project, there is almost nothing in the whole project apart that required to compile.

I can instantiate the serial port, its visible to the project and autocompletes, but when I run it the setup, baud, port etc all bug out and the errors say that the port does not exist.

I can get the setup code to compile in some other way then the serial port DataAvailabel event does not fire as the control goes out of scope (I think).

it has to be a very simple matter of scope, I am amazed just adding the serial port to the APP does not allow it to be accessed in APP as a global control (I tried to set it up in the open event) but the IDE just says to does not exist, although it auto completes the name I give it.

tried a module, again code in APP it autocompletes but when compiling it does not exist.

I know I am doing something very wrong but I can not see what.

Thanks for the reply.

MAC, 19r11 API1 is the toolset.

There is no problem to setup a serial port (maybe you should think if there are side effects on using it)
Add the serial (api1) / serialConnection (api2) as property of your app or module
in a method (to setup) create the istance of your serial(Connection), add the events (addHandler) with the right signatures
Open the device and use the events.

It has no sense adding a serial device to a web page, you have no access to client serial devices. The only serial devices you a can use are the server ones.

Hi Antonio,
I will be trying this again today, I already think I have tried what you suggest.

the serial port is connected to the server, my local computer, I do not want to have to have a separate process to do the serial (which is easy) and then pass data between the web app and the serial container.

my expectation was just to add a serial port to the project as it is done in the desktop and all would work fine, this appears to not be the case.

In which part of the project you placed the serial port?
If you add a class or anything else at the application level it executes in the application and is totally independent from sessions and pages.

Thanks Maurizio,

I tried this, or so I thought, I had a module which would autocomplete but I could not get the serial port initialized from the app.

I am going to do some more tests tonight and make several code snippets to show the non working ways I have done things so the code is seen rather working in pseudo code.

maybe with a little more calmness I can get it operating correctly.

I solved this with the pointer from @Antonio Rinaldi, the fact of it being a web app is NOT relevant, this code I have also run in a desktop application.

so for any other readers, this was a case of me not understanding the use of an APP property and never having used AddHandler before.

The steps that worked were:-
add a property to APP, call is ‘s’ (or something you like) make its Type ‘Serial’
add OPEN event to APP
in the OPEN event add this (I know port 1 is my target so I am not looking for it):-

s=new Serial

s.Baud=13//57600
s.Bits=3//8 bits
s.Parity=0//even parity
s.Stop=0//1 stop bit
s.SerialPort=System.SerialPort(1)//open port 1
if s.Open()=true then
  //YAY!
else
  //inform the user.
  //the port is either not there physically or might be in uses by another app.
end

AddHandler s.DataAvailable, AddressOf SerialDataAvailable

then my s.DataAvailable event is handled by a METHOD I added to APP called ‘SerialDataAvailable’ which has the following declaration:-

SerialDataAvailable(sender as Serial)

I am now very happy and think its about time for a glass of wine.

Thanks to all who answered.