英雄合击发布网 【.Net MF网络开发板研究-06】以太网转串口 - 叶帆工作室 - 博客频道 - CSDN.NET专栏:大数

string s = new string(System.Text.UTF8Encoding.UTF8.GetChars(bytData));

// Read the first chunk of the request (we don't actually do

while (true)

m_clientSocket = clientSocket;

// anything with it).

(开发板有两个串口,其中COM1我们把它设为Debug口,所以不能使用了,我们用的是COM2口)。

sp.Open();

if (sp.BytesToRead > 0)

// reset, or terminated.

// 'using' ensures that the client's socket gets closed.

Int32 bytesRead = m_clientSocket.Receive(buffer, m_clientSocket.Available, SocketFlags.None);

}

}

//---------------------------

byte[] bytData = new byte[bytesRead];

sp.Write(bytData, 0, bytData.Length); //通过串口发送出去

}

const Int32 c_microsecondsPerSecond = 1000000;

{

if (m_clientSocket.Poll(5 * c_microsecondsPerSecond, SelectMode.SelectRead))

{

// Wait for the client request to start to arrive.

MF简介:

{

{

else ProcessRequest();

{

sp.Read(bytData, 0, bytData.Length);

if (asynchronously) // Spawn a new thread to handle the request.

其实,我们比较“牛”一点的是一个网口可以转6个串口(其中一个连接Zigbee,一个是RS485,还带若干IO)的物联网网关模块(如下图),该系统基于STM32F207,正在调试过程中。

new Thread(ProcessRequest).Start();

{

System.TinyGUI.Graphics.Print("<<< " + s + "\r\n"); //显示串口接收的数据

以太网转串口是工控领域最常见的智能通信模块,有的是一网口转1串口,有的是一网口转4串口,最多的可以达到一转16串口(好像有的最多可以支持32串口)。如果该类模块做的足够完善,传奇私服地图补丁,可以提供一个windows系统的设备驱动,安装后,在windows系统上就可以看到虚拟出的串口了。不过这样做,虽然简便了开发,但是性能有些问题,所以有的模块还支持直接用TCP或UDP进行连接,不同端口号对应不同的串口,这样编程可以达到一个比较高的数据吞吐量(我在上个公司用Moxa 5630模块开发隧道广告的数据通信时,就遇到类似问题,也就是最大限度地提高单位时间的数据吞吐量)。

核心代码如下:

现在我们就用.NET MF网络开发板做一个一网口转1串口示例演示。

集群由以下3个服务组成:Shards Server: 每个shard由一个或多个mongod进程组成,网通合击传奇私服,用于存储数据 Config Server: 用于存储集群的Metadata信息,热血江湖sf,包括每个Shard的信息和chunks信息 Route Server: 用于提供路由服务,英雄合击发布网,由Client连接,使整个Cluster看起来像单个DB服务器 另外,Chunks是指MongoDB中一段连续的数据...

测试过程图如下:

byte[] bytData = new byte[sp.BytesToRead];

System.TinyGUI.Graphics.Print(">>> "+s+"\r\n"); //显示网络接收的数据

把代码部署开发板后执行,我们直接用我们的TCP Client工具进行测试(下载地址如下:)。

//--

m_clientSocket.Send(bytData); //把串口接收的数据通过网络发送出去

本文源码:

Array.Copy(buffer, bytData, bytData.Length);

//---------------------------

可以看出TCP Client工具所发出的信息,串口调试助手已经收到,同样,串口调试助手所发的数据,TCP Client也可以收到。

using (m_clientSocket)

{

}

if (sp.IsOpen)

void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)

public ProcessClientRequest(Socket clientSocket, Boolean asynchronously)

private void ProcessRequest()

if (m_clientSocket.Available == 0) return;

}

打开任意一个串口调试工具,设置波特率115200,准备和TCP Client进行通信。

官方网站:

}

Byte[] buffer = new Byte[1024];

此时开发板运行状态图如下:

// If 0 bytes in buffer, then the connection has been closed,传奇私服万能登陆器,

{

sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);

简单期间,网络部分的代码,我们可以借用《》中介绍的代码,串口部分的代码,我们可以参考《》和《》中的串口代码来进行改写。

}

string s = new string(System.Text.UTF8Encoding.UTF8.GetChars(bytData));

sp.Flush();


上一篇: 1.95 因为这些原因,我们一定要做好内链优化! - 新站长杂谈栏 - 落伍者站长论坛 -
下一篇:下面没有链接了