首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >RS232通信协议三菱FX3G PLC

RS232通信协议三菱FX3G PLC
EN

Stack Overflow用户
提问于 2012-12-10 19:08:12
回答 2查看 14.4K关注 0票数 4

有谁知道与三菱RS232 FX3G PLC的通信协议吗?

我搜索了三菱和谷歌的网站,但是找不到命令的语法来获取PLC中特定寄存器的数据。

不过,我找到了命令的以下部分:

  • BR =位读取
  • BW =位写入
  • 字读
  • WW =字写

不过,我找不到是否应该使用直电缆或交叉电缆,甚至连通信速率(或其他设置,如数据位、停止位和奇偶校验)也找不到。

有人有RS232与FX3G PLC通信的经验吗?

  • 什么是波德率(和其他通信设置)?
  • 命令的头是如何建立的?
  • 命令本身是如何建立起来的?
  • 校验和是如何计算的?

(使用哪种编码语言或仅仅使用协议手册并不重要)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-12 11:11:37

我找到了所需的文档这里

默认通信设置为9600,偶数奇偶,7个数据位,1个停止位,以及无校验和。

我将其更改为19200的波德率、无奇偶、8位数据、1位停止位,并打开校验和:

一个小型的VB6项目:

代码语言:javascript
运行
复制
'1 form with :
'    1 mscomm control : name=comFX
'    1 command button : name=cmdSend
'    1 textbox        : name=txtShow   multiline=true
Option Explicit

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private mstrData As String
Private mblnBusy As Boolean

Private Sub Form_Load()
  With App
    Caption = .Title & " " & CStr(.Major) & "." & CStr(.Minor) & "." & CStr(.Revision)
  End With 'App
End Sub

Private Sub Form_Resize()
  Dim sngWidth As Single
  Dim sngTxtHeight As Single
  Dim sngCmdWidth As Single, sngCmdHeight As Single
  sngWidth = ScaleWidth
  sngCmdHeight = 315
  sngTxtHeight = ScaleHeight - sngCmdHeight
  txtShow.Move 0, 0, sngWidth, sngTxtHeight
  cmdSend.Move sngCmdWidth, sngTxtHeight, sngWidth, sngCmdHeight
End Sub

Private Sub cmdSend_Click()
  ReadReg "D8013", 7  'sec,min,hr,day,month,year,dayofweek
  ReadReg "R3310", 10 '10 data registers
End Sub

Private Sub ReadReg(strReg As String, intNr As Integer)
  Dim strCmd As String
  If NotBusy Then
    strCmd = "00FFWR0" & strReg & Right$("00" & Hex$(intNr), 2)
    strCmd = Chr$(5) & strCmd & GetSum(strCmd)
    With comFX
      If .PortOpen = False Then CommOpen
      .Output = strCmd
    End With 'comFX
    mblnBusy = True
  End If
End Sub

Private Sub CommOpen()
  With comFX
    If .PortOpen = True Then .PortOpen = False
    .CommPort = 1
    .Settings = "19200,N,8,1"
    .RThreshold = 1
    .PortOpen = True
  End With 'comFX
End Sub

Private Function NotBusy() As Boolean
  Dim lngTimeout As Long
  Dim blnResult As Boolean
  blnResult = True
  lngTimeout = GetTickCount + 1000 'timeout after being busy for 1 second
  Do While mblnBusy
    DoEvents
    If GetTickCount > lngTimeout Then
      blnResult = False
      Exit Do
    End If
  Loop
  NotBusy = blnResult
End Function

Private Sub comFX_OnComm()
  Dim strInput As String
  Select Case comFX.CommEvent
    Case comEvReceive
      strInput = comFX.Input
      mstrData = mstrData & strInput
      ProcessData
  End Select
End Sub

Private Sub ProcessData()
  'answer : ^02 00FF <data registers 4 characters per reg> ^03
  Dim lngStart As Long, lngEnd As Long
  Dim strHead As String, strSum As String
  Dim strEnd As String
  Dim strData As String
  lngStart = InStr(mstrData, Chr$(2))
  If lngStart > 0 Then
    strEnd = Chr$(3)
    lngEnd = InStr(lngStart, mstrData, strEnd)
    If lngEnd > 0 Then
      strHead = Mid$(mstrData, lngStart + 1, 4)
      If strHead = "00FF" Then
        strData = Mid$(mstrData, lngStart + 1, lngEnd - lngStart)
        strSum = Mid$(mstrData, lngEnd + 1, 2)
        If CheckSum(strData, strSum) Then
          mstrData = Mid$(mstrData, lngEnd + 3)
          ShowData Mid$(strData, 5, Len(strData) - 5)
          mblnBusy = False
        End If
      End If
    End If
  End If
End Sub

Private Function CheckSum(strData As String, strSum As String) As Boolean
  If strSum = GetSum(strData) Then
    CheckSum = True
  Else
    CheckSum = False
  End If
End Function

Private Function GetSum(strCmd As String) As String
  Dim intChar As Integer
  Dim lngSum As Long
  lngSum = 0
  For intChar = 1 To Len(strCmd)
    lngSum = lngSum + Asc(Mid$(strCmd, intChar, 1))
  Next intChar
  GetSum = Right$("00" + Hex$(lngSum), 2)
End Function

Private Sub ShowData(strData As String)
  txtShow.SelText = strData & vbCrLf
End Sub

小心不要发出太快的命令。每plc周期一次(在我的例子中是100 ms )似乎是极限。

这段代码是用VB6编写的,但在C#或任何其他语言中也可以使用这种代码。如果你想让我在C#上做一个例子,请联系我。

票数 3
EN

Stack Overflow用户

发布于 2012-12-11 17:15:36

看看这个手册是不是帮不了你,http://www.automationsystemsandcontrols.net.au/PDF%27s%20Mitsubishi/Manuals/FPLC/FX%20SERIES%20USER%27S%20MANUAL%20-%20Data%20Communication%20Edition.pdfhttp://www.automationsystemsandcontrols.net.au/Technical%20Mitsubishi.html也提供了一份手册列表。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13807495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档