TODOPIC

Lenguajes de programación para PC => Visual Basic => Mensaje iniciado por: IAO en 19 de Diciembre de 2008, 19:58:36

Título: Pregunta sobre Picture.Line y RS232.
Publicado por: IAO en 19 de Diciembre de 2008, 19:58:36
Holaaaa:

Saludos...
Con la ayuda de un programa del Sr. Palistroquez y otro de internet he armado un programa que genera una
senoidal y la envía por RS232 y la auto recibe. Hasta aquí todo me funciona bien. Cuando intento colocar en el PictureBox
lo recibido no encuentro la menera que esta me muestre el gráfico.


Para verlo funcionar debe conectarse los pines 2 y 3 del serial port un puente. Si se tiene instalado el VSPD
no va a funcionar, hay que quitarle el par creado en el VSPD(Virtual Serial Port Driver).

Dejo el código a ver si alguno de ustedes logra ayudarme. En que parte debo colocar el código para que salga
el grafico en el PictureBox. De verdad llevo días y no doy pie con el asunto.
Código: [Seleccionar]
'''--------------------------------------------------------------------------
'''-------------------------------------------------------------------------
Option Explicit

'Sleep desde la API de Windows que Fenomenal
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Dim cx As Integer, cy As Integer
Dim cx1 As Integer, cy1 As Integer
Dim i As Integer, j As Long, desplazar As Integer
Dim dato(1000) As Double
Dim pcx As Long, pcy As Long
Dim fcx As Long, fcy As Long
'Dim m As Long

'Dim s As String
Const pi = 3.14159265358979
Const MaxNumberOfPoints = 100     ' the number of points in the chart i.e. number of
                                  ' most recent samples which shall be displayed


Private Sub Form_Load()

    Option1.Value = True        'Coloca Selecionado Com1 con el Botón Option1

    cy = Picture1.ScaleHeight   ' 117
    cx = Picture1.ScaleWidth    ' 253
   
    cy1 = Picture1.ScaleHeight  ' 117
    cx1 = Picture1.ScaleWidth   ' 253
   
    pcx = Picture1.Width
    pcy = Picture1.Height
   
    fcx = Me.Width
    fcy = Me.Height
   
    Command1.Caption = "Dibuje"
   
End Sub

Private Sub Form_Resize()
    Picture1.Cls

    Picture1.Height = Form1.Height / (fcy / pcy)
    Picture1.Width = Form1.Width / (fcx / pcx)
   
    Picture1.ScaleHeight = Picture1.Height / (pcy / cy1)
    Picture1.ScaleWidth = Picture1.Width / (pcx / cx1)
    cy = Picture1.ScaleHeight
    cx = Picture1.ScaleWidth
   
End Sub

Private Sub Option1_Click()
    Dim i As Long
   
    Dim h As Double
    Dim a As Double
    'desplazar = 0 '?

    Dim data(MaxNumberOfPoints - 1) As Double

    ' ------ simulation -----
    MSComm1.OutBufferSize = 10 * MaxNumberOfPoints
    ' ------ simulation -----

    Const Blocksize = 5                            'Number of samples after which the chart shall be updated
    MSComm1.RThreshold = Blocksize                 'Fire event if the input buffer contains at least Blocksize new samples
    MSComm1.InputLen = 10 * MaxNumberOfPoints
    MSComm1.InputMode = comInputModeBinary

    MSComm1.CommPort = 1                   ' open the serial port
    MSComm1.Settings = "9600,N,8,1"
    MSComm1.PortOpen = True


      For i = 0 To MaxNumberOfPoints - 1     ' clear data array
        data(i) = 0
    Next

'''''Pienso que podría ser aquí.
'''''       

    ' ------ simulation -----
    Timer1.Interval = 20
    Timer1.Enabled = True
    ' ------ simulation -----


End Sub

