locked
Get serial port data in an web page RRS feed

  • Question

  • Hello,

    I have developed a windows form application to read data from serial port using .NET 2.0 (using a C# API).

    I would like to get this scenario:

    * A user in a client machine browse a html page with a button. When the user clicks the button, a page or wpf application shows "Waiting for data from serial port...". The user sends data from the serial port and the html receives the data in a <object> tag or perhaps some javascript, to send the data to the server

    I only could get data in a web page from serial port using a XBAP application but this isn´t the aproach I looking for. I also thinking it could be only possible with a java applet.

    Any suggestions or techonologies to do this scenario?

    Thanks!
    Tuesday, July 3, 2007 3:49 PM

All replies

  • Reading from a port is pretty high up on the security charts so there won't be many sandboxed technologies that would allow it. Unless you got policy access over the client or can have a download then I'd think you're heading for a dead-end. Do you have a specific platform in mind, I was wondering if you could use Vista gadget/Mac dashboard?

    Thursday, July 5, 2007 11:07 PM
  • Hi,

    I am developing similar application in .NET. I have to read data through serial port on client machine from web page(asp.net) and store it in database.Do you have any idea how to approach for this?Could you share your ideas/code with me?
    you can email me at: mgudimalla@hotmail.com

    Thanks in Advance,
    Manasa 

    Wednesday, February 17, 2010 10:27 PM
  • Web browsers have security limitations which stop applications running in them from accessing files on the client computer or ports similarly.  This security arrangement is often described as a "sandbox". 

     

    This is why file sharing apps will usually be windows and installed on your machine.

    Obvious ways round this:

    Write a windows or WPF app.

    XBAP might work - wpf in browser and specify elevated privileges.

    You can install silverlight 4 locally and specify elevated privileges so I'd guess that might work.

    Maybe activex.

     

    Tuesday, July 6, 2010 2:35 PM
  • Hola.

    Tengo una pagina web desarrollada con visual Web Developer 2008 (visual studio 2008

    Quiero saber como puedo recibir datos por el puerto serie del mismo servidor donde está alojada la pagina.

    MUhcas gracias y un saludo

    este es mi codigo y no consigo leer del puerto serie. Sin embargo desde un hyperterminal si logro leerlo.

    Y enviar si puedo enviar sin problemas

     

    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Security.Principal.WindowsIdentity
    Imports System
    Imports System.IO.Ports

    Partial Class XbeePpal
        Inherits System.Web.UI.Page

        Public Conn_RED_GENERAL As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString_RED_GENERAL").ConnectionString)
        Dim WithEvents Port As SerialPort = New SerialPort("COM3", 9600, Parity.None, 8, StopBits.One)
        'Dim Port As SerialPort = New SerialPort("COM3", 9600, Parity.None, 8, StopBits.One)
        Dim popupScript As String = "<script language='JavaScript'>window.open('','_self','');window.close();<" & "/script>"

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            'CheckForIllegalCrossThreadCalls = False
            'Client_Alert(Port.IsOpen)
            Port.ReadBufferSize = 100
            If Port.IsOpen = False Then Port.Open()
            Port.DtrEnable = True
            'Client_Alert(Port.CtsHolding)
            'Port.RtsEnable = True
            'Port.CDHolding
            Port.Handshake = Handshake.None
            'AddHandler Port.DataReceived, AddressOf Recepcion
            'TECNICO.Text = User.Identity.Name()

        End Sub

        Sub Port_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Port.DataReceived
            'Me.Invoke(New EventHandler(AddressOf saludo))
            'Exit Sub
            txtReciveText.Text = "a"
            Client_Alert("recibo")
            txtReciveText.Text = Port.ReadExisting
            If Port.ReadExisting.Length = 0 Then
                LstReciveText.Items.Add(txtReciveText.Text)
                txtReciveText.Text = ""
            End If
        End Sub
        Sub saludo()
            Client_Alert("hola")
        End Sub

        Private Sub btnSendText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSendText.Click
            'If Port.IsOpen = False Then Port.Open()
            Port.Write(txtSendText.Text & "A")
            'If Port.IsOpen = True Then Port.Close()
        End Sub


        Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
            If Port.IsOpen = True Then Port.Close()
        End Sub
    End Class

    Wednesday, December 29, 2010 10:22 AM
  • SInce July, I've written an application which needed to work out a browser and read/write to a port.

    This was in Silverlight and it's by far the best option for a web page IMO.

    You instantiate your silverlight app as an object and you can set properties and run methods from javascript.  Similarly, you can reach out from the silverlight app and run javascript functions in the page on the client. 

    There are two gotchas at the moment which are both security orientated. 

    1) You're stuck with a limited range of ports.

    2) You need to be able to serve a clientaccesspolicy.xml from whichever machine the silverlight app needs to talk to.  Even the client machine.

    Tuesday, January 4, 2011 11:08 AM