使用AJAX与本地网络上的示波器连接

[英]Using AJAX to Interface with an oscilloscope on a Local Network


I'm trying to interface with an oscilloscope networked to IP address 192.168.1.1. It has a built in web-server that, for lack of better words, sucks. It has tons of iframes and only fully works in IE. I'm in the process of building an open-source web application that can easily interface with oscilloscopes and display waveforms with HighcartsJS in real-time.

我正在尝试与网络连接到IP地址192.168.1.1的示波器连接。它有一个内置的Web服务器,由于缺乏更好的单词,很糟糕。它有大量的iframe,只在IE中完全有效。我正在构建一个开源Web应用程序,可以轻松地与示波器连接并实时显示HighcartsJS的波形。

Anyway, I'm trying to run this code in Internet Explorer (even though I want to run it in Chrome) with no luck:

无论如何,我试图在Internet Explorer中运行此代码(即使我想在Chrome中运行它)没有运气:

REMOVED BECAUSE IT HAD SILLY MISTAKES

When I open the file in Internet Explorer I do see that the URL is rewritten to localhost even though localhost is NOT 192.168.1.1. Typing in localhost brings me to my local web server (so I'm open to using PHP to do this POST if I can figure it out).

当我在Internet Explorer中打开文件时,我确实看到URL被重写为localhost,即使localhost不是192.168.1.1。键入localhost会将我带到我的本地Web服务器(因此我可以使用PHP来执行此POST,如果我能搞清楚的话)。

Any insight is greatly appreciated. Thanks for reading.

非常感谢任何见解。谢谢阅读。

EDIT: Here's the TCP Stream from Wireshark:

编辑:这是来自Wireshark的TCP流:

POST /Comm.html HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: 192.168.1.1/Comm.html
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)
Content-Type: text/plain
Accept-Encoding: gzip, deflate
Host: 192.168.1.1
Content-Length: 38
DNT: 1
Connection: Keep-Alive
Cache-Control: no-cache
COMMAND=CURVe?
gpibsend=Send
name=
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
MIME-Version: 1.0
Connection: close
Content-Type: text/html
Date: TUE --
Content-Length: 8506
<HTML>..NUMBERS/HTML CUT OUT TO SAVE SPACE....22,22,22,2</HTML>

CONCLUSION SO FAR: I realized I had multiple problems with my code. However, this works:

结论所以:我意识到我的代码存在多个问题。但是,这有效:

$.ajax(
    {
        url: 'link',
        dataType: 'text',
        type: 'post',
        data: {command: 'BEL',
                gpibsend: 'Send'},
    })

But this doesn't: I'm trying to read the response as detailed in the TCP trace:

但这不是:我正在尝试读取TCP跟踪中详述的响应:

$.ajax(
    {
        url: 'http://192.168.1.1/Comm.html',
        dataType: 'text',
        type: 'post',
        data: {command: 'ZOOM:HORIZONTAL:SCALE?',
                gpibsend: 'Send'},
        success: function(data)
        {
            window.alert(data)
        }
    })

2 个解决方案

#1


0  

Most of browsers will not allow to use ajax call to go to other servers that the origin of that script. So that in your script seems to be wrong.

大多数浏览器不允许使用ajax调用去其他服务器那个脚本的来源。所以在你的脚本中似乎是错的。

On other hand I don't understand why to even You specify the whole IP address of server. Usually pointing to a file that should return answer should be just fine.

另一方面,我不明白为什么甚至你指定服务器的整个IP地址。通常指向应该返回答案的文件应该没问题。

Another thing, what king of webserver do run on that Oscilloscope. I do ask cause they are not a common machine to find, especially with a webserver.

另一件事,网络服务器之王在该示波器上运行的是什么。我确实要问因为它们不是常见的机器,特别是使用网络服务器。

Also if you want a real time updates, don't use AJAX. Use websockets. You see, Ajax is basically a call to a webserver just like calling a website, and that process is very long when we want to make an application that will have to get data very fast. Thus, wise people did invented WebSocket API for use in browsers. You see, socket is a direct connection and cause of that You will have to implement a protocol of your own. But for use to communicate with a oscilloscope that would probably mean to make a server file that hacks to internal software, and will just spit numbers every 0.1 s. JS will catch those numbers and will just add another data to result table, and repaint the whole plot.

此外,如果您想要实时更新,请不要使用AJAX。使用websockets。你看,Ajax基本上就像调用一个网站一样调用web服务器,当我们想要创建一个必须非常快速地获取数据的应用程序时,这个过程很长。因此,聪明人确实发明了WebSocket API以用于浏览器。你看,socket是一个直接的连接,因此你必须实现自己的协议。但是用于与示波器通信可能意味着制作一个破解内部软件的服务器文件,并且每0.1秒只吐出数字。 JS将捕获这些数字,并将向结果表添加另一个数据,并重新绘制整个图。

#2


0  

Just wanted to follow up on this in case anyone comes across this on Google. There are multiple options here:

只是想跟进这个,万一有人在谷歌遇到这个。这里有多种选择:

  1. Host the website on a domain, edit your hosts file and point a sub-domain of your website's domain to the LAN IP address

    在域上托管网站,编辑主机文件并将网站域的子域指向LAN IP地址

  2. Create a VPN and access all machines from static IP addresses

    创建VPN并从静态IP地址访问所有计算机

  3. Run your browser with security features disabled

    禁用安全功能运行浏览器

  4. If you can change the domain name server on the oscilloscope then host your own DNS and resolve any given address to the LAN connection

    如果您可以在示波器上更改域名服务器,则托管您自己的DNS并将任何给定地址解析为LAN连接

  5. Run a LAMP/WAMP server on your computer and make the calls via AJAX through PHP (from the server)

    在您的计算机上运行LAMP / WAMP服务器并通过PHP(来自服务器)通过AJAX进行调用


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/06/11/b9f8aac96b4b3bece1d733e41cfeccda.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号