Portal    Foro    Buscar    FAQ    Registrarse    Conectarse


Publicar nuevo tema  Responder al tema 
Página 1 de 1
 
 
Comunicaciòn Serial Con Gambas3 Y Smartcard
Autor Mensaje
Responder citando   Descargar mensaje  
Mensaje Comunicaciòn Serial Con Gambas3 Y Smartcard 
 
antes que nada quisiera saludar al foro,soy un nuovo miembro.
como dice el titulo estoy pasando un programa de vb6 y vNet a gambas3.en sintesis envio tramite serial la Header command compuesta de 5 byte:
1 byte de la clase + 1 byte de la instruccion + dos byte + 1 byte de quantos byte espero como respuesta.
hasta ahora logrè obtener el ATR pero no consigo "hablar" con la smartcard segun el standard ISO 7816.quisirea saber si alguno de los miembros ha hecho/o esta trabajando un codigo de gestion de las smartcard ISO 7816.
grazias en anticipo.
 



 
alejandrodaniel - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Comunicaciòn Serial Con Gambas3 Y Smartcard 
 
Buonasera, alejandrodaniel

Confieso que nunca he trabajado con smartcard, pero supongo que al margen del protocolo, la comunicación por puerto serie debería de ser fácil. Comprueba que estás escribiendo correctamente en binario y que la longitud en bytes es correcta, contando los caracteres de control que eventualmente hubiera que enviar (gb.Lf ó gb.CrLf). Comprueba que el evento Read se dispara y que estás leyendo una longitud suficiente de bytes. Sé que estas indicaciones ya las habrás tenido en cuenta, pero no se me ocurren otras causas por las que tu programa pueda fallar.

Una pregunta ¿estás usando el componente Serial Port o un Stream apuntando a /dev/ttyS0 ? Si nos muestras la parte de tu código que lee y escribe en el serial port, será más fácil intentar ayudarte.

Saludos
 




===================
Jesús Guardón

Por favor, usemos el corrector ortográfico antes de pulsar el botón "Enviar".

"uo ǝs ʇɐu pıɟıɔıן ɐdɹǝupǝɹ ɐ dɹoƃɹɐɯɐɹ, soןo ɥɐʎ bnǝ dɹodouǝɹsǝןo"
 
jguardon - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Comunicaciòn Serial Con Gambas3 Y Smartcard 
 
Citar:
pero supongo que al margen del protocolo, la comunicación por puerto serie debería de ser fácil

jamàs tube problemas a crear una interfaz entre dos dispositivos tipo PC-PC o PC-PIC.uso el line-feed y carriage-return para limitar el stream.
con las tarjetas ISO 7816 VB6 y MSComm funcionan muy bien.el problema es que mis amigos con OS Linux me han pedido un software en gambas(tengo instalado la version 3.1.1 y OS LinuxMint Nadia x86_64 conectado con adaptador RS232-USB y smartmouse/phoenix).en el codigo uso el componente SerialPort apuntando a /dev/ttyUSBx.
con las tarjetas ISO 7816 el metodo es asi:
Envio INS de pedido informaciòn ---> C1 XX 00 00 LL
Ack de la tarjeta + respuesta -------> C1 XX 00 00 LL XX DD DD ............... DD 9z zz

C1 --- Clase
XX --- Instrucion o pedido informaciòn
00  --- Byte opcionales de INS
00  --- Byte opcionales de INS
LL  --- Longitud de la respuesta
DD --- Datos de respuesta
9z zz --- Status-Byte de la respuesta

codigo en Gambas3:
' gambas class file

