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.
'''--------------------------------------------------------------------------
'''-------------------------------------------------------------------------
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('_')....