Ho trovato qualcosa per te tra le scartoffie.......devo decidermi a riordinarle.........cough.....!cough.....!!

'* Per funzionare, il lettore deve essere configurato
'* porre a fine codice i caratteri CR e LF
'* laser (di codici a barre) in seriale tipo RS-232C

INTERFACCIA GRAFICA
Sul form nuovo e vuoto metti:

1 combobox e nominalo cboCOM
2 textbox le nomini rispettivamente:
txtCOMSettings, txtIn
1 componente MSCom rinominalo con seriale
1 timer nominalo timerto
2 pulsanti li nomini cmdApri, cmdChiudi

'code---------taglia da quì---------------
Option Explicit

Dim Rxbuffer$

Private Sub Form_Load()

Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 5

cboCOM.AddItem "COM1"
cboCOM.AddItem "COM2"
cboCOM.AddItem "COM3"
cboCOM.AddItem "COM4"
cboCOM.ListIndex = 0

txtCOMSettings = "9600,n,8,1"

End Sub

Private Sub cmdApri_Click()
Dim StrAppo$
Dim NrCom%


' Mi assicuro che la porta non sia gia aperta
If Seriale.PortOpen Then MsgBox "Porta gia aperta.": Exit Sub

NrCom% = cboCOM.ListIndex + 1

On Error Resume Next
Seriale.Settings = txtCOMSettings
Seriale.CommPort = NrCom%
If Err Then MsgBox "Errore #1 apertura COM" & NrCom% & Chr$(13) & Error$: Exit Sub

Seriale.NullDiscard = False
Seriale.OutBufferSize = 2048
Seriale.ParityReplace = ""
Seriale.RThreshold = 1
Seriale.SThreshold = 0
Seriale.RTSEnable = True
Seriale.DTREnable = True
Seriale.Handshaking = comNone
Seriale.ParityReplace = "?"

Seriale.PortOpen = True
If Err Then MsgBox "Errore #2 apertura COM" & NrCom% & Chr$(13) & Error$: Exit Sub
StrAppo$ = Seriale.Input ' Svuoto il buffer in ingresso
Seriale.PortOpen = False
Seriale.PortOpen = True
If Err Then MsgBox "Errore #3 apertura COM" & NrCom% & Chr$(13) & Error$: Exit Sub
On Error GoTo 0

' Resetto il TimeOut
timerTO.Enabled = False
timerTO.Tag = ""

cmdApri.Enabled = False
cmdChiudi.Enabled = True

txtIn = ""
Rxbuffer$ = ""

End Sub

Private Sub cmdChiudi_Click()

Seriale.PortOpen = False
cmdApri.Enabled = True
cmdChiudi.Enabled = False

End Sub


Private Sub Seriale_OnComm()

Dim Rx$, Codice$
Dim TagFineCodice$
Dim Pos%

'
' Questo esempio suppone che il codice a barra termina
' con i caratteri CR e LF.
'
TagFineCodice$ = Chr$(13) & Chr$(10)

'
' Leggo la seriale
'
Rx$ = Seriale.Input

'
' Controllo se è scattato il TimeOut
'
If timerTO.Tag = "TO" And Len(Rx$) = 0 Then
If Len(Rxbuffer$) Then
' Simulo la ricezione del marker di fine codice
Rx$ = TagFineCodice$
Else
' Disarmo il timer (questa situazione non dovrebbe mai accadere)
timerTO.Enabled = False
timerTO.Tag = ""
Exit Sub
End If
End If

' se non ho ricevuto nulla, esco subito
If Len(Rx$) = 0 Then Exit Sub

Rxbuffer$ = Rxbuffer$ & Rx$
Do While InStr(Rxbuffer$, TagFineCodice$)
Pos% = InStr(Rxbuffer$, TagFineCodice$)
Codice$ = Left$(Rxbuffer$, Pos%)
Rxbuffer$ = Mid$(Rxbuffer$, Pos% + Len(TagFineCodice$))

'
' Controllo che il codice letto sia corretto
'
'If Len(Codice$) <> 10 Then megbox "Errore, codice letto errato"

'
' Gestico il codice letto.
' Ora mi limito a scriverlo a video
'
txtIn = txtIn & Codice$ & vbCrLf
txtIn.SelStart = Len(txtIn)

Loop

If Len(Rxbuffer$) = 0 Then
' Disarmo il TimeOut
timerTO.Enabled = False
timerTO.Tag = ""
Else
' Ho ricevuto qualcosa, quindi
' Riarmo il TimeOut
timerTO.Enabled = False
timerTO.Enabled = True
timerTO.Tag = ""
End If

End Sub

Private Sub timerTO_Timer()
'
' Time usato per avere un TimeOut
' sulla ricezione
'
timerTO.Tag = "TO"
Call Seriale_OnComm
End Sub
'end code---------fino a quì--------------


Stanotte mi sento in forma.....
questo è l'occasione per dire, ha chi non credeva, come si può comunicazione con la seriale tramite vb, non solo con codice asm o dll.
dimostrazione del controllo MSCom

cough.....! cough...!

'* Ettore Maronese By -MES-
'* 23/11/1998

ciao ettore.........


link
homepage http://%77%77%77%2e%74%77%6f%72%6b%2e%69%74/
forum http://%77%77%77%2e%74%77%6f%72%6b%2...um/default.asp