Public Sub _new()
'''''''''''''''''
End

Public Sub Form_Open()
Me.Center
Me.Caption = "Test SmartCard serial"
Device
cboBaudrate.Index = 5
cboDatabits.Index = 1
cboStopbits.Index = 1
cboParidad.Index = 0
cboFlowControl.Index = 0
lblDelay.Caption = 500
sldDelay.Value = 500
lblDelayCBR.Caption = 500
sldDelayCBR.Value = 500
pcbConexion.Visible = False
pcbDesconexion.Visible = True
End

Public Sub Form_Close()
If RS232.Status = Net.Active Then Close RS232
Quit
End

Public Function Device()
Dim iContador As Integer
For iContador = 0 To 8
    If Exist("/dev/ttyUSB" & iContador) Then
       cboPuertos.Add("/dev/ttyUSB" & iContador)
    Endif
Next
If cboPuertos.Count = 0 Then
   cboPuertos.Add("Puerta n/hab.")
Endif
End

Public Sub btLimpia_Click()
txtLog.Clear()
End

Public Sub cmdConexion_Click()
Dim MensajeError As String
With RS232
     If .Status = Net.Inactive Then
        .PortName = cboPuertos.Text
        .Speed = CInt(Trim(cboBaudrate.Text))
        .Parity = CInt(cboParidad.Index)
        .DataBits = CInt(Trim(cboDatabits.Text))
        .StopBits = CInt(Trim(cboStopbits.Text))
        .FlowControl = CInt(cboFlowControl.Index)
        If cboPuertos.Text = "Puerta n/hab." Then
           Message(MensajeError)
           txtLog.Clear()
           txtEnvia.Clear()
           btLimpia.Enabled = False
           btEnvia.Enabled = False
           cmdInfo.Enabled = False
        Endif
        .Open()
        txtLog.Clear()
        txtEnvia.Clear()
        txtATR.Clear()
        btLimpia.Enabled = True
        btEnvia.Enabled = True
        cmdInfo.Enabled = True
        pcbConexion.Visible = True
        pcbDesconexion.Visible = False
        txtLog.Text = txtLog.Text & "ATR <--- "
        .RTS = 1
        .RTS = 0
        Sleep sldDelay.Value / 1000
     Else If .Status = Net.Active
        txtLog.Clear()
        txtEnvia.Clear()
        txtATR.Clear()
        btLimpia.Enabled = False
        btEnvia.Enabled = False
        cmdInfo.Enabled = False
        pcbConexion.Visible = False
        pcbDesconexion.Visible = True
        .Close()
     Endif
End With
End

Public Sub btEnvia_Click()
Dim ByteIn, BufferOut, BufferIn As String
Dim Parse As Integer
txtLog.Text = txtLog.Text & "\n"
txtLog.Text = txtLog.Text & "INS ---> "
For Parse = 1 To Len(txtEnvia.Text) / 2
    BufferOut = BufferOut & Chr(CInt(Val("&H" & Mid(txtEnvia.Text, ((Parse - 1) * 2) + 1, 2))))
Next
Write #RS232, BufferOut, 5
Sleep sldDelayCBR.Value / 1000
End

Public Sub RS232_Read()
Dim Rx, Word As String
While Not Eof(RS232)
      Read #RS232, Rx, 1
      Rx = Hex$(Asc(Rx))
      If Len(Rx) < 2 Then Rx = "0" & Rx
      txtLog.Text = txtLog.Text & Rx
Wend
End

Public Sub sldDelay_Change()
lblDelay.Caption = sldDelay.Value
End

Public Sub sldDelayCBR_Change()
lblDelayCBR.Caption = sldDelayCBR.Value
End
 


en vb6:
Option Explicit

Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)

Dim risp, Dati As String, DatiCard As String, txStringaOutHeadIns, StringaOutHead, lenrx, StringaOut, StringaOutData

Private Sub Form_Load()
MSComm1.InBufferSize = 1024
Picture3.Visible = True
imgConectar.Visible = True
RigaDiControllo.Text = "Estado: Porta COM" & MSComm1.CommPort & "cerrada"
Height = 5315
End Sub

Public Sub mnuOpen_click()
Dim Commporta As String, Settings As String
On Error Resume Next
Settings = GetSetting(App.Title, "Settaggi", "Settings", "")
    If Settings <> "" Then
        MSComm1.Settings = Settings
        If Err Then
            MsgBox Error$, 48
            Exit Sub
        End If
    End If
Commporta = GetSetting(App.Title, "Settaggi", "CommPorta", "")
    If Commporta <> "" Then MSComm1.CommPort = Commporta
MSComm1.CommPort = Commporta
MSComm1.Settings = Settings
MSComm1.Handshaking = comNone
MSComm1.PortOpen = True
ResetCard
If MSComm1.PortOpen = True Then
    imgConnected.Visible = True
    Picture1.Visible = True
    imgdesconectar.Visible = True
    imgNotConnected.Visible = False
    Picture3.Visible = False
    RigaDiControllo.Text = "Estado: Puerta COM" & MSComm1.CommPort & "abierta " & "  -  " & "Impostaziones : " & " " & MSComm1.Settings
Else
    imgConnected.Visible = False
    imgNotConnected.Visible = True
End If
Exit Sub
Resume Next
txtNumSer.Text = ""
txtNumSerDec.Text = ""
End Sub

Public Function SendText()
Dim a, BufferOut, PreBufferOut$, tempBufferOut, txStringaOutHead, st, rx
rx = MSComm1.Input
rx = ""
MSComm1.RThreshold = lenrx
On Error Resume Next
' ' ' ' ' ' ' gestione dati in uscita ' ' ' ' ' ' ' ' ' ' ' '
For a = 1 To Len(StringaOut) / 2
   PreBufferOut$ = Chr(IHex(Mid(StringaOut, ((a - 1) * 2) + 1, 2)))
   BufferOut = BufferOut & PreBufferOut$
Next a
MSComm1.Output = BufferOut
txtFinestra.Text = txtFinestra.Text & "-->  " & txStringaOutHead & vbCrLf
Resume Next
End Function

Public Sub MSComm1_OnComm()
Dim bufferin As String, BufferHex As String, strHex As String, strBuffer As String, tempbuffer
Dim I, rx, ComBuffer, a, pos
On Error Resume Next
'''''''''''' Dati in arrivo ''''''''''''''''''''''''''''''''''''''''''''''''''''
MSComm1.InputLen = 0
Sleep (250)
ComBuffer = MSComm1.Input
ComBuffer = ComBuffer & MSComm1.Input
For a = 1 To Len(ComBuffer)
    strHex = CStr(Hex(Asc(MidB(ComBuffer, ((a - 1) * 2) + 1, 2))))
    If Len(strHex) = 1 Then
       strBuffer = strBuffer & " " & "0" & strHex
    Else
        strBuffer = strBuffer & " " & strHex
    End If
