Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by Return Ms. ToArray
Preserve File Creation and Modification Date When Downloading in a ZIP File
As part of a recent project, it was necessary to ensure that the creation date and modification date of files were preserved when downloading them from the browser. The default behavior of browsers is to set both dates to the current time upon download (some research showed that this behavior can't be easily bypassed when downloading files directly in the browser). For example, here’s the title image: just downloaded, but definitely not just created.
基于WebSocket的modbus通信(三)- websocket和串口
错误纠正 上一篇还有个错误,就是客户端写数据时服务端不需要响应,但我的服务端响应了的。我选择改客户端,把写数据时接收到的响应丢弃。 PrintBytes(ADUMessage.Serialze(request), "请求"); if (Client != null) { await Client.Client.SendAsync(new Memory<byte>(ADUMessage.Serialze(request))); //丢弃可能的响应 await WebSocket.ReceiveAsync(new ArraySegment<byte>(new byte[1024*4]), CancellationToken.None); } 现在我们同时有了服务器和客户端,就可以在tcp连接上面覆盖一个websocket连接,然后用WebSocket传递Modbus数据帧。 效果 这是基于WebSocket连接的modbus通信,读写都没问题 服务器 客户端 主程序改造 我们的服务器和客户端可以自由选择使用TCP或者WebSocket通信,所以 需要提供对应的命令行参数...
基于WebSocket的modbus通信(二)- 客户端
上一篇已经实现了ModbusTcp服务器和8个主要的功能码,只是还没有实现错误处理功能。 但是在测试客户端时却发现了上一篇的一个错误,那就是写数据成功,服务器不需要响应。 接下来要做的就是实现ModbusTcp客户端。有了清晰的协议,代码循规蹈矩的写就行了。 原始数据 其中只读寄存器和线圈都有可分辨的值 交互 改变线圈和寄存器的值 向线圈写入4个1 向寄存器写入4个11 将每个栈的值查询出来 结果 可以看到数据已变成我们设定的值 工作流程 命令行输入指令 解析指令 根据功能码跳转到相应分支 构造、发送请求 解析响应 根据协议,每次发请求,事务标识符都会自增。 客户端需要实现8种功能码,因此每个功能码都需要一个方法去实现。 //WebModbus.cs // 读 读写线圈 public async Task<bool[]> Request_01(ushort startIndex, ushort length){} // 读 只读线圈 public async Task<bool[]> Request_02(ushort startIndex, ushort length){}...
基于WebSocket的modbus通信(一)- 服务器
ModbusTcp协议是基于tcp的,但不是说一定要通过tcp协议才能传输,只要能传输二进制的地方都可以。比如WebSocket协议。 但由于目前我只有tcp上面的modbus服务器实现,所以我必须先用tcp连接借助已有工具来验证我的服务器是否写正确。 ModBusTCP协议报文比较复杂,主要是区分了3组类型 请求和响应 读和写 多个数据和单个数据 理论上将报文格式的种类从1种变成了8种。 但是在响应读数据时,没有区分数据量,而是到请求中去查找,听说是为了减少传输量。因此实际格式种类是3组6种。 请求读数据报文 事务标识符 协议标识符 报文长度 单元标识符 功能码 起始地址 读取数量 字段长度 2 byte 2 byte 2 byte 1 byte 1 byte 2 byte 2 byte 数据类型 ushort ushort ushort byte byte ushort ushort 自增 一般为0 6,从单元标识符开始算 一般为0 链接 响应读数据报文 事务标识符 协议标识符 报文长度 单元标识符 功能码 数据字节数 数据 2 byte 2 byte 2 byte 1...
Send environmental data from ProjectLab to Azure w/ IoT Hub
Things used in this project (Project updated to v1.1 (released on August 1st, 2023)) This project shows you how to connect send environmental data from your ProjectLab to Azure using IoT Hub! Meadow.Foundation a platform for quickly and easily building connected things using.NET on Meadow. Created by Wilderness Labs, It's completely open source and maintained by the Wilderness Labs community.
Unity基于Google Protobuf序列化和反序列化小案例
1.协议定义,简单实现传玩家的2D坐标 syntax = "proto3"; package SocketGameProtocol; message PlayerInfo { float xPos=1; float yPos=2; } 2.在Unity的Assets目录下创建一个Plugins文件夹(必须这样命名),此文件专门存放扩展文件, 再新建文件夹BaseInfolibrary,将Google.Protobuf.dll拖入 3.新建一个Test.cs脚本 脚本中引入命名空间 using SocketGameProtocol; using Google.Protobuf; using System; using System.IO; private PlayerInfo info; public byte[] Init(Vector2 pos) { if (info == null) { info = new PlayerInfo(); } info.XPos = pos.x; info.YPos = pos.y; byte[] data = Serialize(info);...
Prefer using Stream to byte[]
While reviewing and refactoring a real-world codebase I've noticed how byte[] API is misused. That is the reason why in this article I'm sharing some thoughts on why you shouldn't evade Stream API in your code. Introduction When working with files there are often both APIs operating byte[] and Stream so quite often people chose byte[] counterpart as it requires less ceremony or just intuitively more clear.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Return Ms.
Contact Return Ms., search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack