Cita:
|
Empezado por egtyu HOLA
QUISIERA SABER QUE CODIGO DEBO UTILIZAR PARA COMUNICAR VISUAL BASIC CON UN PINPAD CONECTADO AL COMPUTADOR POR PUERTO SERIAL.
MUCHAS GRACIAS |
Hola,
Vamos a ver, lo primero que tienes que hacer es consultar el manual del dispositivo móvil y averiguar si hay algún ejemplo de conexión ente .NET y el Pind Pad.
Otra opción que deberías investigar la referencia
System.IO.Ports, así que consulta en la ayuda de MSDN que hay varios ejemplos de como conectar.
Te paso un ejemplo:
En el formulario
Código:
Private Sub frmMain_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
OpenComPort()
SendRequestCommand("L0" & ChrW(13))
End Sub
Private Sub OnDataReceived(ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles comPort.DataReceived
Try
txtDataReceived.Invoke(New myDelegate(AddressOf UpdateTextBox), New Object() {})
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Delegate Sub myDelegate()
Public Sub UpdateTextBox()
Dim strInData As String = ""
While comPort.BytesToRead > 0
strInData &= ChrW(comPort.ReadByte())
End While
txtDataReceived.Text = strInData
txtDataReceived.Refresh()
System.Threading.Thread.Sleep(100)
SendRequestCommand("L0" & ChrW(13))
End Sub
Private Sub OpenComPort()
CloseComPort()
Try
With comPort
.PortName = "COM1"
.BaudRate = 9600
.Parity = IO.Ports.Parity.Odd
.DataBits = 7
.StopBits = IO.Ports.StopBits.Two
.ReadBufferSize = 64
.ReadTimeout = 500
.ReceivedBytesThreshold = 5
.Handshake = IO.Ports.Handshake.None
.RtsEnable = True
.DtrEnable = True
.Encoding = System.Text.Encoding.ASCII
End With
comPort.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub CloseComPort()
If comPort.IsOpen() Then
comPort.Close()
End If
End Sub
Private Sub SendRequestCommand(ByVal cmd As String)
If comPort.IsOpen() Then
comPort.DiscardInBuffer()
comPort.Write(cmd)
Else
MsgBox("El puerto COM1 está cerrado")
End If
End Sub Un saludo :-)