problemi con trasmissione parallela
Moderatori:
Paolino,
fairyvilje
21 messaggi
• Pagina 2 di 3 • 1, 2, 3
0
voti
programmi distribuiti sotto forma di giocattolo che puoi inserire nel tuo progetto con la stessa facilita' con cui oggi inserisci pulsanti caselle di testo etc (anche quelli sono controlli activex!)
un esempio classico e fornito con VB è MSCOMM che pero' ti fa usare le porte seriali e non LPT, l'altro postato prima dovrebbe permetterti di accedere anche a porte LPT, per il momento pero' non ho avuto modo di provarlo
un esempio classico e fornito con VB è MSCOMM che pero' ti fa usare le porte seriali e non LPT, l'altro postato prima dovrebbe permetterti di accedere anche a porte LPT, per il momento pero' non ho avuto modo di provarlo
0
voti
programmi distribuiti sotto forma di giocattolo
Bellissima!
Sono proprio come i giocattoli, se li apri si rompono !!!!
LOL

Credo che MSCOMM ti faccia accedere anche alla parallela, comunque, Bill perdonami, ecco il codice completo (viene da qui: http://support.microsoft.com/kb/823179)
Te lo isolo nella parte dedicata alla parallela perché la pagina è abbastanza incomprensibile:
-
- Codice: Seleziona tutto
Option Strict On
' Define a CommException class that inherits from the ApplicationException class.
' Then throw an object of type CommException when you receive an error message.
Class CommException
Inherits ApplicationException
Sub New(ByVal Reason As String)
MyBase.New(Reason)
End Sub
End Class
Module Module1
'Declare structures
Public Structure DCB
Public DCBlength As Int32
Public BaudRate As Int32
Public fBitFields As Int32
Public wReserved As Int16
Public XonLim As Int16
Public XoffLim As Int16
Public ByteSize As Byte
Public Parity As Byte
Public StopBits As Byte
Public XonChar As Byte
Public XoffChar As Byte
Public ErrorChar As Byte
Public EofChar As Byte
Public EvtChar As Byte
Public wReserved1 As Int16 'Reserved; Do Not Use
End Structure
Public Structure COMMTIMEOUTS
Public ReadIntervalTimeout As Int32
Public ReadTotalTimeoutMultiplier As Int32
Public ReadTotalTimeoutConstant As Int32
Public WriteTotalTimeoutMultiplier As Int32
Public WriteTotalTimeoutConstant As Int32
End Structure
'Declare constants.
Public Const GENERIC_READ As Int32 = &H80000000
Public Const GENERIC_WRITE As Int32 = &H40000000
Public Const OPEN_EXISTING As Int32 = 3
Public Const FILE_ATTRIBUTE_NORMAL As Int32 = &H80
Public Const NOPARITY As Int32 = 0
Public Const ONESTOPBIT As Int32 = 0
'Declare references to external functions.
Public Declare Auto Function CreateFile Lib "kernel32.dll" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Int32, _
ByVal dwShareMode As Int32, ByVal lpSecurityAttributes As IntPtr, _
ByVal dwCreationDisposition As Int32, ByVal dwFlagsAndAttributes As Int32, _
ByVal hTemplateFile As IntPtr) As IntPtr
Public Declare Auto Function GetCommState Lib "kernel32.dll" (ByVal nCid As IntPtr, _
ByRef lpDCB As DCB) As Boolean
Public Declare Auto Function SetCommState Lib "kernel32.dll" (ByVal nCid As IntPtr, _
ByRef lpDCB As DCB) As Boolean
Public Declare Auto Function GetCommTimeouts Lib "kernel32.dll" (ByVal hFile As IntPtr, _
ByRef lpCommTimeouts As COMMTIMEOUTS) As Boolean
Public Declare Auto Function SetCommTimeouts Lib "kernel32.dll" (ByVal hFile As IntPtr, _
ByRef lpCommTimeouts As COMMTIMEOUTS) As Boolean
Public Declare Auto Function WriteFile Lib "kernel32.dll" (ByVal hFile As IntPtr, _
ByVal lpBuffer As Byte(), ByVal nNumberOfBytesToWrite As Int32, _
ByRef lpNumberOfBytesWritten As Int32, ByVal lpOverlapped As IntPtr) As Boolean
Public Declare Auto Function ReadFile Lib "kernel32.dll" (ByVal hFile As IntPtr, _
ByVal lpBuffer As Byte(), ByVal nNumberOfBytesToRead As Int32, _
ByRef lpNumberOfBytesRead As Int32, ByVal lpOverlapped As IntPtr) As Boolean
Public Declare Auto Function CloseHandle Lib "kernel32.dll" (ByVal hObject As IntPtr) As Boolean
Sub Main()
' Declare local variables that you will use in the code.
Dim hSerialPort, hParallelPort As IntPtr
Dim Success As Boolean
Dim MyDCB As DCB
Dim MyCommTimeouts As COMMTIMEOUTS
Dim BytesWritten, BytesRead As Int32
Dim Buffer() As Byte
' Declare variables to use for encoding.
Dim oEncoder As New System.Text.ASCIIEncoding
Dim oEnc As System.Text.Encoding = oEncoder.GetEncoding(1252)
' Convert String to Byte().
Buffer = oEnc.GetBytes("Test")
Try
' Serial port.
Console.WriteLine("Accessing the COM1 serial port")
' Obtain a handle to the COM1 serial port.
hSerialPort = CreateFile("COM1", GENERIC_READ Or GENERIC_WRITE, 0, IntPtr.Zero, _
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero)
' Verify that the obtained handle is valid.
If hSerialPort.ToInt32 = -1 Then
Throw New CommException("Unable to obtain a handle to the COM1 port")
End If
' Retrieve the current control settings.
Success = GetCommState(hSerialPort, MyDCB)
If Success = False Then
Throw New CommException("Unable to retrieve the current control settings")
End If
' Modify the properties of the retrieved DCB structure as appropriate.
' WARNING: Make sure to modify the properties according to their supported values.
MyDCB.BaudRate = 9600
MyDCB.ByteSize = 8
MyDCB.Parity = NOPARITY
MyDCB.StopBits = ONESTOPBIT
' Reconfigure COM1 based on the properties of the modified DCB structure.
Success = SetCommState(hSerialPort, MyDCB)
If Success = False Then
Throw New CommException("Unable to reconfigure COM1")
End If
' Retrieve the current time-out settings.
Success = GetCommTimeouts(hSerialPort, MyCommTimeouts)
If Success = False Then
Throw New CommException("Unable to retrieve current time-out settings")
End If
' Modify the properties of the retrieved COMMTIMEOUTS structure as appropriate.
' WARNING: Make sure to modify the properties according to their supported values.
MyCommTimeouts.ReadIntervalTimeout = 0
MyCommTimeouts.ReadTotalTimeoutConstant = 0
MyCommTimeouts.ReadTotalTimeoutMultiplier = 0
MyCommTimeouts.WriteTotalTimeoutConstant = 0
MyCommTimeouts.WriteTotalTimeoutMultiplier = 0
' Reconfigure the time-out settings, based on the properties of the modified COMMTIMEOUTS structure.
Success = SetCommTimeouts(hSerialPort, MyCommTimeouts)
If Success = False Then
Throw New CommException("Unable to reconfigure the time-out settings")
End If
' Write data to COM1.
Console.WriteLine("Writing the following data to COM1: Test")
Success = WriteFile(hSerialPort, Buffer, Buffer.Length, BytesWritten, IntPtr.Zero)
If Success = False Then
Throw New CommException("Unable to write to COM1")
End If
' Read data from COM1.
Success = ReadFile(hSerialPort, Buffer, BytesWritten, BytesRead, IntPtr.Zero)
If Success = False Then
Throw New CommException("Unable to read from COM1")
End If
Catch ex As Exception
Console.WriteLine(Ex.Message)
Finally
' Release the handle to COM1.
Success = CloseHandle(hSerialPort)
If Success = False Then
Console.WriteLine("Unable to release handle to COM1")
End If
End Try
Try
' Parallel port.
Console.WriteLine("Accessing the LPT1 parallel port")
' Obtain a handle to the LPT1 parallel port.
hParallelPort = CreateFile("LPT1", GENERIC_READ Or GENERIC_WRITE, 0, IntPtr.Zero, _
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero)
' Verify that the obtained handle is valid.
If hParallelPort.ToInt32 = -1 Then
Throw New CommException("Unable to obtain a handle to the LPT1 port")
End If
' Retrieve the current control settings.
Success = GetCommState(hParallelPort, MyDCB)
If Success = False Then
Throw New CommException("Unable to retrieve the current control settings")
End If
' Modify the properties of the retrieved DCB structure as appropriate.
' WARNING: Make sure to modify the properties according to their supported values.
MyDCB.BaudRate = 9600
MyDCB.ByteSize = 8
MyDCB.Parity = NOPARITY
MyDCB.StopBits = ONESTOPBIT
' Reconfigure LPT1 based on the properties of MyDCB.
Success = SetCommState(hParallelPort, MyDCB)
If Success = False Then
Throw New CommException("Unable to reconfigure LPT1")
End If
' Reconfigure LPT1 based on the properties of the modified DCB structure.
Success = GetCommTimeouts(hParallelPort, MyCommTimeouts)
If Success = False Then
Throw New CommException("Unable to retrieve current time-out settings")
End If
' Modify the properties of the retrieved COMMTIMEOUTS structure as appropriate.
' WARNING: Make sure to modify the properties according to their supported values.
MyCommTimeouts.ReadIntervalTimeout = 0
MyCommTimeouts.ReadTotalTimeoutConstant = 0
MyCommTimeouts.ReadTotalTimeoutMultiplier = 0
MyCommTimeouts.WriteTotalTimeoutConstant = 0
MyCommTimeouts.WriteTotalTimeoutMultiplier = 0
' Reconfigure the time-out settings, based on the properties of the modified COMMTIMEOUTS structure.
Success = SetCommTimeouts(hParallelPort, MyCommTimeouts)
If Success = False Then
Throw New CommException("Unable to reconfigure the time-out settings")
End If
' Write data to LPT1.
' Note: You cannot read data from a parallel port by calling the ReadFile function.
Console.WriteLine("Writing the following data to LPT1: Test")
Success = WriteFile(hParallelPort, Buffer, Buffer.Length, BytesWritten, IntPtr.Zero)
If Success = False Then
Throw New CommException("Unable to write to LPT1")
End If
Catch ex As Exception
Console.WriteLine(Ex.Message)
Finally
' Release the handle to LPT1.
Success = CloseHandle(hParallelPort)
If Success = False Then
Console.WriteLine("Unable to release handle to LPT1")
End If
End Try
Console.WriteLine("Press ENTER to quit")
Console.ReadLine()
End Sub
End Module
-

