Annexe 1 : Programme en VB6 de Serial Port Writer Private Declare Function lstrcpy Lib "KERNEL32" Alias "lstrcpya" (ByVal lpstring1 As Any, _ ByVal lpstring2 As Any) As Long Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, _ Source As Any, ByVal Length As Long) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'DECLARARTION DES DLL ET DES TYPES DE VARIABLES POUR LA RECUPERATION DES ADRESSES IP DYNAMIQUES' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Private Const WS_VERSION_REQD = &H101 Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF& Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF& Private Const MIN_SOCKETS_REQD = 1 Private Const SOCKET_ERROR = -1 Private Const WSADescription_Len = 256 Private Const WSASYS_Status_Len = 128 Private Type HOSTENT hname As Long haliases As Long haddrtype As Integer hlength As Integer haddrlist As Long End Type Private Type WSADATA wversion As Integer whighversion As Integer szdescription(0 To WSADescription_Len) As Byte szsystemstatus(0 To WSASYS_Status_Len) As Byte imaxsockets As Integer imaxudpdg As Integer lpszvendorinfo As Long End Type Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal _
wversionrequired As Integer, lpwsadata As WSADATA) As Long Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal hostname$, _ ByVal HostLen As Long) As Long Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal _ hostname$) As Long Private Declare Sub RtlMoveMemory Lib "KERNEL32" (hpvdest As Any, ByVal _ hpvsource&, ByVal cbcopy&) Private Function CopieChaine(ByVal adresse As Long) As String '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'FONCTION PERMETTANT DE RECUPERER LES CHAINES DE CARACTERES DANS UNE BASE MySQL' 'Elle récupere les chaines a une adresse donnée. ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim ret As String If adresse > 0 Then ret = Space(256) lstrcpy ret, adresse ret = Trim(ret) If ret <> "" Then CopieChaine = left(ret, Len(ret) - 1) End Function Private Sub EnumTables(pMySQL As Long) ''''''''''''''''''''''''''''''''''''''''''''''' 'LISTER DES TABLES DE LA BASE DE DONNEES MySQL' ''''''''''''''''''''''''''''''''''''''''''''''' Dim pmyrow As Long, myrow As Long, pmyres As Long, i As Long 'Connexion a la bdd If mysql_real_connect(pmysql, "127.0.0.1", "root", "", "mpi", 0, "", 0) = 0 Then MsgBox "la connexion a échoué" pmyres = mysql_list_tables(pmysql, "") If (pmyres <> 0) Then For i = 0 To mysql_num_rows(pmyres) - 1 pmyrow = mysql_fetch_row(pmyres) CopyMemory myrow, ByVal pmyrow, 4 ListBox1.AddItem CopieChaine(myROW) Next
mysql_free_result (pmyres) mysql_close (pmysql) Private Sub LitEnregistrements(pMySQL As Long) ''''''''''''''''''''''''''''''''' 'ACCEDER AUX DONNEES DE LA TABLE' ''''''''''''''''''''''''''''''''' Dim texta, textb, textc As String Dim pmyrow As Long, myrow As Long, plengths As Long, pmyres As Long Dim i As Long, j As Long, nbfields As Long, lengths() As Long, texte As String 'Connexion a la bdd If mysql_real_connect(pmysql, "127.0.0.1", "root", "", "mpi", 0, "", 0) = 0 Then MsgBox "la connexion a échoué" 'Ouverture de la table et selection de l'enregistrement If (mysql_query(pmysql, "select * from 3st") = 0) Then pmyres = mysql_store_result(pmysql) 'Stockage de l'enregistrement dans une variable If (pmyres <> 0) Then nbfields = mysql_num_fields(pmyres) 'Determination du nombre de champ de la table If nbfields > 0 Then ReDim lengths(0 To nbfields - 1) 'redimensionnement de la variable lenghts qui est de type long par defaut For i = 0 To mysql_num_rows(pmyres) - 1 'boucle servant a definir les pointeurs et a specifier leur contenu pmyrow = mysql_fetch_row(pmyres) CopyMemory myrow, ByVal pmyrow, 4 plengths = mysql_fetch_lengths(pmyres) CopyMemory lengths(0), ByVal plengths, 4 * nbfields 'pour j=0, on indexe le premier champ de l'enregistrement ie le champ id de la table 3st texte = Space(lengths(0)) 'on recupere la valeur de l'enregistrement du champ lstrcpy texte, myrow 'puis on met l'adresse de l'enregistrement courant dans la variable myrow
myrow = myrow + lengths(0) + 1 'LabeletatS3.Caption = texte, on a pas besoin de le faire afficher 'alors on leurre le systeme afin qu'au passage suivant le pointeur 'passe aisement a l'adresse suivante. 'pour j=1, on indexe le 2nd champ ie le champ S1 de la meme table texte = Space(lengths(1)) lstrcpy texte, myrow myrow = myrow + lengths(1) + 1 texta = texte If texta = 1 Then 'on compare la valeur de la table a la valeur 1 LabeletatS1.Caption = "ON" ' S1=1 dans la table LabeletatS1.BackColor = &HC0FFC0 'S1 prend une couleur verte LabeletatS1.Caption = "OFF" 'S1=0 dans la table LabeletatS1.BackColor = &H8080FF ' S1 prend une couleur rouge 'pour J=2, on indexe le 3eme champ de l'enregistrement ie S2 texte = Space(lengths(2)) lstrcpy texte, myrow myrow = myrow + lengths(2) + 1 textb = texte If textb = 1 Then 'on compare la valeur de la table a la valeur 1 LabeletatS2.Caption = "ON" LabeletatS2.BackColor = &HC0FFC0 LabeletatS2.Caption = "OFF" LabeletatS2.BackColor = &H8080FF 'pour j=3, on indexe le 4 eme champ de l'enregistrement ie S3 texte = Space(lengths(3)) lstrcpy texte, myrow myrow = myrow + lengths(3) + 1 textc = texte If textc = 1 Then LabeletatS3.Caption = "ON" LabeletatS3.BackColor = &HC0FFC0 LabeletatS3.Caption = "OFF" LabeletatS3.BackColor = &H8080FF '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'boucle de test, elle a servie a tester les lignes de code plus haut!!!' 'For j = 0 To nbfields - 1 ' 'texte = Space(lengths(j)) '
'lstrcpy texte, myrow 'myrow = myrow + lengths(j) + 1 'ListBox2.AddItem texte '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Next Next mysql_free_result (pmyres) mysql_close (pmysql) 'ListBox2.text = "" Private Sub Combobalayage_click() balayage = Val(Combobalayage.Text) ' ' ' Private Sub Command1_click() If Command1.BackColor = &HC0FFC0 Then Command1.BackColor = &H808FF Command1.Caption = "Ouverture du port" 'choix du port et declaration des caracteristiques MSComm1.CommPort = 1 MSComm1.Settings = "9600,N,8,1" MSComm1.PortOpen = True 'ouverture du port 'fin de la declaration des caracteristiques 'appel de la procedure de transmission des bits Timerport.Enabled = True Command1.BackColor = &HC0FFC0 Command1.Caption = "Fermeture du port" Timerport.Enabled = False MSComm1.PortOpen = False 'fermeture du port Private Sub Commandmarche_Click() ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Congiguration du temps de balayage des entrees de la table' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' balayage = Combobalayage.Text 'Selection de la duree de balayage 'Un petit controle pour que le temps de balayage ne soit jamais nul If Combobalayage.Text = "" Then MsgBox " Veuillez selectionner un temps de balayage." If Commandmarche.BackColor = &HC0FFC0 Then Commandmarche.BackColor = &H808FF Commandmarche.Caption = "OFF" Combobalayage.Enabled = False Timerbalayage.Interval = balayage 'attribution de la duree de balayage au timer Timerbalayage.Enabled = True ' enclenchement de la temporisation Commandmarche.BackColor = &HC0FFC0 Commandmarche.Caption = "ON" Combobalayage.Enabled = True Timerbalayage.Enabled = False Private Sub Form_Load() SocketsInitialize 'renvoie de l'adresse ip Dim hostname As String * 256 Dim hostent_addr As Long Dim host As HOSTENT Dim hostip_addr As Long Dim temp_ip_address() As Byte Dim i As Integer Dim ip_address As String If gethostname(hostname, 256) = SOCKET_ERROR Then MsgBox "Windows Sockets error " & Str(WSAGetLastError()) Exit Sub hostname = Trim$(hostname) hostent_addr = gethostbyname(hostname) If hostent_addr = 0 Then
MsgBox "Winsock.dll is not responding." Exit Sub RtlMoveMemory host, hostent_addr, LenB(host) RtlMoveMemory hostip_addr, host.haddrlist, 4 'MsgBox hostname 'get all of the IP address if machine is multi-homed Do ReDim temp_ip_address(1 To host.hlength) RtlMoveMemory temp_ip_address(1), hostip_addr, host.hlength For i = 1 To host.hlength ip_address = ip_address & temp_ip_address(i) & "." Next ip_address = Mid$(ip_address, 1, Len(ip_address) - 1) 'MsgBox ip_address Labelip.Caption = ip_address ip_address = "" host.haddrlist = host.haddrlist + LenB(host.hAddrList) RtlMoveMemory hostip_addr, host.haddrlist, 4 Loop While (hostip_addr <> 0) Private Sub Label4_Click() Private Sub Timerbalayage_Timer() Dim pmysql As Long pmysql = mysql_init(0) Call LitEnregistrements(pMySQL) Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If MSComm1.PortOpen = True Then MSComm1.PortOpen = False 'fermeture du port
SocketsCleanup Private Sub Timerport_Timer() 'S1,S2 et S3 sont off If LabeletatS1.Caption = "OFF" And LabeletatS2.Caption = "OFF" And LabeletatS3.Caption = "OFF" Then MSComm1.DTREnable = False 'S2 MSComm1.RTSEnable = False 'S3 MSComm1.Break = False 'S1 'S1 est on, S2 et S3 sont Off If LabeletatS1.Caption = "ON" And LabeletatS2.Caption = "OFF" And LabeletatS3.Caption = "OFF" Then MSComm1.DTREnable = False 'S2 MSComm1.RTSEnable = False 'S3 MSComm1.Break = True 'S1 'S1 est off, S2 est On et S3 est off If LabeletatS1.Caption = "OFF" And LabeletatS2.Caption = "ON" And LabeletatS3.Caption = "OFF" Then MSComm1.DTREnable = True 'S2 MSComm1.RTSEnable = False 'S3 MSComm1.Break = False 'S1 'S1 et S2 sont off, S3 est on If LabeletatS1.Caption = "OFF" And LabeletatS2.Caption = "OFF" And LabeletatS3.Caption = "ON" Then MSComm1.DTREnable = False 'S2 MSComm1.RTSEnable = True 'S3 MSComm1.Break = False 'S1 'S1 et S2 sont on, S3 est off If LabeletatS1.Caption = "ON" And LabeletatS2.Caption = "ON" And LabeletatS3.Caption = "OFF" Then MSComm1.DTREnable = True 'S2 MSComm1.RTSEnable = False 'S3 MSComm1.Break = True 'S1 'S1 est on, S2 est off et S3 est on
If LabeletatS1.Caption = "ON" And LabeletatS2.Caption = "OFF" And LabeletatS3.Caption = "ON" Then MSComm1.DTREnable = False 'S2 MSComm1.RTSEnable = True 'S3 MSComm1.Break = True 'S1 'S1 est off, S2 et S3 sont on If LabeletatS1.Caption = "OFF" And LabeletatS2.Caption = "ON" And LabeletatS3.Caption = "ON" Then MSComm1.DTREnable = True 'S2 MSComm1.RTSEnable = True 'S3 MSComm1.Break = False 'S1 'S1,S2 et S3 sont on If LabeletatS1.Caption = "ON" And LabeletatS2.Caption = "ON" And LabeletatS3.Caption = "ON" Then MSComm1.DTREnable = True 'S2 MSComm1.RTSEnable = True 'S3 MSComm1.Break = True 'S1 Function hibyte(byval wparam As Integer) hibyte = wparam \ &H100 And &HFF& End Function Function lobyte(byval wparam As Integer) lobyte = wparam And &HFF& End Function Sub SocketsInitialize() Dim WSAD As WSADATA Dim ireturn As Integer Dim slowbyte As String, shighbyte As String, smsg As String ireturn = WSAStartup(WS_VERSION_REQD, WSAD) If ireturn <> 0 Then MsgBox "Winsock.dll is not responding." End
If lobyte(wsad.wversion) < WS_VERSION_MAJOR Or (lobyte(wsad.wversion) = _ WS_VERSION_MAJOR And hibyte(wsad.wversion) < WS_VERSION_MINOR) Then shighbyte = Trim$(Str$(hibyte(WSAD.wversion))) slowbyte = Trim$(Str$(lobyte(WSAD.wversion))) smsg = "Windows Sockets version " & slowbyte & "." & shighbyte smsg = smsg & " is not supported by winsock.dll " MsgBox smsg End 'imaxsockets is not used in winsock 2. So the following check is only 'necessary for winsock 1. If winsock 2 is requested, 'the following check can be skipped. If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then smsg = "This application requires a minimum of " smsg = smsg & Trim$(Str$(MIN_SOCKETS_REQD)) & " supported sockets." MsgBox smsg End Sub SocketsCleanup() Dim lreturn As Long lreturn = WSACleanup() If lreturn <> 0 Then MsgBox "Socket error " & Trim$(Str$(lReturn)) & " occurred in Cleanup " End
Thème : PILOTER TROIS SORTIES VIA LE PORT SERIE Annexe 2 Annexe 2: Photos prises lors du montage des composants sur la plaquette
Thème : PILOTER TROIS SORTIES VIA LE PORT SERIE Annexe 3 Annexe 3: Source de la page d index PHP affichant le formulaire <?php session_start(); define("bd_host","127.0.0.1"); # adresse de la base de données (127.0.0.1 en local) define("bd_login","root" ); # login base de données (root en local) define("bd_pass","" ); # mot de passe base de données (inutile en local) define("bd_name","mpi" ); # nom de la BD // J'ai choisi le mot de passe "kangourou" if (isset($_post['mot_de_passe'])) // Si la variable existe { // On se crée une variable $mot_de_passe avec le mot de passe entré $mot_de_passe = $_POST['mot_de_passe']; } else // La variable n'existe pas encore { $mot_de_passe = ""; // On crée une variable $mot_de_passe vide } if(isset($_get['deconnexion'])) { $_SESSION = array(); session_destroy(); $mot_de_passe = ""; } if ($mot_de_passe == "maxzener" OR isset($_session['password']) ) // Si le mot de passe est bon { $_SESSION['password']='true'; // On affiche la page cachée. // CONNEXION MySQL ------------------------------------------------------------- $mysql_link=mysql_connect(bd_host, bd_login, bd_pass); if (!$mysql_link) die("echec : Impossible de se connecter à MySQL."); mysql_select_db(bd_name) or include("creationbd.php"); // Lecture de l'état des sorties dans la base----------------------------------- $query="select S1,S2,S3 FROM 3st WHERE id='1'"; $result=mysql_query($query,$mysql_link); $sorties=mysql_fetch_array($result); if ( $sorties['s1']=="1" ) $sorties['s1']="checked"; else $sorties['s1']=""; if ( $sorties['s2']=="1" ) $sorties['s2']="checked"; else $sorties['s2']=""; if ( $sorties['s3']=="1" ) $sorties['s3']="checked"; else $sorties['s3']="";?> <HTML>
Thème : PILOTER TROIS SORTIES VIA LE PORT SERIE Annexe 3 <HEAD> <TITLE>MESURER VIA INTERNET : 3 Sorties sur Triacs</TITLE> <link rel="stylesheet" media="screen" type="text/css" title="exemple" href="design.css" /> </HEAD> <BODY> <center><img src="logo.gif" /></center></br> <?php echo'<b><center>bienvenue sur la page de configuration des sorties du port serie</b></center>'?> <FORM METHOD="post" ACTION="3sttraitement.php"> <P><CENTER> <INPUT TYPE="checkbox" NAME="S1" VALUE="1" > Sortie n 1<BR> <INPUT TYPE="checkbox" NAME="S2" VALUE="1" > Sortie n 2<BR> <INPUT TYPE="checkbox" NAME="S3" VALUE="1" > Sortie n 3 </CENTER></P> <P><CENTER> <INPUT NAME="action" TYPE="submit" VALUE="Envoyer"></br></br></br></br></br></br></br> </br></br></br> Dernière mise à jour: <?php $repons=mysql_query('select * FROM 3st'); $donnees=mysql_fetch_array($repons); echo date('d.m.y',$donnees['timestamp']); echo ' par '.$donnees['ip'];?> </CENTER></P> </FORM> <?php } else {?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <title>page protégée par mot de passe</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> </head> <body> <p>veuillez entrer le login et le mot de passe pour acceder à la page de configuration des sorties :</p> <form action="index.php" method="post">
Thème : PILOTER TROIS SORTIES VIA LE PORT SERIE Annexe 3 <fieldset> <legend>connexion</legend> <p> <label for="pseudo">pseudo</label> <input type="text" name="pseudo" id="pseudo" /></br> <label for="password">password</label> <input type="password" name="mot_de_passe" id="password" /> </br> </p></fieldset></br> <input type="submit" value="valider" /> </form> <p>cette page est réservée au personnel de la société ZENER TECHONOLOGY. Si vous ne travaillez pas dans la société ZENER TECHNOLOGIE, inutile d'insister vous ne trouverez jamais le mot de passe!</p> </body> </html> <?php } // Fin du else // Fin du code :)?> </BODY> </HTML>
Thème : PILOTER TROIS SORTIES VIA LE PORT SERIE Annexe 4 Annexe 4: Source de la page PHP traitant les données du formulaire <?php define("bd_host","127.0.0.1"); # adresse de la base de données (127.0.0.1 en local) define("bd_login","root" ); # login base de données (root en local) define("bd_pass","" ); # mot de passe base de données (inutile en local) define("bd_name","mpi" ); # nom de la BD // CONNEXION MySQL ------------------------------------------------------------- $mysql_link=mysql_connect(bd_host, bd_login, bd_pass); if (!$mysql_link) die("echec : Impossible de se connecter à MySQL."); mysql_select_db(bd_name) or include("creationbd.php"); // Mise à jour de l'état des sorties dans la base------------------------------- //if(isset($_post['action']) AND isset($_post['s1']) AND isset($_post['s3']) AND isset($_post['s3'])){ if ($_POST['action']=='Envoyer') { $query="update 3st SET S1='".$_POST['S1']."', S2='".$_POST['S2']."', S3='".$_POST['S3']."', timestamp='".time()."', ip='".$_server['remote_addr']."' WHERE id='1'"; if (!mysql_query($query,$mysql_link) ) echo("impossible de mettre à jour les sorties"); echo'<center>'; echo'les sorties ont été mises à jour</br>'; $reponse = mysql_query('select * FROM 3st'); $donnees = mysql_fetch_array($reponse); //echo date('d/m/y', $donnees['timestamp']); if (date('d.m.y', $donnees['timestamp']) == date('d.m.y', time())) echo'aujourd\'hui à '.date('h\hi', $donnees['timestamp']); elseif (date('d.m.y', $donnees['timestamp']) == date('d.m.y', time() - 86400)) echo'hier à '.date('h\hi', $donnees['timestamp']); else echo'à '.date('h\hi \l\e d M y',$donnees['timestamp']); } echo'</br></br></br>cliquez <a href="index.php">ici</a> pour retourner à la page de mise à jour des sorties'; echo'</br></br></br>cliquez <a href="index.php?deconnexion=true">ici</a> pour vous deconnecter</center>';?>