Macro - Send Flaot data

Professional Windows® software to communicate with CAN and CAN FD busses and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
xamrex
Posts: 1
Joined: Tue 9. Jul 2024, 09:23

Macro - Send Flaot data

Post by xamrex » Tue 9. Jul 2024, 09:28

Hello
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
Here is part that I d like to modify to something like:

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
I d like to send float data from lets say 1 to 10.
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?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Macro - Send Flaot data

Post by PEAK-Support » Tue 9. Jul 2024, 09:55

If you want to use float values - create a real Signal with the Symbol Editor and use a Variable to get and set the float Value.
That is the reason why to use a PCAN-Explorer - the decoding of such Signals in real time.
Send a e-mail with your detailed company information, the serial number of your Software to support[at]peak-system.com and we could send you a simple sample.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply