Reputation: 2951
Does anyone know the communication protocol for communication with the RS232 port of a Mitsubishi FX3G PLC?
I searched the site of Mitsubishi and Googled, but couldn't find the syntax of the commands to send to obtain the data of specific registers in the PLC.
I found the following parts of the command though:
I could not find though wether i should use a straight cable, or a crossed cable, and not even at which baudrate i should communicate (or other settings like data bits, stop bits, and parity)
Does anyone have any experience with RS232 communication with a FX3G PLC ?
(It doesn't matter in which coding language or just a protocol manual)
Upvotes: 4
Views: 16011
Reputation: 2951
I found the required documentation here
The default communication settings are a baudrate of 9600, even parity, 7 data bits, 1 stop bit, and no checksum
I changed this to a baudrate of 19200, none parity, 8 data bits, 1 stop bit, and checksum turned on :
A small VB6 project :
'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
Be careful not to send the commands too fast. Once per plc cycle (100 ms in my case) seems to be the limit.
This code is in VB6, but the same could be applied in C# or any other languages. If you want me to make an example in C#, please contact me.
Upvotes: 3
Reputation: 9726
See if this manual doesn't help you, http://www.automationsystemsandcontrols.net.au/PDF%27s%20Mitsubishi/Manuals/FPLC/FX%20SERIES%20USER%27S%20MANUAL%20-%20Data%20Communication%20Edition.pdf. A list of manuals is also available at http://www.automationsystemsandcontrols.net.au/Technical%20Mitsubishi.html.
Upvotes: 4