Dim adata(500) As Single Dim j As IntegerPrivate Sub Command1_Click() Timer1.Enabled = True End SubPrivate Sub Command2_Click() Timer1.Enabled = FalseEnd Sub Private Sub Command3_Click()Timer2.Enabled = True End SubPrivate Sub Command4_Click() Timer2.Enabled = False End SubPrivate Sub Form_Load() hDevice = AC6611_CreateDevice(0, pError) '创建设备驱动句柄 If hDevice <> &HFFFFFFFF Then '判断板卡是否存在 Label1.Caption = "AC6611card is exits." Else Label1.Caption = "AC6611card is not exits." End If Picture1.AutoRedraw = True Picture1.Scale (0, 0)-(640, 480) Picture1.Cls End Sub Private Sub Form_Unload(Cancel As Integer) AC6611_CloseDevice hDevice '关闭驱动句柄 End SubPrivate Sub Timer1_Timer() Dim X As Integer, Y As Single, z As Single Dim scaley As Single Dim j As Integer Static i As Integer Dim ADData As Long '定义AD采样变量AC6611_AD hDevice, 0, ADData 'AD采样,0通道,AC6611一共有16个通道0-15,由addata返回AD采样值0-4095 Print AC6611_ADToVoltage(ADData, 0) '显示采样的数据,并转换为0-5V电压实际电压值 scaley = Picture1.ScaleHeight / 4 Picture1.CurrentX = 0 Picture1.CurrentY = Picture1.ScaleHeight / 2 i = i + 1 adata(j) = AC6611_ADToVoltage(ADData, 0) X = i / 30 * scaley Y = adata(j) / 5 * scaley z = adata(j) Picture1.PSet Step(X, -Y), vbRed Open App.Path + "\myfile1.txt" For Append As #1 'For j = 1 To 500 Print #1, z & vbCrLf 'Next j Close #1End SubPrivate Sub Timer2_Timer() Dim X As Integer, Y As Single, z As Single Dim scaley As Single Dim j As Integer Static i As Integer Dim ADData As Long '定义AD采样变量AC6611_AD hDevice, 1, ADData 'AD采样,0通道,AC6611一共有16个通道0-15,由addata返回AD采样值0-4095 Print AC6611_ADToVoltage(ADData, 0) '显示采样的数据,并转换为0-5V电压实际电压值 scaley = Picture2.ScaleHeight / 4 '画曲线 Picture2.CurrentX = 0 Picture2.CurrentY = Picture2.ScaleHeight / 2 i = i + 1 adata(j) = AC6611_ADToVoltage(ADData, 0) X = i / 30 * scaley Y = adata(j) / 5 * scaley z = adata(j) Picture2.PSet Step(X, -Y), vbRed Open App.Path + "\file1.txt" For Append As #2 '记录实时数据 Print #2, z & vbCrLf
Close #2End Sub 这是我的代码
Scale方法是绘点. 画线使用Line方法.
我知道的,用line出来的效果一样的
是不是你的Picture的线型选择的是虚线???
0-solid是虚线么?不会吧。那画其他曲线的时候怎么可以呢
说错了 Pset方法是画点 Scale 方法 用以定义 Form、PictureBox 或 Printer 的坐标系统。 LZ:由于你自定义坐标系统,使得点距改变过大,以至引起视觉上的虚线.你可使点距缩小来达到目的: Private Sub Timer1_Timer() Dim X As Integer, Y As Single, z As Single Dim scaley As Single Dim j As Integer Static i As Integer Dim ADData As Long '定义AD采样变量 AC6611_AD hDevice, 0, ADData 'AD采样,0通道,AC6611一共有16个通道0-15,由addata返回AD采样值0-4095 Print AC6611_ADToVoltage(ADData, 0) '显示采样的数据,并转换为0-5V电压实际电压值 scaley = Picture1.ScaleHeight / 4 Picture1.CurrentX = 0 Picture1.CurrentY = Picture1.ScaleHeight / 2 i = i + 1 adata(j) = AC6611_ADToVoltage(ADData, 0) X = i / 60 * scaley '改变点距,将30改为60 Y = adata(j) / 10 * scaley '改变点距,将5改为10 z = adata(j) Picture1.PSet Step(X, -Y), vbRed Open App.Path + "\myfile1.txt" For Append As #1 Print #1, z & vbCrLf Close #1 End Sub
Dim j As IntegerPrivate Sub Command1_Click()
Timer1.Enabled = True
End SubPrivate Sub Command2_Click()
Timer1.Enabled = FalseEnd Sub
Private Sub Command3_Click()Timer2.Enabled = True
End SubPrivate Sub Command4_Click()
Timer2.Enabled = False
End SubPrivate Sub Form_Load()
hDevice = AC6611_CreateDevice(0, pError) '创建设备驱动句柄
If hDevice <> &HFFFFFFFF Then '判断板卡是否存在
Label1.Caption = "AC6611card is exits."
Else
Label1.Caption = "AC6611card is not exits."
End If
Picture1.AutoRedraw = True
Picture1.Scale (0, 0)-(640, 480)
Picture1.Cls
End Sub
Private Sub Form_Unload(Cancel As Integer)
AC6611_CloseDevice hDevice '关闭驱动句柄
End SubPrivate Sub Timer1_Timer()
Dim X As Integer, Y As Single, z As Single
Dim scaley As Single
Dim j As Integer
Static i As Integer
Dim ADData As Long '定义AD采样变量AC6611_AD hDevice, 0, ADData 'AD采样,0通道,AC6611一共有16个通道0-15,由addata返回AD采样值0-4095
Print AC6611_ADToVoltage(ADData, 0) '显示采样的数据,并转换为0-5V电压实际电压值
scaley = Picture1.ScaleHeight / 4
Picture1.CurrentX = 0
Picture1.CurrentY = Picture1.ScaleHeight / 2
i = i + 1
adata(j) = AC6611_ADToVoltage(ADData, 0)
X = i / 30 * scaley
Y = adata(j) / 5 * scaley
z = adata(j)
Picture1.PSet Step(X, -Y), vbRed
Open App.Path + "\myfile1.txt" For Append As #1
'For j = 1 To 500
Print #1, z & vbCrLf
'Next j
Close #1End SubPrivate Sub Timer2_Timer()
Dim X As Integer, Y As Single, z As Single
Dim scaley As Single
Dim j As Integer
Static i As Integer
Dim ADData As Long '定义AD采样变量AC6611_AD hDevice, 1, ADData 'AD采样,0通道,AC6611一共有16个通道0-15,由addata返回AD采样值0-4095
Print AC6611_ADToVoltage(ADData, 0) '显示采样的数据,并转换为0-5V电压实际电压值
scaley = Picture2.ScaleHeight / 4 '画曲线
Picture2.CurrentX = 0
Picture2.CurrentY = Picture2.ScaleHeight / 2
i = i + 1
adata(j) = AC6611_ADToVoltage(ADData, 0)
X = i / 30 * scaley
Y = adata(j) / 5 * scaley
z = adata(j)
Picture2.PSet Step(X, -Y), vbRed
Open App.Path + "\file1.txt" For Append As #2 '记录实时数据 Print #2, z & vbCrLf
Close #2End Sub
这是我的代码
画线使用Line方法.
Pset方法是画点
Scale 方法
用以定义 Form、PictureBox 或 Printer 的坐标系统。
LZ:由于你自定义坐标系统,使得点距改变过大,以至引起视觉上的虚线.你可使点距缩小来达到目的:
Private Sub Timer1_Timer()
Dim X As Integer, Y As Single, z As Single
Dim scaley As Single
Dim j As Integer
Static i As Integer
Dim ADData As Long '定义AD采样变量
AC6611_AD hDevice, 0, ADData 'AD采样,0通道,AC6611一共有16个通道0-15,由addata返回AD采样值0-4095
Print AC6611_ADToVoltage(ADData, 0) '显示采样的数据,并转换为0-5V电压实际电压值
scaley = Picture1.ScaleHeight / 4
Picture1.CurrentX = 0
Picture1.CurrentY = Picture1.ScaleHeight / 2
i = i + 1
adata(j) = AC6611_ADToVoltage(ADData, 0)
X = i / 60 * scaley '改变点距,将30改为60
Y = adata(j) / 10 * scaley '改变点距,将5改为10
z = adata(j)
Picture1.PSet Step(X, -Y), vbRed
Open App.Path + "\myfile1.txt" For Append As #1
Print #1, z & vbCrLf
Close #1
End Sub
用line也试过了,。我现在就再想怎么把前后采集到的两点用线连起来。
事实上LZ不必在这上面过度废心思.用Line方法,将画线宽度设置大些,就可掩盖了.
DrawWidth 属性用来指定图形方法输出时线的宽度,BorderWidth 属性用来指定直线和形状控件轮廓线的粗细。
下列过程将画出几条不同宽度的线。
Private Sub Form_Click ()
DrawWidth = 1
Line (100, 1000)–(3000, 1000)
DrawWidth = 5
Line (100, 1500)–(3000, 1500)
DrawWidth = 8
Line (100, 2000)–(3000, 2000)
End Sub说明
增大该属性值会增加线的宽度。如果 DrawWidth 属性值大于 1,DrawStyle 属性值设置为 1 到 4 时会画出一条实线来(DrawStyle 属性值不会改变)。将 DrawWidth 设置为 1,允许 DrawStyle 产生 DrawStyle 属性表中列出的结果。
x_new = i '终点座标
y_new = Sin(2 * 3.14159 * plot_freq * i / RangeW) * plot_amp + RangeH / 2
'画直线
Picture1.Line (x_old, y_old)-(x_new, y_new), RGB(255, 0, 0)
x_old = x_new '将终点座标变成下一次的起始点座标
y_old = y_new
i = i + 1
Loop While i < RangeW