1

通常我更喜欢潜伏在论坛中寻找答案,但我找不到答案,所以这里......

我有一个用 ASP 为客户编写的自定义车队管理系统,他们要求 GPS 功能,以便他们可以摆脱每月的卫星服务。我为卡车驾驶室中的笔记本电脑购买了一个串行 GPS 加密狗,并为卡车司机的笔记本电脑编写了一个简短的 Windows 服务来读取和翻译数据。目前,我每 10 秒用翻译的位置覆盖一个文本文件。(这样做的原因是 Google API 显然无法识别 Windows 7 中的外部位置传感器。)

但是,现在,我需要将该信息发送到服务器,以便调度员可以更新位置,以便卡车司机在客户处标记他们的位置,以供可能需要覆盖其路线的其他司机使用。我想我必须使用 JavaScript,但希望有人能把我送到正确的方向。我试图将一个值预填充到 html 文件上传小部件中,但显然这不起作用

或者我可以将文件保存在临时 Internet 文件中并通过 ASP 获取它吗?使用套接字推送到服务器会更好吗?我想合并我已经写过的网站...

我不需要任何代码,我只需要指出正确的方向!

谢谢!

4

1 回答 1

0

好,知道了。感谢 dmarruco 对 REST 的建议,它启发了我对 xml 使用类似的解决方案。客户端如下:

Imports System.IO
Imports System.IO.Ports
Imports System.Text
Imports System.Xml
Imports System.Web
Imports System.Net


Module Module1

Sub Main()
    Dim myport As SerialPort = New SerialPort("COM3", "4800", Parity.None, 8, StopBits.One)
    Dim availableSerialPorts As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.Ports.SerialPortNames
    If availableSerialPorts.Contains("COM3") Then
        Dim dstring As String = ""
        Try
            If myport.IsOpen Then
                myport.Close()
            End If
            myport.Open()
            System.Threading.Thread.Sleep(1500)
            Dim datastring As String = myport.ReadExisting
            dstring += datastring
            myport.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            If myport IsNot Nothing Then
                myport.Close()
            End If
        End Try

        Dim loc As Integer
        Dim search As String = "$GPGGA"
        loc = InStr(1, dstring, search, CompareMethod.Text)

        Dim latstart As Integer = loc + 18
        Dim lonstart As Integer = loc + 30
        Dim lat As String = Mid(dstring, latstart, 9)
        Dim lon As String = Mid(dstring, lonstart, 10)
        Dim gpgga As String = Mid(dstring, loc, 50)

        If Left(lat, 1) <> "," And Left(lon, 1) <> "?" Then

            Dim HH As String = Left(lat, 2)
            Dim mmmm As String = Mid(lat, 3, 7)
            Dim mconv As String = Val(mmmm) / 60
            mconv = mconv.Replace("0.", "")
            Dim latcoord As String = HH & "." & mconv
            Dim lH As String = Left(lon, 3)
            Dim lmm As String = Mid(lon, 4, 7)
            Dim lmC As String = Val(lmm) / 60
            lmC = lmC.Replace("0.", "")
            Dim loncoord As String = "-" & lH & "." & lmC
            Dim xmldoc As New XmlDocument
            Dim xmldec = xmldoc.CreateXmlDeclaration("1.0", "ASCII", "")
            Dim outx As XmlElement
            outx = xmldoc.CreateElement("Location")
            xmldoc.AppendChild(outx)
            Dim root As XmlElement = xmldoc.DocumentElement
            xmldoc.InsertBefore(xmldec, root)
            Dim xmlat As XmlElement
            xmlat = xmldoc.CreateElement("lat")
            xmlat.InnerText = latcoord
            outx.AppendChild(xmlat)

            Dim xmlon As XmlElement
            xmlon = xmldoc.CreateElement("lon")
            xmlon.InnerText = loncoord
            outx.AppendChild(xmlon)
            Dim machineid As String = "1" 'arbitrary for testing purposes
            Dim xmach As XmlElement
            xmach = xmldoc.CreateElement("MID")
            xmach.InnerText = machineid
            outx.AppendChild(xmach)

            Dim url As String = "http://fakeurl.com/getxml.aspx" 'the receiving page goes here
            Dim wreq As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
            Dim encoding As New ASCIIEncoding()
            Dim bytestowrite As Byte() = encoding.GetBytes(xmldoc.ToString)
            wreq.Method = "POST"
            wreq.ContentLength = bytestowrite.Length
            wreq.ContentType = "text/xml"
            Dim mystream As Stream = wreq.GetRequestStream()
            mystream.Write(bytestowrite, 0, bytestowrite.Length)
            mystream.Close()

        Else
            MsgBox("No Fix")
        End If
    Else
        MsgBox("Disconnected")
    End If
End Sub

End Module

原谅 try/catch 这是我发布之前的测试代码。

于 2013-10-30T20:40:05.130 回答