Hi all,
I have got a problem here. I am currently working on a program. In this programi am using 4 input pins from the PLC to attach to 4 different sensors. In the programme below I am able to detect only one sensor. I am unable to detect the other 3 sensors. In the coding below the instring1 is detect the sensor at pin 9. How do i modify the programme so that it can detect 3 more sensors? I keep getting errors whenever i loop them. Do I have to read in a "DM"? Can anybody help?
"
Private Sub tmrReadInput_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrReadInput.Tick
Dim instring1 As String
tmrReadInput.Enabled = False
' Always wrap up working with Comm Ports in exception handlers.
Try
' Enable the timer.
Me.tmrReadCommPortMain.Enabled = True
instring1 = "RD" + " " + "9" & Chr(13)
' Write an user specified Command to the Port.
m_CommPort.Write(Encoding.ASCII.GetBytes(instring1))
' Sleep long enough for the modem to respond and the timer to fire.
System.Threading.Thread.Sleep(200)
Application.DoEvents()
Catch ex As Exception
' Warn the user.
MessageBox.Show("Unable to communicate with PLC")
Finally
' Disable the timer.
Me.tmrReadCommPortMain.Enabled = False
Me.tmrReadInput.Enabled = True
End Try
End Sub
"
I am using the below code to generate the output detected by the input.
"
Private Sub WriteMessageMain(ByVal message As String, ByVal linefeed As Boolean)
Dim buffer As Integer
buffer = InStr(message, "0")
If buffer <> 0 Then
TextBox1.Text = "Vacant"
End If
buffer = InStr(message, "1")
If buffer <> 0 Then
TextBox1.Text = "Occupied"
End If
End Sub
"
Thanx
Sandhya
I have got a problem here. I am currently working on a program. In this programi am using 4 input pins from the PLC to attach to 4 different sensors. In the programme below I am able to detect only one sensor. I am unable to detect the other 3 sensors. In the coding below the instring1 is detect the sensor at pin 9. How do i modify the programme so that it can detect 3 more sensors? I keep getting errors whenever i loop them. Do I have to read in a "DM"? Can anybody help?
"
Private Sub tmrReadInput_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrReadInput.Tick
Dim instring1 As String
tmrReadInput.Enabled = False
' Always wrap up working with Comm Ports in exception handlers.
Try
' Enable the timer.
Me.tmrReadCommPortMain.Enabled = True
instring1 = "RD" + " " + "9" & Chr(13)
' Write an user specified Command to the Port.
m_CommPort.Write(Encoding.ASCII.GetBytes(instring1))
' Sleep long enough for the modem to respond and the timer to fire.
System.Threading.Thread.Sleep(200)
Application.DoEvents()
Catch ex As Exception
' Warn the user.
MessageBox.Show("Unable to communicate with PLC")
Finally
' Disable the timer.
Me.tmrReadCommPortMain.Enabled = False
Me.tmrReadInput.Enabled = True
End Try
End Sub
"
I am using the below code to generate the output detected by the input.
"
Private Sub WriteMessageMain(ByVal message As String, ByVal linefeed As Boolean)
Dim buffer As Integer
buffer = InStr(message, "0")
If buffer <> 0 Then
TextBox1.Text = "Vacant"
End If
buffer = InStr(message, "1")
If buffer <> 0 Then
TextBox1.Text = "Occupied"
End If
End Sub
"
Thanx
Sandhya