我尝试发送FINS命令通过 UDP 从 PC (C#.NET) 发送到 PLC 以太网模块 (Omron),但没有从 PLC 得到任何响应,并且不知道从哪里可以开始故障排除。
PLC has a very simple ladder logic as follow:
If DM100
has value of #0001
, then trigger on output 101.00
. (Here, "Trigger" is just a symbol name for memory area D100
, and "Output" is a symbol for output 101.00
)
然后我写了一段C#,执行“内存区域写入”的FINS命令,其命令代码为01 02
,后面是起始地址、要写入的项目数和数据。 C# 代码应写入值 #0001
到PLC的D100
触发 ON 的区域101.00
.
[删除了不起作用的代码]..
输出101.00
没有被触发,我也没有收到任何异常。
我已确定以下事项:
- 端口、节点和地址配置正确,经 CX-Programmer 中的“在线工作”确认。我还对每个 IP 执行 ping 操作以确保节点已连接。
- The
UdpClient
代码是有效的,因为我编写了一个非常简单的服务器/客户端代码,可以成功发送和接收数据包。
- 梯形图逻辑没有问题。我将梯形图传输到PLC并通过Work Online在Monitor模式和设置下进行测试
D100
手动设置一个值。
我怀疑其中有错误fins_cmnd
数组,但正如我的代码中所见,我对每个值都进行了尽可能详细的注释;我不可能发现自己错过了什么。我怀疑我可能没有正确解析十六进制,但同样,我也不例外地指导我。
我不知道在哪里以及如何排除故障。希望这里有人与FINS
编程或PLC经验可以给我一些帮助。
[ANSWER]
Thanks Porge对于链接 - 这让我发现了问题。经过几次尝试后终于开始工作了。请参阅下面的工作代码。
string SERV_IP_ADDR = "192.168.250.1";
const int FINS_UDP_PORT = 9600;
byte[] sendPacket = new byte[]
{
// Full UDP packet: 80 00 02 00 00 00 00 05 00 19 01 02 82 00 64 00 00 01 00 01
// Header
0x80, //0.(ICF) Display frame information: 1000 0001
0x00, //1.(RSV) Reserved by system: (hex)00
0x02, //2.(GCT) Permissible number of gateways: (hex)02
0x00, //3.(DNA) Destination network address: (hex)00, local network
0x00, //4.(DA1) Destination node address: (hex)00, local PLC unit
0x00, //5.(DA2) Destination unit address: (hex)00, PLC
0x00, //6.(SNA) Source network address: (hex)00, local network
0x05, //7.(SA1) Source node address: (hex)05, PC's IP is 192.168.250.5
0x00, //8.(SA2) Source unit address: (hex)00, PC only has one ethernet
0x19, //9.(SID) Service ID: just give a random number 19
// Command
0x01, //10.(MRC) Main request code: 01, memory area write
0x02, //11.(SRC) Sub-request code: 02, memory area write
// PLC Memory Area
0x82, //12.Memory area code (1 byte): 82(DM)
// Address information
0x00, //13.Write start address (2 bytes): D100
0x64,
0x00, //15.Bit address (1 byte): Default 0
0x00, //16.No. of items (2 bytes): only one address which is D100
0x01,
// Write Data
0x00, //18.Data to write (2 bytes): value is 1
0x01,
};
UdpClient client = new UdpClient(); //create a UdpClient instance
try
{
client.Send(sendPacket, sendPacket.Length, SERV_IP_ADDR, FINS_UDP_PORT);
}
catch (SocketException se)
{
Console.WriteLine(se.ErrorCode + ": " + se.Message);
}
client.Close();