VB_NET与三菱PLC自働化控制

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

2010 与三菱FX系统设计:实现网络控制自働化工装

Public Class Vbfxn

Private Sub Butcom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butcom.Click

If Comnct.IsOpen Then

Comnct.Close()

Butcom.BackColor = Color.Red

Else

Comnct.PortName = Comnum.Text

Comnct.Open()

Try

Butcom.BackColor = wnGreen

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End If

Inputxt.Text = ""

Inputxt.Focus()

End Sub

Private Sub Vbfxn_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

Me.Dispose()

End Sub

Private Sub Vbfxn_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try

For i As Integer = 0 To puter.Ports.SerialPortNames.Count - 1

Comnum.Items.Add(puter.Ports.SerialPortNames(i))

Next

Comnum.Text = puter.Ports.SerialPortNames(0)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

End Sub

Public Sub Sp_DataReceived(ByVal sender As Object, ByVal e As

System.IO.Ports.SerialDataReceivedEventArgs) Handles Comnct.DataReceived

Me.Invoke(New EventHandler(AddressOf Sp_Receiving)) '调Ì¡Â用®?接¨®收º?数ºy据Y函¡¥数ºy End Sub

Private Sub Sp_Receiving(ByVal sender As Object, ByVal e As EventArgs)

' Dim strIncoming As Byte

Dim strIncoming As Integer

Dim str1(), str2(), Mtxu, mty, str4 As String

Dim bytes() As Byte

Dim i, Mtxt, Mtx, Slen As Integer

Threading.Thread.Sleep(100) '添¬¨ª加¨®的Ì?延¨®时º¡À

If Sendtxt.Text = "02 30 30 30 41 30 30 32 03 36 36"Then

If Comnct.BytesToRead > 0 Then

ReDim bytes(Comnct.BytesToRead)

strIncoming = Comnct.ReadByte()

bytes(0) = strIncoming

For i = 1 To Comnct.BytesToRead

strIncoming = Comnct.ReadByte() '读¨¢取¨?缓o冲?区?中D的Ì?数ºy据Y

bytes(i) = strIncoming

Next

'SerialPort1.Write(sendbox.Text)'发¤¡é送¨ª数ºy据Y

Comnct.DiscardInBuffer()

str1 = Split(BitConverter.ToString(bytes), "-")

ReDim str2(str1.Length - 1) '去¨£¤除ystr1中D最Á?后¨®的Ì?字Á?符¤?

For i = 0 To str1.Length - 2

str2(i) = str1(i)

Next

str4 = Join(str2, " ")

If Microsoft.VisualBasic.Len(str4) > 7 Then

Try

Mtxu = 0

If Mid(Join(str2, " "), 7, 1) = 3 Then

ElseIf Mid(str4, 7, 1) = 4 Then

If Mid(str4, 8, 1) = 1 Then

Mtxu = "A"

ElseIf Mid(str4, 8, 1) = 2 Then

Mtxu = "B"

ElseIf Mid(str4, 8, 1) = 3 Then

Mtxu = "C"

ElseIf Mid(str4, 8, 1) = 4 Then

Mtxu = "D"

ElseIf Mid(str4, 8, 1) = 5 Then

Mtxu = "E"

ElseIf Mid(str4, 8, 1) = 6 Then

Mtxu = "F"

End If

End If

Mtxt = Val(CLng("&H" & Mid(str4, 5, 1) & Mtxu)) mty = ""

Do While Mtxt > 0

Mtx = Mtxt Mod 2

Mtxt = Mtxt \ 2

mty = Mtx & mty

Loop

Slen = Microsoft.VisualBasic.Len(mty)

If Slen < 7 Then

For i = 1 To 7 - Slen

mty = "0" + mty

Next

End If

If Mid(mty, 1, 1) = 1 Then

ButY06.BackColor = wnGreen

Else

ButY06.BackColor = Color.Yellow

End If

If Mid(mty, 2, 1) = 1 Then

ButY05.BackColor = wnGreen

Else

ButY05.BackColor = Color.Yellow

End If

If Mid(mty, 3, 1) = 1 Then

ButY04.BackColor = wnGreen

Else

ButY04.BackColor = Color.Yellow

End If

相关文档
最新文档