sp.Open(cmbPort.Value)
sp.SetParams (115200,8,1,0)
sp.ReadingThreadInterval=1
astream.Initialize(sp.GetInputStream, sp.GetOutputStream, "astream")
Sub btnStart_Action
If cmbPort.Enabled Then
fx.Msgbox(MainForm,"Сначало нужно выбрать COM порт","Ошибка:")
Else
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
End If
End Sub
Sub CRC8 (b0 As Int,b1 As Int,b2 As Int,b3 As Int,b4 As Int,b5 As Int,b6 As Int) As Int
'Log(ForCRC(Bit.Xor(b6,ForCRC(Bit.Xor(b5,ForCRC(Bit.Xor(b4,ForCRC(Bit.Xor(b3,ForCRC(Bit.Xor(b2,ForCRC(Bit.Xor(b1,ForCRC(Bit.Xor(0,b0)))))))))))))))
Return ForCRC(Bit.Xor(b6,ForCRC(Bit.Xor(b5,ForCRC(Bit.Xor(b4,ForCRC(Bit.Xor(b3,ForCRC(Bit.Xor(b2,ForCRC(Bit.Xor(b1,ForCRC(Bit.Xor(0,b0))))))))))))))
End Sub
Sub AStream_NewData (Buffer() As Byte)
For ii = 0 To Buffer.Length-1
New123(j)=Buffer(ii)
j=j+1
If j = 8 Then
'Dim n As Long = DateTime.Now
j=0
If New123(5)<0 Then
Sbyte=Bit.And(New123(5),127)
Sbyte=Bit.Or(Sbyte,128)
Else
Sbyte=New123(5)
End If
If New123(6)<0 Then
Mbyte=Bit.And(New123(6),127)
Mbyte=Bit.Or(Mbyte,128)
Else
Mbyte=New123(6)
End If
Sig=Sbyte
Sig=Bit.ShiftLeft(Sig,8)
Sig=Bit.Or(Sig,Mbyte)
Sig=640-(Sig/102.4)
If Sig>Por Then
Col1=0
Col2=0
Col3=255
Else
Col1=255
Col2=0
Col3=0
End If
Graf
'Log(DateTime.Now - n) 'in milliseconds
End If
Next
End Sub
Sub Graf
'temp=1
If x=0 Then
x=1
Canvas1.DrawLine(0,0,1,Sig,fx.Colors.Blue,1)
OldSig=Sig
Move
Else
Canvas1.DrawLine(t,OldSig,t+1,Sig,fx.Colors.RGB(Col1,Col2,Col3),2)
OldSig=Sig
t=t+temp
Move
End If
End Sub
Private Sub Move
If t>=720 Then
x=0
t=1
Canvas1.ClearRect(0, 0, 720, 640)
End If
If SS=0 Then
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
Else
SS=0
End If
End Sub
Timer1.Initialize("Timer1", 1)
Timer1.Enabled=True
Sub Timer1_Tick
Sig=Rnd(16384,49170)
Sig=640-(Sig/102.4)
If Sig>Por Then
Col1=0
Col2=0
Col3=255
Else
Col1=255
Col2=0
Col3=0
End If
Graf
End Sub
Sub btnStart_Action
If cmbPort.Enabled Then
fx.Msgbox(MainForm,"Сначало нужно выбрать COM порт","Ошибка:")
Else
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
End If
End Sub
Sub AStream_NewData (Buffer() As Byte)
For ii = 0 To Buffer.Length-1
New123(j)=Buffer(ii)
j=j+1
If j = 8 Then
'Dim n As Long = DateTime.Now
j=0
If New123(5)<0 Then
Sbyte=Bit.And(New123(5),127)
Sbyte=Bit.Or(Sbyte,128)
Else
Sbyte=New123(5)
End If
If New123(6)<0 Then
Mbyte=Bit.And(New123(6),127)
Mbyte=Bit.Or(Mbyte,128)
Else
Mbyte=New123(6)
End If
Sig=Sbyte
Sig=Bit.ShiftLeft(Sig,8)
Sig=Bit.Or(Sig,Mbyte)
Sig=640-(Sig/102.4)
If Sig>Por Then
Col1=0
Col2=0
Col3=255
Else
Col1=255
Col2=0
Col3=0
End If
Graf
'Log(DateTime.Now - n) 'in milliseconds
End If
Next
End Sub
Sub Graf
If x=0 Then
x=1
Canvas1.DrawLine(0,0,1,Sig,fx.Colors.Blue,1)
OldSig=Sig
Move
Else
Canvas1.DrawLine(t,OldSig,t+1,Sig,fx.Colors.RGB(Col1,Col2,Col3),2)
OldSig=Sig
t=t+temp
Move
End If
End Sub
Private Sub Move
If t>=720 Then
x=0
t=1
Canvas1.ClearRect(0, 0, 720, 640)
End If
If SS=0 Then
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
Else
SS=0
End If
End Sub
Sub AStream_NewData (Buffer() As Byte)
There is no delay there. It sends the data as quickly as possible.Is there any way to increase the speed of sending a message "astream.Write"?
Private kan=1 As Int
Timer1.Initialize("Timer1", 1)
Timer1.Enabled=True
Sub Timer1_Tick
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x01,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
End Sub
Sub CRC8 (b0 As Int,b1 As Int,b2 As Int,b3 As Int,b4 As Int,b5 As Int,b6 As Int) As Int
Return ForCRC(Bit.Xor(b6,ForCRC(Bit.Xor(b5,ForCRC(Bit.Xor(b4,ForCRC(Bit.Xor(b3,ForCRC(Bit.Xor(b2,ForCRC(Bit.Xor(b1,ForCRC(Bit.Xor(0,b0))))))))))))))
End Sub
Sub btnStart_Action
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
End Sub
Sub AStream_NewData (Buffer() As Byte)
For ii = 0 To Buffer.Length-1
New123(j)=Buffer(ii)
j=j+1
If j = 8 Then
j=0
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
End If
Next
End Sub
Sub btnStart_Action
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
End Sub
Sub AStream_NewData (Buffer() As Byte)
For ii = 0 To Buffer.Length-1
New123(j)=Buffer(ii)
j=j+1
If j = 8 Then
j=0
astream.Write(Array As Byte(0x00,0x07,0x52,0x00,kan,0x00,0x00,CRC8(0x00,0x07,0x52,0x00,kan,0x00,0x00)))
End If
Next
End Sub