Private Sub Form_Terminate()    '''Cuando se finaliza el Formulario
    If MSComm1.PortOpen = True Then
    MSComm1.PortOpen = False
    End If
       
    End
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If MSComm1.PortOpen = True Then
    MSComm1.PortOpen = False
    End If
End Sub

Private Sub MSComm1_OnComm()
    Dim i As Long, NumNewPoints As Long
    Dim Arr() As Byte
    Dim data() As Double
   
   Select Case MSComm1.CommEvent
       Case comEvReceive
           NumNewPoints = MSComm1.InBufferCount                    ' the actual number of samples in the input buffer
                                                                   ' can be greater than Blocksize!
           Arr = MSComm1.Input                                     ' move the new data to a temporary array
           ReDim data(NumNewPoints - 1)
           For i = 0 To NumNewPoints - 1
               data(i) = Arr(i) - 128                              ' convert to signed data and scale if necessary
           Next
    End Select
End Sub

'''------ Simulation -----
Private Sub Timer1_Timer()
Dim i As Integer
Dim s As String
Dim m As Double
Static phase As Double
Const numsamples = 3  '0.5 '1 '3       '''number of new samples to append to the data stream

    '''simulate a sine wave signal
    For i = 0 To cx 'numsamples - 1
    '''Cambiar el valor 127 , 128, 0.11 para ver la diferencia.
    ''''m = 127 * Sin((i + phase) * 0.11) + 128
        m = 60 * Sin((i + phase) * 0.11) + 120
        s = s & Chr(m)
    Next
   
    phase = phase + numsamples
    MSComm1.Output = s ' send
    '
End Sub
'''------ simulation -----


Private Sub Picture1_Click()
Picture1.Cls
With Picture1
  .AutoRedraw = False    'Lo hacemos visible
  .Visible = True
  End With
End Sub


Espero puedan entenderme y ayudarme.
Bye('_')....
Título: Re: Pregunta sobre Picture.Line y RS232.
Publicado por: IAO en 20 de Diciembre de 2008, 12:12:37
Holaaa:

Ok. ya logré que se vea en el PictureBox.
Aunque con unos detalles que es lo que voy a ir  resolviendo, poco a poco.
En lo que finalice se los paso. A ver que tal me quedó.

(http://img183.imageshack.us/img183/8137/captura1it0.png) (http://[URL=http://imageshack.us)]Captura Imagen[/url]



Esto fue lo que modifiqué, por si alguno necesita hacer pruebas.....
Código: [Seleccionar]
Private Sub MSComm1_OnComm()
    Dim i As Long, NumNewPoints As Long
    Dim Arr() As Byte
    Dim data() As Double
   
   Select Case MSComm1.CommEvent
       Case comEvReceive
           NumNewPoints = MSComm1.InBufferCount                    ' the actual number of samples in the input buffer
                                                                   ' can be greater than Blocksize!
           Arr = MSComm1.Input                                     ' move the new data to a temporary array
           ReDim data(NumNewPoints - 1)
           For i = 0 To NumNewPoints - 1
               data(i) = Arr(i) - 128                              ' convert to signed data and scale if necessary
       
        j = data(i)
        dato(i + 1) = (cy / 2) - (j / 2) 'senoidal
        Picture1.Line (i, dato(i))-(i, dato(i + 1)), vbBlue
       
            Next

    End Select
End Sub



Bye('_').....
Título: Re: Pregunta sobre Picture.Line y RS232.
Publicado por: PalitroqueZ en 20 de Diciembre de 2008, 18:05:40
Hola Ruben,

ya veo que solucionaste el problema, si es ahí donde se llama al método Line. Por supuesto que hay que procesar el dato recibido para que se ajuste al picture.



Título: Re: Pregunta sobre Picture.Line y RS232.
Publicado por: IAO en 20 de Diciembre de 2008, 18:31:05
Hola Pedro:

Feliz Navidad, tiempo sin conversar. He estado un poco fuera de onda.

Si, ya logré que se viera.
Ando con el lio de que desplace la onda, pero esta noche creo que lo termino.
-
Siempre siguiendo la ayuda de tu Tutorial de gráficas Pedro. Que Dios te haga un lugar en el cielo.
-
Saludos a todos...
Feliz Navidad....Jojojojo :-)
Bye('_')....
Título: Re: Pregunta sobre Picture.Line y RS232.
Publicado por: BrunoF en 23 de Enero de 2009, 15:52:18
Hola IAO. Que es lo que querés desplazar?
Título: Re: Pregunta sobre Picture.Line y RS232.
Publicado por: IAO en 24 de Enero de 2009, 18:32:53
Holaaaaa:

Hola maestro BrunoF:
Te comento que ya logré que desplazara la señal, pero quedo con un error en los
exremos que no he podido corregir.
Si gustas ve como quedó el programita, aquí te dejo el link en este subforo...
http://www.todopic.com.ar/foros/index.php?topic=16233.msg196337#msg196337

Bye('_')....