Next a
Dati = strBuffer
ElaboraDati (Dati)
ElaboraDatiInfoCard (Dati)
Resume Next
End Sub
                                                                          
Private Sub ResetCard()
Dim BufferATR
BufferATR = MSComm1.Input
BufferATR = ""
MSComm1.RTSEnable = True
MSComm1.RTSEnable = False
MSComm1.RThreshold = 16
End Sub

.
.
.
.
.
.
.
.
 


grazias
 



 
alejandrodaniel - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Mostrar mensajes anteriores:    
 
OcultarTemas parecidos
Tema Autor Foro Respuestas último mensaje
No hay nuevos mensajes Manejo Del Puerto Serial scpic General 1 Sabado, 12 Febrero 2011, 22:27 Ver último mensaje
jguardon
No hay nuevos mensajes Pedido De Serial Al Iniciar - Tutorial kingworld Aplicaciones/Fragmentos de Código 1 Viernes, 25 May 2012, 19:34 Ver último mensaje
tonixs
No hay nuevos mensajes Duda Puerto Serial Y Bluetooth Erik Gasca Controles/Librerías/Componentes 4 Viernes, 28 Marzo 2014, 17:03 Ver último mensaje
Erik Gasca
No hay nuevos mensajes Linux & Gambas Liberar Uso De Puertos ... AlfredoSC Controles/Librerías/Componentes 3 Domingo, 23 Febrero 2020, 01:41 Ver último mensaje
vuott
 

Publicar nuevo tema  Responder al tema  Página 1 de 1
 

Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado
Usuarios registrados conectados: Ninguno


 
Lista de permisos
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas
No puede adjuntar archivos
Puede descargar archivos
No puede publicar eventos en el calendario



  

 

cron