Anda di halaman 1dari 11

Option Explicit

Private data As Double


Private taskHandle As Long
Private taskIsRunning As Boolean
Private Trama_Data(100) As String
'Declaramos el Api GetAsyncKeyState
Private Declare Function GetAsyncKeyState _
Lib "user32" ( _
ByVal vKey As Long) As Integer

Private Sub ExitA_Click()


Unload Me
End Sub

Private Sub Star_Boton_Click()


Dim sampsPerChanRead As Long
Dim iu As Integer
On Error GoTo ErrorHandler
' startCommandButton.Enabled = False
If ValidateControlValues Then
'

startCommandButton.Enabled = True
Exit Sub
End If

For iu = 0 To 0

DAQmxErrChk DAQmxCreateTask("", taskHandle) ' Create the DAQmx task.


taskIsRunning = True
' Add an analog input channel to the task.
DAQmxErrChk DAQmxCreateAIVoltageChan(taskHandle, Canal(iu).Text, "", _
DAQmx_Val_Cfg_Default, Min_In(iu).Text, Max_in(iu).Text, _
DAQmx_Val_VoltageUnits1_Volts, "")
DAQmxErrChk DAQmxReadAnalogScalarF64(taskHandle, 10#, data, ByVal 0&) ' Read in one
sample from the analog input channel.
DatLeido(iu).Text = CStr(data) ' Display the acquired sample on the user interface
Chanel_Round.Text = Round(DatLeido(0), 8) '////////////////////////////
PorMil.Caption = Val(Chanel_Round) * GainVar + NivelCero
' Trama_Data = DatLeido(0).Text

StopTask ' Call the StopTask module to stop the DAQmx task.
Next ' startCommandButton.Enabled = True
Estado_Digital
Salida_Digital
Exit Sub
ErrorHandler:
If taskIsRunning = True Then
DAQmxStopTask taskHandle
DAQmxClearTask taskHandle
taskIsRunning = False
End If
'

startCommandButton.Enabled = True
MsgBox "Error:" & Err.Number & " " & Err.Description, , "Error"

End Sub

Private Sub StopTask()


' All done!
DAQmxErrChk DAQmxStopTask(taskHandle)
DAQmxErrChk DAQmxClearTask(taskHandle)
taskIsRunning = False
End Sub

Private Function ValidateControlValues()


ValidateControlValues = 0
If Min_In(0).Text = "" Or Max_in(0).Text = "" Then
MsgBox "Complete campos vacios.", , "Error"
ValidateControlValues = 1
End If
End Function

Private Sub Form_Load()


taskIsRunning = False
GainVar = 10
NivelCero = 50
' Mainform.Visible = False
' Mainform.Histogr.Value = True
End Sub

Private Sub Form_Unload(Cancel As Integer)


' Quit the program.
If taskIsRunning = True Then
StopTask
End If
End
End Sub

Private Sub Timer1_Timer()


Dim i As Integer

For i = 0 To 255
'Consultamos el valor de la tecla mediante el Api. _
Si se presion devuelve -32767 y mostramos el valor de i
If GetAsyncKeyState(i) = -32767 Then

' MsgBox "Cdigo de la tecla virtual :" & i & vbCrLf _


'

& " La Tecla presionada es : " & Chr(i), vbInformation

If i = vbKeyLeft Then
bitCheckBox(6).Value = 1
Shape3(0).FillStyle = 0
Shape3(1).FillStyle = 0
Else
bitCheckBox(6).Value = 0

Shape3(0).FillStyle = 1
Shape3(1).FillStyle = 1
End If
If i = vbKeyRight Then
bitCheckBox(7).Value = 1
Shape4(0).FillStyle = 0
Shape4(1).FillStyle = 0
Else
bitCheckBox(7).Value = 0
Shape4(0).FillStyle = 1
Shape4(1).FillStyle = 1
End If

If i = vbKeyUp Then
bitCheckBox(4).Value = 1
Shape2(0).FillStyle = 0
Shape2(1).FillStyle = 0
Else
bitCheckBox(4).Value = 0
Shape2(0).FillStyle = 1
Shape2(1).FillStyle = 1
End If

If i = vbKeyDown Then
bitCheckBox(5).Value = 1
Shape1(0).FillStyle = 0

Shape1(1).FillStyle = 0
Else
bitCheckBox(5).Value = 0
Shape1(0).FillStyle = 1
Shape1(1).FillStyle = 1
End If

End If
Next

Star_Boton.Value = True

End Sub

Public Sub Estado_Digital()


Dim sampsPerChanRead As Long
Dim data As Long
Dim numBytesPerSamp As Long
Dim i As Integer
Dim bufferSize As Long
Dim channelList As String * 255
Dim arraySizeInBytes As Long
Dim readArray() As Byte

On Error GoTo ErrorHandler

' startCommandButton.Enabled = False


If ValidateControlValues Then
'

startCommandButton.Enabled = True
Exit Sub
End If

arraySizeInBytes = 8
bufferSize = 255
' Re-initialize a dynamic array to hold values read off the digital lines
ReDim readArray(arraySizeInBytes)

' Create the DAQmx task.


DAQmxErrChk DAQmxCreateTask(" ", taskHandle)

' Add a digital input channel to the task.


DAQmxErrChk DAQmxCreateDIChan(taskHandle, digitalLinesTextBox1.Text, "",
DAQmx_Val_ChanForAllLines)

' Start the task running, and read from the digital lines.
DAQmxErrChk DAQmxStartTask(taskHandle)
DAQmxErrChk DAQmxReadDigitalLines(taskHandle, 1, 10#, _
DAQmx_Val_GroupByChannel, readArray(0), arraySizeInBytes, _
sampsPerChanRead, numBytesPerSamp, ByVal 0&)

For i = 0 To 7
bitCheckBoxS(i) = readArray(i)
Next

' Display a window indicating the number of samples per channel read.
samplesPerChannelReadLabel.Caption = "Samples / Line Read = " & sampsPerChanRead
samplesPerChannelReadLabel.Visible = True

' All done!


StopTask

Exit Sub

ErrorHandler:
If taskIsRunning = True Then
DAQmxStopTask taskHandle
DAQmxClearTask taskHandle
taskIsRunning = False
End If
' startCommandButton.Enabled = True
MsgBox Err.Number & " " & Err.Description, , "Error"
End Sub

Public Sub Salida_Digital()


Dim i As Integer

Dim sampsPerChanWritten As Long


Dim arraySizeInBytes As Long
Dim writeArray() As Byte

On Error GoTo ErrorHandler

' startCommandButton.Enabled = False

If ValidateControlValues Then
'

startCommandButton.Enabled = True
Exit Sub
End If

arraySizeInBytes = 8
' Re-initialize an array that holds the digital values to be written

ReDim writeArray(arraySizeInBytes)
For i = 0 To arraySizeInBytes - 1
writeArray(i) = bitCheckBox(i)
Next

' Create the DAQmx task.


DAQmxErrChk DAQmxCreateTask("", taskHandle)
taskIsRunning = True

' Add a digital output channel to the task.


DAQmxErrChk DAQmxCreateDOChan(taskHandle, digitalLinesTextBox2.Text, "",
DAQmx_Val_ChanForAllLines)

' Start the task running, and write to the digital lines.
DAQmxErrChk DAQmxStartTask(taskHandle)
DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, True, 10#, DAQmx_Val_GroupByChannel,
writeArray(0), sampsPerChanWritten, ByVal 0&)

' Display a window indicating the number of samples per channel read.
samplesPerChannelWrittenLabel.Caption = "Samples / Line written = " & sampsPerChanWritten
' samplesPerChannelWrittenLabel.Visible = True

' All done!


StopTask

Exit Sub

ErrorHandler:
If taskIsRunning = True Then
DAQmxStopTask taskHandle
DAQmxClearTask taskHandle
taskIsRunning = False
End If

' startCommandButton.Enabled = True

MsgBox "Error: " & Err.Number & " " & Err.Description, , "Error"

End Sub

Anda mungkin juga menyukai