I d like to write macro where float data will be send.
I base on the example:
Code: Select all
Sub NewClientSend()
'DESCRIPTION: Sends CAN messages using a new PCAN client
Dim UseConn, conn
' Find the first enabled connection in the project that uses the CAN protocol
Set UseConn = Nothing
For Each conn In Connections
If conn.IsEnabled And conn.Protocol = peProtocolCAN Then
Set UseConn = conn
Exit For
End If
Next
If UseConn Is Nothing Then
MsgBox "Project does not contain any enabled CAN connections"
Exit Sub
End If
' Create a new client and connect it to the same Net that the
' found connection uses
Dim MyClient, PcanConn
Set MyClient = CreateObject("PCAN4.PCANClient")
MyClient.Device = UseConn.Device
MyClient.Name = "Macro"
Set PcanConn = MyClient.Connections.Add(UseConn.CommunicationObject.NetName)
' Now create and initialize a new transmit message
Dim msg, timestamp, i
Set msg = MyClient.Messages.Add
timestamp = MyClient.GetSystemTime + 1000
With msg
.ID = &H100
.DLC = 5
.MsgType = pcanMsgTypeExtended
.Data(0) = &H11
.Data(1) = &H22
.Data(2) = &H33
.Data(3) = &H33
End With
for i = 1 To 20
msg.Data(3) = i
msg.Write PcanConn, timestamp
timestamp = timestamp + 500
next
' Wait until all messages have been sent before finishing macro,
' since this would terminate the client and delete all messages
' that are still in the queue
While not MyClient.XmtQueueEmpty
Wait 500
Wend
Wait 500
End Sub
Code: Select all
for i = 1 To 20
.Data(0) = &H3F
.Data(1) = &H80
.Data(2) = &H00
.Data(3) = &H00
msg.Write PcanConn, timestamp
timestamp = timestamp + 500
next
So:
Number one would be:
.Data(0) = &H3F
.Data(1) = &H80
.Data(2) = &H00
.Data(3) = &H00
Number Two would be:
.Data(0) = &H40
.Data(1) = &H00
.Data(2) = &H00
.Data(3) = &H00
Etc.
How to convert float to 4 bytes?