Dim Connected, flag3, flag2, flag, VIT, PORTB, PORTA, PORTC As Integer ' pour connection port module IO/24 com3 usb Private Declare Sub StartDevice Lib "wiiuse.dll" () Private Sub A_Click() If flag2 = 1 Then flag2 = 0 PORTA = 6 ETATPINCE = " Pince fermée " Else flag2 = 1 PORTA = 5 ETATPINCE = " Pince ouverte " End If MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB End Sub Private Sub ARRET_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If PORTC = 0 textvitesse = "0" Label5 = PORTC MSComm1.Output = "C" + Chr$(PORTC) ' envoie sur port C USB End Sub Private Sub AVANCE_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If If VIT = 1 Then PORTC = 12 End If If VIT = 2 Then PORTC = 20 End If If flag3 = 1 Then PORTA = 10 End If Label5 = PORTC MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB MSComm1.Output = "C" + Chr$(PORTC) ' envoie sur port C USB End Sub Private Sub B_Click() ETATB = flag3 If flag3 = 1 Then flag3 = 0 ETATB = " Déplacement Robot " Else flag3 = 1 ETATB = " Déplacement Pince " End If End Sub ' ******* Pour communication IO24 ******* Private Sub Connect_Click() ' Make sure it's not already open If Connected = 1 Then MSComm1.PortOpen = False ' Open the device MSComm1.CommPort = Val(PortNumber) ' PortNumber c'est la zone de texte du meme nom On Error GoTo notopen MSComm1.PortOpen = True On Error GoTo 0 Connected = 1 StatusLabel = "Connected" Call ResetIO24_Click Exit Sub notopen: StatusLabel = "Could Not Open That Port" End Sub Private Sub deux_Click() If flag3 = 0 Then Label2 = " Vitesse Petite " VIT = 1 labelvit = VIT Else flag3 = 1 PORTA = 9 Label3 = "Bras Rentré" End If MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB End Sub Private Sub DROITE_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If If VIT = 1 Then PORTC = 14 End If If VIT = 2 Then PORTC = 22 End If If flag3 = 1 Then PORTA = 41 End If Label5 = PORTC MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB MSComm1.Output = "C" + Chr$(PORTC) ' envoie sur port C USB End Sub Private Sub EcrirePortA_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If PORTA = Val(TextA) MSComm1.Output = "A" + Chr$(PORTA) ' envoie format chaine de caractère End Sub Private Sub EcrirePortB_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If PORTB = Val(TextB) MSComm1.Output = "B" + Chr$(PORTB) ' envoie format chaine de caractère End Sub Private Sub EcrirePortC_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If PORTC = Val(TextC) MSComm1.Output = "C" + Chr$(PORTC) ' envoie format chaine de caractère End Sub Private Sub ETATBRAS_Click() End Sub Private Sub fichierdonnee_Click() Open "C:\Documents and Settings\user\Mes documents\test\letest.txt" For Output As #1 If VIT = 2 Then Print #1, ligne1$; "Vitesse Moyenne" End If If VIT = 1 Then Print #1, ligne1$; "Vitesse Petite" End If If PORTA = 6 Then Print #1, ligne2$; "Pince Fermée" End If If PORTA = 5 Then Print #1, ligne2$; "Pince Ouverte" End If If PORTB = 8 Then Print #1, ligne3$; "Bras Sortie" End If If PORTB = 9 Then Print #1, ligne3$; "Bras Rentré" End If If flag3 = 0 Then Print #1, ligne4$; "Déplacement Robot" End If If flag3 = 1 Then Print #1, ligne4$; "Déplacement Pince" End If Close #1 End Sub Private Sub Form_Load() Connected = 0 flag3 = 0 flag2 = 0 flag = 0 Label2 = " Vitesse Petite " VIT = 1 End Sub Private Sub ResetIO24_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If '****** 2 registres identifiés par !A et A pour le port A '****** Le premier registre !A est le registre de direction (entrée ou sortie) '****** Le deuxième , c'est la valeur (envoyée ou lue) MSComm1.Output = "!A" + Chr$(0) 'PORT A : 0: sortie, 1: entrée MSComm1.Output = "!B" + Chr$(0) 'PORT B en sortie MSComm1.Output = "!C" + Chr$(0) 'PORT C en sortie MSComm1.Output = "A" + Chr$(0) 'PORT A All Low MSComm1.Output = "B" + Chr$(0) 'PORT B All Low MSComm1.Output = "C" + Chr$(0) 'PORT C All Low End Sub Private Sub ChkWII_SetMotion_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) Call WII_SetMotion(0, CLng(ChkWII_SetMotion.Value)) End Sub Private Sub ChkWII_SetIr_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) Call WII_SetIr(0, CLng(ChkWII_SetIr.Value)) End Sub Private Sub CmdWII_Connect_Click() CmdWII_Connect.Enabled = False nb = WII_Connect(AddressOf Callback_WiimoteBTN, AddressOf Callback_IR, AddressOf Callback_Gforce, AddressOf Callback_NunchukBTN) 'nb = WII_Connect(AddressOf Callback_WiimoteBTN, AddressOf Callback_IR, AddressOf Callback_NunchukBTN) If nb > 0 Then Frame1.Enabled = True Frame1.Caption = Str$(nb) & " connecté(s)" Call CmdWII_GetLeds_Click Timer1.Enabled = True End If End Sub Private Sub Check1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single) Dim LED As Long If Check1(0).Value = 1 Then LED = WIIMOTE_LED_1 If Check1(1).Value = 1 Then LED = LED + WIIMOTE_LED_2 If Check1(2).Value = 1 Then LED = LED + WIIMOTE_LED_3 If Check1(3).Value = 1 Then LED = LED + WIIMOTE_LED_4 Call WII_SetLeds(0, LED) End Sub Private Sub ChkWII_SetVibreur_Click() Call WII_SetVibreur(0, ChkWII_SetVibreur.Value) End Sub Private Sub CmdWII_Disconnect_Click() Timer1.Enabled = False Call WII_Disconnect Frame1.Caption = "" Frame1.Enabled = False CmdWII_Connect.Enabled = True End Sub Private Sub CmdWII_GetLeds_Click() Check1(0).Value = WII_GetLeds(0, WIIMOTE_LED_1) Check1(1).Value = WII_GetLeds(0, WIIMOTE_LED_2) Check1(2).Value = WII_GetLeds(0, WIIMOTE_LED_3) Check1(3).Value = WII_GetLeds(0, WIIMOTE_LED_4) End Sub Private Sub Command1_Click() LblBattery.Caption = Str$(WII_GetBattery(0)) End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If Connected = 1 Then MSComm1.PortOpen = False ' Déconnection module IO24ES Call WII_Disconnect End Sub Private Sub LirePortC_Click() '******** Lecture du PORT C *********** '******** '******** Important : il faut régler dans la boite de dialogue du composant MSComm1 '******** InputMode à 1 Sinon lecture marche pas If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If MSComm1.Output = "abc" InputBuffer$ = "" ' Setup a half second timeout for the USBIO24 to respond (Ttakes less than 1ms in reality) T = Timer2 While Timer2 < T + 0.4 And MSComm1.InBufferCount <> 3 Wend If MSComm1.InBufferCount <> 3 Then StatusLabel = "Read Timeout" Exit Sub End If Dim PORTA, PORTB, PORTC As Byte Dim TempBuffer As Variant Dim ByteBuffer() As Byte TempBuffer = MSComm1.Input ByteBuffer = TempBuffer PORTA = ByteBuffer(0) PORTB = ByteBuffer(1) PORTC = ByteBuffer(2) ' TextC = Str$(PORTC) TextC = Str$(PORTC) End Sub Private Sub RWPortC_Click() End Sub Private Sub GAUCHE_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If If VIT = 1 Then PORTC = 13 End If If VIT = 2 Then PORTC = 21 End If If flag3 = 1 Then PORTA = 40 End If Label5 = PORTC MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB MSComm1.Output = "C" + Chr$(PORTC) ' envoie sur port C USB End Sub Private Sub home_Click() If flag = 1 Then flag = 0 ETATCAM = " Gauche / Droite " Else flag = 1 ETATCAM = " Bas / Haut " End If End Sub Private Sub moins_Click() If flag = 0 Then PORTA = 16 Label4 = PORTA Else PORTA = 17 Label4 = PORTA End If MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB End Sub Private Sub plus_Click() If flag = 0 Then PORTA = 18 Label4 = PORTA Else PORTA = 19 Label4 = PORTA End If MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB End Sub Private Sub RECULE_Click() If Connected = 0 Then StatusLabel = "Connectez vous d'abord !" Exit Sub End If If VIT = 1 Then PORTC = 15 End If If VIT = 2 Then PORTC = 23 End If If flag3 = 1 Then PORTA = 11 End If Label5 = PORTC MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB MSComm1.Output = "C" + Chr$(PORTC) ' envoie sur port C USB End Sub Private Sub Timer1_Timer() Timer1.Interval = 30000 LblBattery.Caption = "Batterie " & Str$(WII_GetBattery(0) * 100) & "%" End Sub Private Sub vitesse_Click() End Sub Private Sub un_Click() If flag3 = 0 Then Label2 = " Vitesse Moyenne " VIT = 2 labelvit = VIT Else flag3 = 1 PORTA = 8 Label3 = "Bras Sorti" End If MSComm1.Output = "A" + Chr$(PORTA) ' envoie sur port A USB End Sub