基于MODBUS协议和PLC的通讯

本文分享了使用VB.NET编写的MODBUS通讯代码,为需要与PLC进行MODBUS协议通信的读者提供参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

很多人在找MODBUS通讯代码,我把以前用VB.NET写的一些代码贴上来供参考

'判断电机是否在转动
    Public Sub WaitMotorStop()
        '判断电机是否在转动
        Dim str1 As String = "1"
        Do Until str1 = "0"
            Comm2PLC(RCS, Relay901, "")
            System.Threading.Thread.Sleep(50)
            Dim str2 As String = FormMain.RS232.ReadExisting().ToString()
            FormMain.RS232.DiscardInBuffer()
            FormMain.RS232.DiscardOutBuffer()
            '先高低位转换,再16进制转换为10进制。例如把78563412转换为12345678
            If str2.Length > 6 Then
                str1 = str2.Substring(6, 1)
            End If
        Loop
        Thread.Sleep(200)
    End Sub
    ‘----------------------------------------------------------------’
    '写入PLC
    Public Sub Comm2PLC(ByRef _Code As String, ByRef _Address As String, ByVal _Command As String)
        Dim str1 As String = _Code & _Address & _Command         '代码字+中间继电器+命令字
        Dim str2 As String = Calculte_Vertification_bit(str1)
        Dim str3 As String =
The "RCS Commander" (RCS = Remote Control System) tool supports you in your day-to-day work with SINUMERIK solution line control systems. The "RCS Commander" tool makes it easy to manage files on your PC and on SINUMERIK solution line control systems. The "RCS Commander" tool offers the following functions: Exchanging data between the SINUMERIK and your PC. Generating and restoring an image from the CompactFlash Card of your control system to save data. Writing images to a CompactFlash Card. Loading commissioning files directly to the control system and from the control system to your PC. This function is used to support commissioning. Managing the control system's NC data. You can copy files directly from the PC to the NC and from the NC to the PC. Monitoring processes and remote control of the SINUMERIK via a remote control function. Saving the control system's current HMI view as a screen on your PC. This function is used to represent your control system and improves support in the event of an error. Editing the following user files in the OFFLINE mode on the PC: PLC alarm texts (oem_alarms_plc) Cycle alarm texts (oem_alarms_cycles) Part program messages (oem_partprogram_messages) EasyScreen files Tool management texts EasyExtend files (oem_aggregate) Maintenance planner files (oem_maintenance) Managing user files with the following options: Creating a project OFFLINE. Create a project, which automatically copied the files from the control. Copy individual files using project dialog to the control system or copy from the control system into the project. Delete user files using project dialog on the control
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值