Getting back value to transmit

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
oliv
Posts: 3
Joined: Wed 29. Aug 2012, 16:23

Getting back value to transmit

Post by oliv » Wed 29. Aug 2012, 16:31

Hello to all,
I would like to make a VBscript to configure a device automatically. I succeed in transmitting few times the same frame with different value with standard macro. Now I would like to read bytes in a reception frame and put it in an emission frame. I think that is not possible with the standard macro, but it is in VBscript.

The problem is that I’m completely novice in writing VBscipt.
Below, you will find an example of the wanted function

Send 1 300h 12h 00h 00h 00h 00h 00h 00h 00h
Send 1 300h 43h 00h 00h 00h 00h 00h 00h 00h

Then I will received:
Received 1 400h 8F 01h 02h 03h 04h

Send 1 300h 13h 21h 10h 00h 00h 00h 00h 00h
Send 1 300h 21h 01h 02h 03h 04h
Send 1 300h 22h 01h 02h 03h 04h

If someone can give me the trick to do that, it would be very helpful.
Thanks a lot in advance

Regards

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

Re: Getting back value to transmit

Post by PEAK-Support » Thu 30. Aug 2012, 09:18

Without any VBS Basics it is hard to start. You will find a lot of VBS Samples all over the WEB.
Here a small code for PE5 that check if a defined CAN Frame is received.

Code: Select all

'------------------------------------------------------------------------------
'FILE DESCRIPTION:RecvCAN Data
'------------------------------------------------------------------------------

Sub RecvCANData()
'DESCRIPTION: Read CAN Data - see if in a defined CAN Msg data one Bit is set
  ' To view the output messages of this macro, open the Output Window and
  '  select the "Macro" tab
  Dim MyClient, MyConn
  Set MyClient = CreateObject("Pcan3.PCANClient")
  MyClient.Name = "RecvCANDataMacro"
  If Connections.Count > 0 And Connections(1).Protocol = peProtocolCAN Then
    ' Connect to the same Net that the first connection in the
    '  current project uses
    Dim obj
    Set obj = Connections(1).CommunicationObject
    MyClient.Device = obj.Parent.Device
    Set MyConn = MyClient.Connections.Add(obj.NetName)
  Else
    ' Connect to the default "TestNet"
    Set MyConn = MyClient.Connections.Add("TestNet")
  End IF

  If MyConn.IsConnected = False Then
	MsgBox "Cannot connect to Net" 
	Exit Sub
  End If

  ' MyConn.RegisterMsg &H000, &H800, False, False
  ' MyConn.RegisterMsg &H00000000, &H1FFFFFFF, True, True
  ' MyConn.RegisterMsg &H600, &H1FFFFFFF, True, True
  PrintToOutputWindow "Start the Read...."
  i = 0
  Dim RcvMsg
  Set RcvMsg = MyClient.Messages.Add
  Do
  	Do While not RcvMsg.Read
	  ' Wait for a received message
	   Wait(10)	' Prevent 100% CPU load
    Loop
	If RcvMsg.LastError = pcanErrorOk Then
	 If RcvMsg.DLC > 0 Then ' Yes, >0 DLC ist OK 
	  If RcvMsg.Data(0) AND &h80 Then
	  	PrintToOutputWindow "Received CAN ID: " & CStr(RcvMsg.ID)
	    PrintToOutputWindow "Data0 is set to 0x80"
	    i = i + 1
	   End If
	  End If  
	End IF
  Loop While RcvMsg.ID <> &H001 ' Stop when receiving ID 0x001
  PrintToOutputWindow "Finished, " & CStr(i) & " messages 0x80 in Data0 received !"
End Sub
It is also very simple to add Write Messages to such a script:

Code: Select all

 ' Now create and initialize a new transmit message
  Dim msg
  Set msg = MyClient.Messages.Add
  timestamp = MyClient.GetSystemTime + 50
  With msg
    .ID = &H100
    .DLC = 4
    .MsgType = pcanMsgTypeExtended
    .Data(0) = &H11
    .Data(1) = &H22
    .Data(2) = &H33
  End With
  for i = 1 To 20
    msg.Data(3) = i
    msg.Write MyConn, timestamp
    timestamp = timestamp + 10
  next
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

oliv
Posts: 3
Joined: Wed 29. Aug 2012, 16:23

Re: Getting back value to transmit

Post by oliv » Thu 30. Aug 2012, 11:31

Thanks for your quick answer.

What does that mean: "Connect to the same Net that the first connection in the
current project uses"

I might use the same usb/can interface or the same usb port connection.
Actually I have the message "cannot connect to Net".

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

Re: Getting back value to transmit

Post by PEAK-Support » Thu 30. Aug 2012, 12:16

If you have still define a Connection in your PE5 project- than this Connection will be useed.
If not it will use the Connection with the NetName "TestNet" (you need to add this to your project)
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

oliv
Posts: 3
Joined: Wed 29. Aug 2012, 16:23

Re: Getting back value to transmit

Post by oliv » Thu 30. Aug 2012, 14:06

It doesn't work whereas my configuration seems to be ok (see the sreen print in attached)
Attachments
imp_ecr.png
imp_ecr.png (135.53 KiB) Viewed 10153 times

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

Re: Getting back value to transmit

Post by PEAK-Support » Thu 30. Aug 2012, 15:01

Please send us the complete project files (we need all) to our support(at)peak-system.com E-Mail Address, we will take a look at it.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

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

Re: Getting back value to transmit

Post by PEAK-Support » Sun 1. Feb 2015, 10:21

Thread closed
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply