当前位置:网站首页>上位机和三菱FN2x通信实例
上位机和三菱FN2x通信实例
2022-07-28 11:40:00 【yi_tianchou】
应项目需求需要使用上位机软件和三菱的PLC进行通信,C# 和PLC都是零基础,
C#的学习过程略,不难,学会空间就好
下面简述和PLC通信的关键步骤:
1、串口设置:
1) 串口线(三菱的422线)
2)串口工具
波特率:9600 (PLC是固定的)
奇偶检验:偶校验 (PLC固定的)
数据位:7
停止位:1
2、通信测试
上位机:发送 0x05
PLC:回应0x06(正常) 返回0x15 说明指令无效,看看自己串口设置问题
3、获取x个点的当前状态
1)通信格式
读:
| STX | CMD | x/y地址(4字节) | 读取几个字节 | EXT | 校验 | |||||
| 0x02 | '0'读 / '1' 写 | ‘0’ | '0' | 'A' | '0' | ‘0’ | ‘2’ | 0x03 | ‘6’ crc1 | ‘6’ crc2 |
| 固定值0x02 | 0x30 /0x31 | 0x30 | 0x30 | 0x41 | 0x30 | 0x30 | 0x32 | 固定值 | 0x36 | 0x36 |
注 : ‘A’ 直接 转asiic 码 放置的是字符 ‘9’-9= 0x30 ‘A’ - 0x0a = 0x31,此处要注意,运算的时候要区别对待
校验值计算:CMD+地址值+读取字节值+ext = 总和
temp = 总和&0xff
a = ((temp >> 4) & 0x0f) > 9 ? ((temp >> 4) & 0x0f) + 7 : ((temp >> 4) & 0x0f);
b = (temp & 0x0f) > 9 ? ((temp & 0x0f) + 7) : (temp & 0x0f);
crc1= (byte) ( a + 0x30);
crc2= (byte)( b + 0x30);
PLC返回:
错误返回:0x15
成功返回:
| STX | 第一值 | 第二值 | EXT | 校验 | |||
| 0x02 | ‘3’ | '5' | '8' | '4' | 0x03 | ‘D’ crc1 | ‘7’ crc2 |
| 固定值0x02 | 0x33 | 0x35· | 0x38 | 0x34 | 固定值 | 0x44 | 0x37 |
第一值:
| y7 | y6 | y5 | y4 | y3 | y2 | y1 | y0 |
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
| 3 | 5 | ||||||
第二值
| y17 | y16 | y15 | y14 | y13 | y12 | y11 | y10 |
| 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 8 | 4 | ||||||
多字节的同理2字节的方式
写:
| STX | CMD | x/y地址(4字节) | 读取几个字节 | 第一值 | 第二值 | EXT | 校验 | |||||||
| 0x02 | ' '1' 写 | ‘0’ | '0' | 'A'(Y地址) | '0' | ‘0’ | ‘2’ | ‘3’ | ‘5’ | ‘8’ | ‘4’ | 0x03 | ‘6’ crc1 | ‘6’ crc2 |
| 固定值0x02 | 0x31 | 0x30 | 0x30 | 0x41 | 0x30 | 0x30 | 0x32 | 0x33 | 0x35 | 0x38 | 0x34 | 固定值 | 0x33 | 0x42 |
第一值:
| y7 | y6 | y5 | y4 | y3 | y2 | y1 | y0 |
| 0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
| 3 | 5 | ||||||
第二值:
| y17 | y16 | y15 | y14 | y13 | y12 | y11 | y10 |
| 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 8 | 4 | ||||||
写入成功返回:0x06
写入失败返回:0x15
PLC寄存器个点的对应关系:
x: 0x0080
y:0x00a0
边栏推荐
- 遭受痛苦和创伤后的四种本真姿态 齐泽克
- 分布式定时器
- Developing NES games with C language (cc65) 02. What is v-blank?
- Open source office (ospo) unveils Secrets
- Analysis of new retail e-commerce o2o model
- How to build knowledge management system in enterprises and institutions
- Arduino Pro Mini atmega328p connect and light the first LED (at the same time, record the problem of burning failure stk500_recv)
- 用C语言开发NES游戏(CC65)09、滚动
- MSP430 开发中遇到的坑(待续)
- 用C语言开发NES游戏(CC65)10、游戏循环
猜你喜欢

Anhui Jingzhun: Beidou satellite synchronous clock | Beidou synchronous clock | NTP network clock server

Zadig v1.13.0 believes in the power of openness, and workflow connects all values

To build agile teams, these methods are indispensable

产学研用 共建开源人才生态 | 2022 开放原子全球开源峰会教育分论坛圆满召开

西门子对接Leuze BPS_304i 笔记

FlexPro软件:生产、研究和开发中的测量数据分析
![[half understood] zero value copy](/img/5b/18082c1ea93f2e3bbf4920d73163fd.png)
[half understood] zero value copy

用C语言开发NES游戏(CC65)07、控制器

Ten prohibitions for men and women in love

分布式定时器
随机推荐
Developing NES games with C language (cc65) 08. Background collision
Exploration on cache design optimization of community like business
Developing NES games with C language (cc65) 04. Complete background
Library automatic reservation script
Introduction to several methods of keeping two decimal places in PHP
Jinshanyun rushes to the dual main listing of Hong Kong stocks: the annual revenue of 9billion is a project supported by Lei Jun
Is it overtime to be on duty? Take up legal weapons to protect your legitimate rights and interests. It's time to rectify the working environment
[cute new problem solving] climb stairs
用C语言开发NES游戏(CC65)08、背景 碰撞
[nuxt 3] (XII) project directory structure 3
Deployment之滚动更新策略。
Developing NES games with C language (cc65) 02. What is v-blank?
用C语言开发NES游戏(CC65)11、Metatiles
SQL injection less26 (filter spaces and comments, and use error injection without spaces)
Knowledge points of MySQL (13)
MarkDown简明语法手册
Distributed session solution
Arduino Pro Mini atmega328p connect and light the first LED (at the same time, record the problem of burning failure stk500_recv)
揭秘界面控件DevExpress WinForms为何弃用受关注的MaskBox属性
[dark horse morning post] LETV 400 employees have no 996 and no internal papers; Witness history! 1 euro =1 US dollar; Stop immediately when these two interfaces appear on wechat; The crackdown on cou