Lelettrico
2.458 1 4 6 - Master

- Messaggi: 1108
- Iscritto il: 13 set 2010, 12:24
0
voti
@Lele visto - sorry ma non lo ricordavo (o usavo una versione precedente bho) è dal 98 che non uso questi toys :P e comunque i controlli di zio Billy non mi sono mai piaciuti
@kbdj scarica http://www.mvps.org/rgrier/IOOcxInstall.zip, decomprimilo e segui l'installazione al riavvio di VB6 nella toolbox hai nuove icone o se non appaiono direttamente nel menu' Progetto seleziona Componenti e metti un segno di spunta accanto al nome del componente a questo punto dalla toolbox inserisci il componente nel form


aggiornamento: beh visto che anche mscomm puo' - puoi risparmiarti una nuova installazione
@kbdj scarica http://www.mvps.org/rgrier/IOOcxInstall.zip, decomprimilo e segui l'installazione al riavvio di VB6 nella toolbox hai nuove icone o se non appaiono direttamente nel menu' Progetto seleziona Componenti e metti un segno di spunta accanto al nome del componente a questo punto dalla toolbox inserisci il componente nel form


aggiornamento: beh visto che anche mscomm puo' - puoi risparmiarti una nuova installazione
0
voti
ok... ho installato activex.
se ho capito (e non ne sono molto sicuro) dovrei copiare il codice proposto da Lelettrico nella ruotine del nuovo componente che ho aggiungo... giusto???
se ho capito (e non ne sono molto sicuro) dovrei copiare il codice proposto da Lelettrico nella ruotine del nuovo componente che ho aggiungo... giusto???
0
voti
no :)
nel pulsante1_click
scrivi
ioocx1.writeaddress=indirizzo (per lpt1 &h378-&h37f, lpt2 &h278-&h27f)
ioocx1.writeio(dati_da_scrivere)
es.:
ioocx1.writeaddress=&H378
ioocx.writeio(1);
' accende led pin1 (d0)
nel pulsante1_click
scrivi
ioocx1.writeaddress=indirizzo (per lpt1 &h378-&h37f, lpt2 &h278-&h27f)
ioocx1.writeio(dati_da_scrivere)
es.:
ioocx1.writeaddress=&H378
ioocx.writeio(1);
' accende led pin1 (d0)
0
voti
Non capisco semi stai prendendo in giro o se sei veramente prima delle prime armi:
eccetera ... eccetera
Leggi la pagina che ti ho linkato EOT
Utilizzare il controllo MSComm in Visual Basic .NET per accedere alle porte seriali
Perché non classi Microsoft.NET Framework esistono per accedere alle risorse di comunicazioni che collegata al computer, è possibile utilizzare il controllo MSComm in Microsoft Visual Basic 6.0. Controllo MSComm fornisce comunicazioni seriali per la vostra applicazione, consentendo la trasmissione e la ricezione di dati tramite una porta seriale. Implementare comunicazioni seriali di base utilizzando un modem, segui questi passaggi:
Avviare Microsoft Visual Studio. NET.
Scegliere nuovo dal menu file, quindi progetto.
In Tipi progetto, fare clic su Progetti di Visual Basic.
In modelli, fare clic su Applicazione Console.
Nella casella nome, digitare MyConsoleApplication e quindi fare clic su OK.
Per impostazione predefinita, viene creato Module1.vb.
Destro del progetto MyConsoleApplication e quindi scegliere Aggiungi riferimento.
Fare clic sulla scheda COM, fare clic su Microsoft com controllo 6.0 in Nome componente, fare clic su Seleziona e quindi fare clic su OK.
Nota Per utilizzare il controllo MSComm, è necessario installare i relativi componenti COM di Microsoft Visual Basic 6.0 sullo stesso computer che dispone di Microsoft Visual Studio .NET installato.
eccetera ... eccetera
Leggi la pagina che ti ho linkato EOT
-

