MANEJO EN VISUAL BASIC DEL MÓDULO J2304 O. Cantone En

Anuncio
MANEJO EN VISUAL BASIC DEL MÓDULO J2304
O. Cantone
En este ejemplo se trabaja el manejo del Módulo Digital de Comando J2304 en un entorno visual
usando el objeto integrado MSComm, lo que presenta como ventaja mantener la operación por
eventos de la aplicación. El código fuente esta disponible en www.cantone.com.ar
Dim entrada As String
Dim comando As Byte
Dim salidas As Byte
Dim index As Integer
Dim dac As Byte
……………………………………………………………………………………
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputLen = 0
MSComm1.Handshaking = comNone
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.DTREnable = True
MSComm1.PortOpen = True
salidas = 0
Text1.Text = salidas
MSComm1.Output = Chr(&H31)
MSComm1.Output = Chr(salidas)
comando = &H37
MSComm1.Output = Chr(comando)
Timer1.Enabled = True
index = &H80
End Sub
……………………………………………………………………………………
Private Sub Command1_Click()
Timer1.Enabled = False
If Val(Text1.Text) > 255 Then Text1.Text = 255
If Val(Text1.Text) < 0 Then Text1.Text = 0
MSComm1.Output = Chr(&H31)
MSComm1.Output = Chr(Val(Text1.Text))
Timer1.Enabled = True
End Sub
……………………………………………………………………………………
Private Sub Cmd_Leer_Click()
comando = &H37
MSComm1.Output = Chr(comando)
End Sub
……………………………………………………………………………………
Private Sub HScroll1_Change()
MSComm1.Output = Chr(&H32)
dac = Val(HScroll1.Value)
MSComm1.Output = Chr(dac)
Label8.Caption = HScroll1.Value
End Sub
……………………………………………………………………………………
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
entrada = MSComm1.Input
If comando = &H37 Then
entradas.Text = 255 - Asc(entrada)
End If
If comando = &H41 Then
AI0.Text = Asc(entrada)
AI1.Text = Asc(entrada)
'Dibuja las barras.
Shape2.Height = 1785 - (7 * Val(AI0.Text))
Shape4.Height = 1785 - (7 * Val(AI0.Text))
End If
End If
End Sub
……………………………………………………………………………………
Private Sub Timer1_Timer()
Select Case comando
Case &H37
comando = &H41
Case &H41
comando = &H37
End Select
MSComm1.Output = Chr(comando)
Timer1.Enabled = True
End Sub
……………………………………………………………………………………
Private Sub Cmd_Salir_Click()
salidas = 0 'Apaga las salidas.
MSComm1.Output = Chr(&H31)
MSComm1.Output = Chr(salidas)
End
End Sub
……………………………………………………………………………………
Private Sub Y7_Click()
salidas = salidas Xor 128 'Cambia de estado el bit 7
MSComm1.Output = Chr(&H31)
MSComm1.Output = Chr(salidas)
End Sub
……………………………………………………………………………………
Private Sub Y6_Click()
salidas = salidas Xor 64 'Cambia de estado el bit 6
MSComm1.Output = Chr(&H31)
MSComm1.Output = Chr(salidas)
End Sub
……………………………………………………………………………………
Nota: Con los siguientes botones proceder de igual forma que con Y7 y Y6.
Documentos relacionados
Descargar