Originariamente inviato da MItaly
Per cambiare lo stato di un singolo pin e tenerlo costante dovresti usare una porta parallela, non una seriale... con la seriale puoi solo inviare dati, per cui il pin RTR finisce con il cambiare stato più volte ad ogni byte che invii...
Non e' cosi' ... esistono segnali nella RS232 che sono costanti e sono utilizzati per l'handshaking ... DTR e' uno di questi ...
Originariamente inviato da marco.santilli
Allora ho la seriale al cui c'è connesso un circuitino fatto apposto per questo da un negoziante che crea queste cose e mi ha detto che è funzionante
Mi ha detto che per far scattare il relè bisogna modificare lo stato del PIN 4 (RTR)
In tutto ci sono attaccati 3 PIN
1) DCD
4) RTR - segnale
5) GND - terra
Sai dirmi come si fa in vb.net ad inviare un segnale al PIN 4????
Come gia' ti ha detto MItaly, il pin 4 e' il DTR (non RTR, che non esiste ...).
Prova ad usare questo codice ...
codice:
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Threading
Imports System.ComponentModel
Imports System.IO
Module Module1
Private Const GENERIC_READ As Integer = &H80000000
Private Const GENERIC_WRITE As Integer = &H40000000
Private Const OPEN_EXISTING As Integer = 3
Private Const SetDtr = 5
Private Const ClearDtr = 6
<DllImport("kernel32.dll", SetlastError:=True, CharSet:=CharSet.Auto)> Private Function CreateFile(ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As IntPtr
End Function
<DllImport("kernel32.dll", SetlastError:=True)> Private Function CloseHandle(ByVal hObject As IntPtr) As Boolean
End Function
<DllImport("kernel32.dll", SetlastError:=True)> Private Function EscapeCommFunction(ByVal hFile As IntPtr, ByVal ifunc As Int32) As Boolean
End Function
Sub Main()
Dim hRS As IntPtr = New IntPtr(0)
hRS = CreateFile("\\.\COM1", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
EscapeCommFunction(hRS, SetDtr)
EscapeCommFunction(hRS, ClearDtr)
CloseHandle(hRS)
End Sub
End Module
Considera che devi usare la
EscapeCommFunction(hRS, SetDtr)
oppure la
EscapeCommFunction(hRS, ClearDtr)
per attivare/disattivare il segnale.
Ovviamente devi cambiare la porta ... (ho messo COM1 per esempio) ...