Message in Receive list

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
janamoosa
Posts: 5
Joined: Mon 24. Sep 2012, 16:39

Message in Receive list

Post by janamoosa » Mon 24. Sep 2012, 16:46

Hello,
I am new to Pcan and I am trying to create a Vb to send a message of 8 byte using the Pcan Explorer 5 with version 5.2.0.754. I used the program NewClientSend Macros described in the Pcan. It is working fine but the message 100h is displayed on receive list. But it has to be displayed on Transmit window as I want to send the message in the CAN bus. Please help me what is going wrong in it.

Regards,
Jana

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

Re: Message in Receive list

Post by PEAK-Support » Mon 24. Sep 2012, 19:32

Nothing is going wrong. Your Macro is a seperate CAN Client, and send the Message to the CAN Driver.
The PCAN-Explorer´s Receive Queue also receive the Message that you have send over the CAN Driver. If you have connect a real CAN node to your network, you have send the CAN ID 0x100 also on the real CAN Network.
To see how it works, open the PCAN-Stat (Tools Menü) and start the Macro again - that will help to understand what´s happend...
By the way...the PCAN-Explorer 5.3 was released - see the start page of your PE5 to get the free Update.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

janamoosa
Posts: 5
Joined: Mon 24. Sep 2012, 16:39

Re: Message in Receive list

Post by janamoosa » Tue 25. Sep 2012, 10:10

Hello Mr. Wilhelm,
Thank you very much for the reply. I have updated my software to 5.3. In my project I need to implement 6 messages with different cycle time namely 20 ms, 40ms and 100 ms. These messages has different message counter. The message counter ranges from 0 to 15 and 0 to 255. I tried to implement using VB Macro and used the "msg.Write connection ,timestamp" statement inside the message counter loop. I tried to send two different message having same message counter using different cycle time. But both the messages are sent at same cycletime in the trace window. Could you please help me to implement this scenario? Thanks in advance . I have also attached the program for your reference.

Regards,
Jana
Attachments
new 2.c
Implementing Message Counter and CRC
(2.45 KiB) Downloaded 873 times

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

Re: Message in Receive list

Post by PEAK-Support » Tue 25. Sep 2012, 11:27

Attached a simple project that use 4 CAN Messaages with cycle times of 20, 40, 80 and 100ms
Timing generated inside the VB Scriptr. Always a better choice is to work with real Signals, use them inside the script and set their transmit intervall inside the definition.

Code: Select all

'------------------------------------------------------------------------------
'FILE DESCRIPTION: Simple PE5 script to send 4 CAN Messages with different Interval 
'------------------------------------------------------------------------------
Sub SimpleMsg_Cnt()
'DESCRIPTION: Rest Bus msg counter
    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("PCAN3.PCANClient")
  MyClient.Device = UseConn.Device
  MyClient.Name = "PCANLight_USB_16"
  Set PcanConn = MyClient.Connections.Add(UseConn.CommunicationObject.NetName)

  Dim counter1, counter2, counter3, counter4
  Dim loopcounter
  Dim i,j,k,l
  ' Now create and initialize a new transmit message
  Dim msg,msg1,msg2,msg3
  Set msg= MyClient.Messages.Add
  Set msg1 = MyClient.Messages.Add
  Set msg2= MyClient.Messages.Add
  Set msg3= MyClient.Messages.Add
  
  timestamp = MyClient.GetSystemTime
  
  With msg
    .ID = &H27A									
    .DLC = 7
    .Data(0) = &H01
    .Data(1) = &H02
    .Data(2) = &H04
    .Data(3) = &H08
    .Data(4) = &H10
    .Data(5) = &H20
    .Data(6) = &H40
  End With
    
  With msg1
    .ID = &H4EA
    .DLC = 8
    .Data(0) = &H01
    .Data(1) = &H02
    .Data(2) = &H03
    .Data(3) = &H04
    .Data(4) = &H05
    .Data(5) = &H06
    .Data(6) = &H07
    .Data(7) = &H08
  End With
  
  With msg2
    .ID = &H37A									
    .DLC = 5
    .Data(0) = &H01
    .Data(1) = &H02
    .Data(2) = &H03
    .Data(3) = &H04
    .Data(4) = &H05
  End With
    
  With msg3
    .ID = &H3EA
    .DLC = 8
    .Data(0) = &H10
    .Data(1) = &H20
    .Data(2) = &H30
    .Data(3) = &H40
    .Data(4) = &H50
    .Data(5) = &H60
    .Data(6) = &H70
    .Data(7) = &H80
  End With
  
 i=0
 j=0
 k=0
 l=0
   
 do
 	loopcounter=loopcounter+1
 	' // 20ms 
 	i=i+1
  	msg.Data(5) = i							'//Initializing the byte 5 with message counter for message1							
  	If i>15 then i=0 End If
    msg.Data(6) = msg1.Data(0)+msg1.Data(1)+msg1.Data(2)+msg1.Data(3)+ msg1.Data(4)+msg1.Data(5) '//Implementing a simple CheckSum
    msg.Write PcanConn, timestamp				'//Transmitting data into CAN bus at Cycletime= 20 ms
    
    counter1=counter1+1
    If(counter1=2)Then
    	j=j+1
        msg1.Data(1) = j							'//Initializing the byte 1 with message counter for message1						
        if j>255 then j=0 End If
    	msg1.Write PcanConn, timestamp				'//Transmitting data into CAN bus at Cycletime= 40 ms
    	counter1=0
    End If
    
    counter2=counter2+1
    If(counter2=4)Then
     	k=k+1
		msg2.Data(2) = k							'//Initializing the byte 2 with message counter for message1						     	
		if k>128 Then k=0 End If
    	msg2.Write PcanConn, timestamp				'//Transmitting data into CAN bus at Cycletime= 80 ms
    	counter2=0
    End If    
    
    counter3=counter3+1
    If(counter3=5)Then
		l=l+1
		msg3.Data(3) = l							'//Initializing the byte 3 with message counter for message1						     	
		if l>64 Then l=0 End If    
    	msg3.Write PcanConn, timestamp				'//Transmitting data into CAN bus at Cycletime= 100 ms
    	counter3=0
    End If    
    
    ' lowest timer intervall is 20ms - so we need a 20ms resolution
    Wait 20
    
 	
  	Loop While(loopcounter<1000) ' run forever?...no...until 1000 loops 
  
  
  ' 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
