Des touches fantomes !

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
KrisJNT
Messages : 110
Inscription : ven. 31/oct./2008 16:51

Des touches fantomes !

Message par KrisJNT »

Bonjour à tous !

Voici un programme que j'essaye de faire pour envoyer un message via le port COM1 à un µControlleur. Voici le bug :
Une fois le programme lancé, tapez "Bonjour !" ou ce que vous voulez, puis amusez-vous avec les touches directionnelles : des caractères se tapent tout seul !!!

Voila le code source :

Code : Tout sélectionner

InitSprite() : InitKeyboard()
LoadFont(0, "Arial", 20, #PB_Font_HighQuality)

Global x = 0
Global y = 0
Global blackit

Global Dim char(20, 2)

Procedure drawBG()
  Box(0, 0, 600, 200, $A7C6A1)
  For b = 0 To 19
    Box(30 * b + 2, 2, 28, 38, $9BBE93)
    Box(30 * b + 2, 44, 28, 38, $9BBE93)
  Next
EndProcedure

Procedure drawTchar()
  DrawingFont(FontID(0))
  For u = 0 To 19
    For v = 0 To 1
      DrawText(30 * u + 2 + Int((28 - TextWidth(Chr(char(u, v))))/2), 42 * v + 40 - TextHeight(Chr(char(u, v))), Chr(char(u, v)), 0, $9BBE93)
    Next
  Next
EndProcedure

Procedure blackIT(delay)
  Repeat
    blackit = ~blackit
    Delay(delay)
  ForEver
EndProcedure

Procedure caClignoooooote(delay)
  CreateThread(@blackIT(), delay)
  Repeat
    FlipBuffers()
    StartDrawing(ScreenOutput())
      drawBG()
      drawTchar()
      If blackit : Box(30 * x + 2, 42 * y + 2, 28, 38, 0) : EndIf
    StopDrawing()
  ForEver
EndProcedure

Procedure sendData()
  dat$ = ""
  For l = 0 To 1
    For c = 0 To 19
      dat$ = dat$ + Chr(char(c, l))
    Next
    dat$ = dat$ + Chr(10)
  Next
  
  WriteSerialPortString(0, dat$, #PB_Ascii)
EndProcedure

lcdStart.s = " LCD Writer v:1.0.1 " + Chr(10) + "********************"
OpenSerialPort(0, "COM1", 110, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 0, 40)
WriteSerialPortString(0, lcdStart, #PB_Ascii)

CreateImage(0, 600, 84)

OpenWindow(0, 10, 10, 600, 84, "LCD Writer", #PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 600, 84, 1, 0, 0)

CreateThread(@caClignoooooote(), 500)

Repeat
  event = WaitWindowEvent(10)
  
  If GetAsyncKeyState_(#VK_RETURN)
    SetWindowTitle(0, "TRANSFERT...")
    sendData()
    SetWindowTitle(0, "LCD Writer")
  EndIf
  
  ExamineKeyboard()
  key$ = KeyboardInkey()

  If key$
    Debug key$
    char(x, y) = Asc(key$)
    If x = 19
      y = (y + 1) % 2
    EndIf
    x = (x + 1) % 20
 EndIf
  
  If GetAsyncKeyState_(#VK_BACK)
    If Not temoinB Or ElapsedMilliseconds() - ctrB >= 250
      char(x, y) = 0
      x = x - 1
      If x = -1 : x = 19 : y = (y + 1) % 2 : EndIf
      temoinB = 1
      ctrB = ElapsedMilliseconds()
    EndIf
  Else
    temoinB = 0
  EndIf
  
  If GetAsyncKeyState_(#VK_F1) And (GetAsyncKeyState_(#VK_LCONTROL) Or GetAsyncKeyState_(#VK_RCONTROL))
    If Not temoinLIGHT
      light.s = Chr(7)
      WriteSerialPortString(0, light, #PB_Ascii)
      temoinLIGHT = 1
    EndIf
  Else
    temoinLIGHT = 0
  EndIf
  
  If GetAsyncKeyState_(#VK_RIGHT)
    If Not temoinL Or ElapsedMilliseconds() - ctrR >= 250
      x = (x + 1) % 20
      blackit = -1
      temoinL = 1
      ctrR = ElapsedMilliseconds()
    EndIf
  Else
    temoinL = 0
  EndIf
  
  If GetAsyncKeyState_(#VK_LEFT)
    If Not temoinR Or ElapsedMilliseconds() - ctrL >= 250
      x = x - 1
      If x = -1 : x = 19 : EndIf
      blackit = -1
      temoinR = 1
      ctrL = ElapsedMilliseconds()  
    EndIf
  Else
    temoinR = 0
  EndIf
  
  If GetAsyncKeyState_(#VK_UP) Or GetAsyncKeyState_(#VK_DOWN)
    If Not temoinUD Or ElapsedMilliseconds() - ctrUD >= 250
      y = (y + 1) % 2
      blackit = -1
      temoinUD = 1
      ctrUD = ElapsedMilliseconds()
    EndIf
  Else
    temoinUD = 0
  EndIf
Until event = #PB_Event_CloseWindow
; IDE Options = PureBasic 4.30 (Windows - x86)
; CursorPosition = 81
; FirstLine = 67
; Folding = -
; EnableXP
Merci pour votre aide !

Kris
KrisJNT
Messages : 110
Inscription : ven. 31/oct./2008 16:51

Message par KrisJNT »

Je vois qu'il n'y a pas de réponses... pour 40 lectures. Alors je précise ma question : savez-vous d'où pourrait venir ce bug ? :)
Atomo
Messages : 207
Inscription : lun. 17/sept./2007 12:27

Message par Atomo »

Je viens de tester et je n'ai eu aucun problème, désolé de ne pas pouvoir t'aider :?
KrisJNT
Messages : 110
Inscription : ven. 31/oct./2008 16:51

Message par KrisJNT »

Bizarre bizarre... J'ai testé sur 3 PC différents, et même problèmes :
Configurations :
1) Proc : Intel Celeron 500MHz x86
Ram : 128 Mo
DirectX : 7

2) Proc : Intel Pentium III 1.2GHz x86
Ram : 384 Mo
DirectX : 9

3) Proc : AMD Athlon XP 2000 +
Ram : 512 Mo
DirectX : 9

Essayez avec ces combinaisons de touches en boucles Haut-Gauche-Bas-Gauche, des lettres s'écrivent toutes eules et seules celles qui sont à l'écran reviennent !!! :o
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

j'ai tester sans probleme
il ya pas de bug sur le mien

Proc : DualCore E6650
Ram: 4000 Mo
Direct x 9.0C
KrisJNT
Messages : 110
Inscription : ven. 31/oct./2008 16:51

Message par KrisJNT »

Comment avez-vous configuré votre Compilo ?
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

quel compilo tu parle?????

j'ai jute copier ton code dans japbe et appuiez sur f5 pour tester
Atomo
Messages : 207
Inscription : lun. 17/sept./2007 12:27

Message par Atomo »

Par défaut, c'est à dire juste Enable XP skin support, par contre je désactive ces 2 lignes sinon ça plante chez moi :

60) OpenSerialPort(0, "COM1", 110, #PB_SerialPort_NoParity, 8,1,#PB_SerialPort_NoHandshake, 0, 40)
61) WriteSerialPortString(0, lcdStart, #PB_Ascii)

Je suis sur Vista SP1.
KrisJNT
Messages : 110
Inscription : ven. 31/oct./2008 16:51

Message par KrisJNT »

Tu n'as peut-être pas de port série sur ton Vista ^^.
Pour le compilo, je parle des configurations comme "Activer le supprot des thèmes XP", "Gestion avancée des Threads", etc. Bref, quelles config avez-vous par défaut ? :?
jbernard13
Messages : 1501
Inscription : dim. 18/avr./2004 15:04
Localisation : sud de la france

Message par jbernard13 »

KrisJNT

je suis sous window xp

tu utilise Japbe?
KrisJNT
Messages : 110
Inscription : ven. 31/oct./2008 16:51

Message par KrisJNT »

non, l'IDE par défaut, mais le compilo reste le même il me semble. Sinon, je peux toujours essayer.
Atomo
Messages : 207
Inscription : lun. 17/sept./2007 12:27

Message par Atomo »

KrisJNT a écrit :quelles config avez-vous par défaut ? :?
J'ai répondu à la question plus haut :
juste Enable XP skin support
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Message par Ar-S »

Je dois aussi desactiver la ligne

Code : Tout sélectionner

;WriteSerialPortString(0, lcdStart, #PB_Ascii)
pour qu'il fonctionne.

Par defaut mon IDE est regler sur :
- Activer support des themes XP
- Exe compatible NT4

Je suis en PB 4.30 sous winXP
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Ollivier
Messages : 4197
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Message par Ollivier »

@KrisJNT

Enlève les lignes propres au port série et vérifie si l'erreur persiste. J'ai testé ton code et pas d'erreur.

Ollivier
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Message par Kwai chang caine »

Moi tel quel....j'ai bien des caracteres qui s'ecrivent tout seul quand je deplace le curseur :roll:
Répondre