Serveur d'un port serie au choix du client (dll activex )

Description

Copier le fichier zip attacher copier le dans un repertoire de votre choix et faites fichier make
SerialService.dll

Source / Exemple :


'Section de code de la classe ISerialPort  
'Evenement public de la classe 
'l'evenement et generer lors d'une reception dans dont le port est ouvert .
Public Event GetCommPortInput _ (ByValValueInputString)
        'Variable avec evenement du controle activex mscomm de microsot 
        Private WithEvents CommIn As MSComm
        'variable de la forme SerialPort contenant l'ocx 
        Private MyPort As SerialPort
        'variable servant au suffix et prefix
        Private suffix
        Private prefix
        'variable du port si ouvert = true 
        Private Opencomm As Boolean
Private Sub Class_Initialize()
'-------------------------------------
initialise les instances 
If MyPort Is Nothing Then
    Set MyPort = New SerialPort
End If
'--------------------------------------
If Not MyPort Is Nothing Then
    Set CommIn = MyPort.MSComm1
End If
End Sub
Private Function SetPrefix(ByVal prefix As String) As String
    If Not prefix = "" Then
        SetPrefix = prefix
    Else
        prefix = ""
    End If
End Function
Public Function SetSuffix(ByVal Mysuffix As String) As String
    If Not Mysuffix = "" Then
        SetSuffix = Mysuffix
        suffix = SetSuffix
    Else
        SetSuffix = ""
    End If
End Function
Public Function LoadCommunication(ByVal R_Treshold, ByVal PortNum, ByVal Sett, ByVal OpenPort)
If Not R_Treshold = 0 And Not PortNum = 0 And Not Sett = "" Then
    If Not CommIn Is Nothing Then
        With CommIn
        If Not Opencomm = True Then
            .RThreshold = R_Treshold
            .CommPort = PortNum
            .Settings = Sett
        End If
        If OpenPort = True Then
            .PortOpen = OpenPort
            Opencomm = True
        Else
            .PortOpen = OpenPort
            Opencomm = False
        End If
        End With
    End If
End If
End Function
Private Sub CommIn_OnComm()
Dim StrInput, strData As String
Select Case CommIn.CommEvent
    Case OnCommConstants.comEvReceive
         Do
            StrInput = StrInput & CommIn.Input
            strData = StrInput
         Loop Until InStr(StrInput, suffix)
            RaiseEvent GetCommPortInput(strData)
End Select
End Sub
Public Function SendAsciiCommand(ByVal StrCommand As String)
If Not StrCommand = "" Then
If Not Opencomm = False Then
    CommIn.Output = StrCommand & Chr(13)
End If
End If
End Function

Conclusion :


Pour la bonne comprehension de l'object
1-Faites un nouveaux exe .
2-Referencer la dll (dans projet reference)
3-Dans votre forme principal ajouter une variable
a cette object (ISerialPort)
4-Initialiser le a new ou createobject
5-Utiliser la methode setsuffix pour le charactere de fin (Obligatoire)
5-et ensuite loadCommunication avec en parametre
obligatoire R_Treshold a 1 pour avoir une reception
ex:LoadCommunication 1,1,"9600" & "," & "n" & ,"8" & "," & "1",true
cette commande ouvrirait le port serie numero 1
avec la vitesse de transmission 9600 ,8 bit de depart ,parity a none ,bit de fin a 1

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.

Du même auteur (DcomComMania)