Lelettrico
2.458 1 4 6 - Master

- Messaggi: 1108
- Iscritto il: 13 set 2010, 12:24
0
voti
NON CI STO A CAPI NIENTE...
allora, io è la prima valta che uso la trasmissione trasmite porta parallela con visula basi... l'ha spiegata poco tempo fa il mio prof di sistemi, però mi aveva detto che bisognava solo aggiungere un modulo che permetteva la trasmissione parallela. non mi ha parlato di tutto questo bordello.
di solito sono uno che apprende al volo... ma questa volta proprio non ci riesco.
vi chiedo un favore grandissimo... postare il codice con rispettivo form. se è possibile aggiungere ad ogni riga un'etichetta che mi spieghi che cosa fa quell''istruzione. per favore scrivere in linguaggio assembly non in linguaggio C...
grazie.
allora, io è la prima valta che uso la trasmissione trasmite porta parallela con visula basi... l'ha spiegata poco tempo fa il mio prof di sistemi, però mi aveva detto che bisognava solo aggiungere un modulo che permetteva la trasmissione parallela. non mi ha parlato di tutto questo bordello.
di solito sono uno che apprende al volo... ma questa volta proprio non ci riesco.
vi chiedo un favore grandissimo... postare il codice con rispettivo form. se è possibile aggiungere ad ogni riga un'etichetta che mi spieghi che cosa fa quell''istruzione. per favore scrivere in linguaggio assembly non in linguaggio C...
grazie.
21 messaggi
• Pagina 2 di 3 • 1, 2, 3
Chi c’è in linea
Visitano il forum: Google Adsense [Bot] e 13 ospiti

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)