Attachments
SeqSend.zip
complete PE5 ProjectSequenzSend
(2.94 KiB) Downloaded 703 times
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

janamoosa
Posts: 5
Joined: Mon 24. Sep 2012, 16:39

Re: Message in Receive list

Post by janamoosa » Tue 2. Oct 2012, 10:31

Hello Mr.Wilhelm,
Thank you fof your quick response and the program. It was very helpful. I am implementing crc in the messages and it requires logical operation. For example, AND operation, XOR operation , Not operation and left shift and right shift operation. The examples are given below for your reference

XOR operation with data byte:
crc = msg.Data(0) ^msg.Data(1)^msg.Data(2)

AND operation with Hexadecimal values:
crc = msg.Data(0) & (&H0F)

Shift operation:
crc = crc >>4

Could you please help me to implement these in the program. Also these messages are displayed in receive list. I could understand the explanation provided by you for this behavior. But still it will be good if there is a way to display the messages in transmit list. Please help me to find a solution.

Regards,
Jana

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

Re: Message in Receive list

Post by PEAK-Support » Tue 2. Oct 2012, 10:59

To use the signal based sending, you need first to define all Signals in a Symbol file. Without a valid Symbol File we could not use the VBS to genearte a script that use the transmitlist AND change the Data via script.

For boolean functions in VBS, please see the VBS Online Help which is part og the PE4/5 or use the Microsoft Support page - this is microsoft specific and not a PE4/5 specific problem.

We also develop complete scripts for our customers in VBS - if you have a detailed description, we could send you a official offer.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

janamoosa
Posts: 5
Joined: Mon 24. Sep 2012, 16:39

Re: Message in Receive list

Post by janamoosa » Tue 16. Oct 2012, 15:46

Hello,
Thank you very much for the response. I have implemented the signals in the symbol file and I tried to use VB script to send the dynamic value of message counter. It was not possible to transmit a modified signal. Can you provide an example how to get the signal from symbol file to VB script and then transmit the message to the bus. Thanks in advance.

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

Re: Message in Receive list

Post by PEAK-Support » Tue 16. Oct 2012, 16:16

Attached a smal PE5 project that calculate, based on two differnet signals that are defined in a Symbol file, a third virtual signal. This shows how to interact with signals in a VBS in the PE5. This project also use the UserPanel AddIn - if you do not own the AddIn, please ignore the error while loading the project.
Power-Project in action...(JPEG)
Power-Project in action...(JPEG)
Power-Project.jpg (570.56 KiB) Viewed 20023 times
Attachments
Power.zip
PCAN-Explorer 5 Project - Power calculating
(3.73 KiB) Downloaded 673 times
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

janamoosa
Posts: 5
Joined: Mon 24. Sep 2012, 16:39

Re: Message in Receive list

Post by janamoosa » Fri 19. Oct 2012, 13:14

Thanks for the reply. In symbol editor combining the signals worked fine. But i have few doubts.
1. Is it possible to implement byte operation from symbol file (Similar to combining signal from symbol editor which you have explained in the 'power calculation')
2. Can we see physical value in Receieve/transmit window even if we give some raw value in 'Default Value' tab in Symbol Editor
3. How can we send messages defined in .sym to the can bus? Do we have to write some script for sending data?

Please help me to solve the problems. Thanks in advance.

Regards,
Jana

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

Re: Message in Receive list

Post by PEAK-Support » Fri 19. Oct 2012, 14:58

1. Is it possible to implement byte operation from symbol file (Similar to combining signal from symbol editor which you have explained in the 'power calculation')
You could use the VBS function set to work with the Signals, like a normal VAR in VBS. Inside a Symbol file a "opration" make no sence - it is a definition file - no scripting description.
2. Can we see physical value in Receieve/transmit window even if we give some raw value in 'Default Value' tab in Symbol Editor
If you have defined a Symbol File entry for a CAN ID with a Signal Definition, the PCAN-Explorer will show the values of the signals in this way. You always could add Signals in the Watch Windows, or could switch to "RAW View". If you give a signal a default value, it is the startup value if no value set by CAN Bus, Panel, VBS or manualy.
3. How can we send messages defined in .sym to the can bus? Do we have to write some script for sending data?
Use Transmit Lists (see Online Help "Transmitlist"), add entrys to the Transmit Window (press INSERRT, select one pre defined Signal), use VBS -> add Message to Transmit List etc.
A lot of information, sample code snipes etc. are inside the Online Help - very usefull to read and studi this document.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply