blueskit / mitsubishiplcprotocol Goto Github PK
View Code? Open in Web Editor NEW三菱PLC(Mitsubishi)通讯协议的C#实现,支持FX、Q系列的ASCII-3E、BIN-3E、FX串口格式。
License: MIT License
三菱PLC(Mitsubishi)通讯协议的C#实现,支持FX、Q系列的ASCII-3E、BIN-3E、FX串口格式。
License: MIT License
I apologize if I ask for information here, but I have not found any other places to talk about communication with Mitsubishi PLC.
I have developed a C # program that communicates with a Misubishi PLC, using your code.
What happens is that if I connect two instances of this program, the first instance connects and can read the data from the PLC, while the second instance connects but does not get the response packets to its own read requests. The second instance is able to complete the reading only when the first instance is disconnected.
It seems that the PLC does not support two connected readers simultaneously. Could it be? Is there any confirmation of this problem in some documentation? I could not find anything!
Thanks for any kind of support. Diego
感謝您的開源。想請教一下, 由於 Execute 函數使用後回覆一長串 raw data 信息, 見到您撰寫的 ResponseMessage 物件可沒有使用, 請問該如何判斷並僅取出 read 後的 value 呢?
(一)為甚麼需在後面加上u呢?
public McCommand(McFrame iFrame)
{
FrameType = iFrame;
SerialNumber = 0x0001u;
NetwrokNumber = 0x0000u;
PcNumber = 0x00FFu;
IoNumber = 0x03FFu;
ChannelNumber = 0x0000u;
CpuTimer = 0x0010u;
}
(二)想請問以下程式碼是以甚麼想法或概念寫的?
public byte[] SetCommand(uint iMainCommand, uint iSubCommand, byte[] iData)
{
var dataLength = (uint)(iData.Length + 6);
var ret = new List(iData.Length + 20);
uint frame = (FrameType == McFrame.MC3E) ? 0x0050u :
(FrameType == McFrame.MC4E) ? 0x0054u : 0x0000u;
ret.Add((byte)frame);
ret.Add((byte)(frame >> 8));
if (FrameType == McFrame.MC4E)
{
ret.Add((byte)SerialNumber);
ret.Add((byte)(SerialNumber >> 8));
ret.Add(0x00);
ret.Add(0x00);
}
ret.Add((byte)NetwrokNumber);
ret.Add((byte)PcNumber);
ret.Add((byte)IoNumber);
ret.Add((byte)(IoNumber >> 8));
ret.Add((byte)ChannelNumber);
ret.Add((byte)dataLength);
ret.Add((byte)(dataLength >> 8));
ret.Add((byte)CpuTimer);
ret.Add((byte)(CpuTimer >> 8));
ret.Add((byte)iMainCommand);
ret.Add((byte)(iMainCommand >> 8));
ret.Add((byte)iSubCommand);
ret.Add((byte)(iSubCommand >> 8));
ret.AddRange(iData);
return ret.ToArray();
}
public int SetResponse(byte[] iResponse)
{
int min = (FrameType == McFrame.MC3E) ? 11 : 15;
if (min <= iResponse.Length)
{
var btCount = new[] { iResponse[min - 4], iResponse[min - 3] };
var btCode = new[] { iResponse[min - 2], iResponse[min - 1] };
int rsCount = BitConverter.ToUInt16(btCount, 0);
ResultCode = BitConverter.ToUInt16(btCode, 0);
Response = new byte[rsCount - 2];
Buffer.BlockCopy(iResponse, min, Response, 0, Response.Length);
}
return ResultCode;
}
// ================================================================================
public bool IsIncorrectResponse(byte[] iResponse)
{
var min = (FrameType == McFrame.MC3E) ? 11 : 15;
var btCount = new[] { iResponse[min - 4], iResponse[min - 3] };
var btCode = new[] { iResponse[min - 2], iResponse[min - 1] };
var rsCount = BitConverter.ToUInt16(btCount, 0) - 2;
var rsCode = BitConverter.ToUInt16(btCode, 0);
return (rsCode == 0 && rsCount != (iResponse.Length - min));
}
项目的代码入口main函数在哪个路径
导入项目之后很多标红的命名空间和类呢?
比如:InControls.Common
InControls.IO.Common;
InControls.IO.SerialDevice;
这些在项目里都没有啊?还有那个vila什么的
Dear Sir,
I am using your source code to read and write from C# program to FX plc. I read the data from PLC Ok but when I try to write the Y0 bit is ON or OFF I don't know how I can use your source code
When I try the following code but it fail !
cmd = FxCommandHelper.Make(FxCommandConst.FxCmdForceOn, new FxAddress("Y0")); // turn on Y0
res = FxSerial.Send(9, cmd); // com is 9
Debug.WriteLine(string.Format("Y0 \t{0}", res.ToString()));
Please kindly help me,
Thank you very much
改进后提交。能够编译通过、并可运行。包含必要的第三方库
不知道这个是用什么做的,
在PLC的彩页上看到 三菱官网有C# 类库和 JAVA类库 专门用于通讯的,找半天没找到,
public FxAddress (string tagName, ControllerTypeConst controllerType)
中switch的default应修改为Int16,此前默认的Bin模式会在计算D寄存器地址时额外/8,这是错误的
default:
_AddressLayoutType = FxAddressLayoutType.AddressLayoutInt16;
break;
public static string Make(FxCommandConst cmd, FxAddress addr, int length)
中的sb.Append(addr.ToAddressHexString());
似乎是Byte需要交换高低位,而不是Bin?
/// 返回标准格式的地址字符串,用于MOD-BUS协议控制命令中的“地址”部分
/// 注意:地址需要交换高低字节
/// </summary>
public string ToAddressHexString ()
{
uint addr = _UniformAddr;
if(_AddressLayoutType == FxAddressLayoutType.AddressLayoutByte) {
addr = ((_UniformAddr >> 8) & 0xff) | ((_UniformAddr & 0xff) << 8);
}
return string.Format("{0:X4}", addr);
}
public static string ConvertToString<T>(List<uint> data)
中的FxConvert.DecToHex后需要再进行一次高低字节交换
测试PLC型号是FX3GA
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.