Ser2net (zt)

2012-09-18 09:44:22  阅读 9315 次 评论 1 条

ser2net(Serial to Network Proxy)给用户提供了一种网络与串口相互连接的软件。因为是基于linux的,所以它可以在Openwrt上运行,至于它能为你做什么,就看你了。
这里说一下怎么去配置和安装它。
对于已经刷好openwrt的路由器,你先配置网络信息,使其能够连上外网,之后在windows下可以用putty这个软件通过SSH来接入路由,对于linux用户,可以直接用终端中带的SSH功能来登陆,之后,运行opkg update,来更新下其软件包。之后用
 

  1. opkg install ser2net
复制代码

来安装这个软件,之后进入/etc这个目录,使用

  1. vi ser2net.conf
复制代码

来编辑它的内容,在文件中的前部,主要是讲解的怎么去配置它。有兴趣的可以去仔细的看看。之后到后面,没有#号的地方,我们可以把不用的语句删掉,当然也可以不管。之后执行
 

  1. ser2net
复制代码

此时,我们就已经可以通过网络来给串口发送数据了,但是,因为端口引用的原因,还没法实现串口数据到网络。此时,我们就要改其他文件了,只是进入init.d这个文件夹,找到inittab这个文件,我们将该文件中的与你用到的端口有关的语句删掉之后重启就行了。(对于有些文件,在修改后要执行:wq!,不然没法正常的退出,这要注意!!!)
在重启之后,在打开ser2net就能实现ser2net的双向通信了。
此时唯一的问题就是程序的开机自启问题了,这个需要自己去写启动脚本。具体的操作,将在之后为你讲解。。。。。

另外补充一点东西:
#
# This is an example configuration file for ser2net. It has the following
# format:
# <TCP port>:<state>:<timeout>:<device>:<options>
# TCP port
# Name or number of the TCP/IP port to accept con-
# nections from for this device. A port number may
# be of the form [host,]port, such as 127.0.0.1,2000
# or localhost,2000. If this is specified, it will
# only bind to the IP address specified. Otherwise
# it will bind to all the ports on the machine.
#
# state Either raw or rawlp or telnet or off. off disables
# the port from accepting connections. It can be
# turned on later from the control port. raw enables
# the port and transfers all data as-is between the
# port and the long. rawlp enables the port and
# transfers all input data to device, device is open
# without any termios setting. It allow to use
# /dev/lpX devices and printers connected to them.
# telnet enables the port and runs the telnet proto-
# col on the port to set up telnet parameters. This
# is most useful for using telnet.
#
# timeout
# The time (in seconds) before the port will be dis-
# connected if there is no activity on it. A zero
# value disables this function.
#
# device The name of the device to connect to. This
# must be in the form of /dev/<device>.
#
# options
# Sets operational parameters for the serial port.
# Options 300, 1200, 2400, 4800, 9600, 19200, 38400,
# 57600, 115200 set the various baud rates. EVEN,
# ODD, NONE set the parity. 1STOPBIT, 2STOPBITS set
# the number of stop bits. 7DATABITS, 8DATABITS set
# the number of data bits. [-]XONXOFF turns on (-
# off) XON/XOFF support. [-]RTSCTS turns on (- off)
# hardware flow control, [-]LOCAL turns off (- on)
# monitoring of the modem lines, and
# [-]HANGUP_WHEN_DONE turns on (- off) lowering the
# modem control lines when the connection is done.
# NOBREAK disables automatic setting of the break
# setting of the serial port.
# The "remctl" option allow remote control (ala RFC
# 2217) of serial-port configuration. A banner name
# may also be specified, that banner will be printed
# for the line. If no banner is given, then no
# banner is printed.
# The tw, tr, and tb options take a tracefile name (
# specified in TRACEFILE that will take all traced data.
# tw is data written to the device, tr is data read from
# the device, and tb is both.
#
# or...

# BANNER:<banner name>:banner
# This will create a banner, if the banner name is given in the
# options of a line, that banner will be printed. This takes the
# standard "C" \x characters (\r is carraige return, \n is newline,
# etc.). It also accepts \d, which prints the device name, \p,
# which prints the TCP port number, and \s which prints the serial
# parameters (eg 9600N81). Banners can span lines if the last
# character on a line is '\'. Note that you *must* use \r\n to
# start a new line.
#
# TRACEFILE:<name>:filename
# This specifies a filename to trace output into, as tw:/tmp/trace1.
# This takes a large number of escape sequences, see the man page
# for details on these options.
#
# Note that the same device can be listed multiple times under different
# ports, this allows the same serial port to have both telnet and raw
# protocols.
这些是ser2net的原文,捡其中的重点和看懂的部分翻译一下:
配置格式:
<TCP端口号>:<状态>:<超时>:<设备>:<选项>
TCP端口号:【host,】port,也就是说可以这样写localhost,2020 意思就是使用本机的2020端口作为映射端口
状态:可以填写raw,rawlp,telnet或者off
off禁止端口,但是可以从控制口唤醒
raw:在端口和串口设备之间双向通信
rawlp:端口想串口设备单向通信
telnet:
超时:指定一个数值用于超时,写0禁用超时
设备:必须这样写/dev/《设备名称》
选项:设置串口的参数如:波特率(300,1200,2400,4800,9600,19200,38400,57600,115200)
校验(EVEN,ODD,NONE)
停止位(1STOPBIT,2STOPBITS)
数据位(7DATABITS,8DATABITS)
开启(关闭)XON\XOFF :XONXOFF(-XONXOFF)
开启(关闭)硬件控制流:RTSCTS(-RTSCTS)
其他的内容没有看明白,等待大家的补充,谢谢

 

 

本文地址:http://blog.jinesc.net/?id=80
版权声明:本文为原创文章,版权归 jinesc 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

评论列表

  1. 854619267
    854619267  @回复

    您好,请教个问题:
    现在路由器可以接收tcp的数据然后转发到串口上,,那么反方向通信,串口到tcp口的转发,电脑上应该怎么接收? ser2net用不用配置?

    • jinesc
      jinesc 2013-10-12 10:47:49  回复

      @854619267这个我还真不清楚, 主要是最近没有去折腾这个了
      LINUX下编程不熟悉不好说
      我在WINDOWS下是写了个程序 监视串口发来的数据 后写文件或者数据库再处理的,

  2. jinesc
    jinesc 2013-10-12 10:47:49  回复

    @854619267这个我还真不清楚, 主要是最近没有去折腾这个了
    LINUX下编程不熟悉不好说
    我在WINDOWS下是写了个程序 监视串口发来的数据 后写文件或者数据库再处理的,