[Visual Basic] modify variables value in transmitMessage

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Locked
vbrehier
Posts: 6
Joined: Thu 18. Jul 2013, 17:50

[Visual Basic] modify variables value in transmitMessage

Post by vbrehier » Thu 18. Jul 2013, 18:05

Hi,

i attempt to write a vba application which take data in a excel sheet, to put them in the Symbol/variable corresponding in my transmitList.

My problem is when i do that, instead of update the value of my variable, the macro create a new transmitMessage in the list, with the 0xF8 sourceAddress, with my value.

there is the code for this part:

wsExcel.Cells(indexLigne, 2) is the name of the symbol
wsExcel.Cells(indexLigne, 3) is the name of the variable
wsExcel.Cells(indexLigne, 4 + indicePasTest) is the value of the variable

Code: Select all


     ' pour toutes les trames de la transmit list
    For Each message In appCanExplorer.Connections.TransmitMessages
    
        ' si le message est le bon nom
        If message.Symbol.Name = wsExcel.Cells(indexLigne, 2) Then

            For Each variable In message.multiplexer.Variables
                
                'si la variable a le bon nom
                If variable.Name = wsExcel.Cells(indexLigne, 3) Then
                    
                    ' on met à jour sa valeur
                    variable.Value = wsExcel.Cells(indexLigne, 4 + indicePasTest)
                    Exit For

                End If
            Next
        End If
    Next


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

Re: [Visual Basic] modify variables value in transmitMessage

Post by PEAK-Support » Fri 19. Jul 2013, 10:07

Here a simple and small Macro to send values from a EXCEL Sheet:

Macro Code (PE5):

Code: Select all

Sub SendMessagesFromExcel()
  Dim ExcelApp, ExcelWorkbook, ExcelSheet

  Set ExcelApp = CreateObject("Excel.Application")  ' Start Excel
  ExcelApp.Visible = True ' Make Excel visible, not really required
  Set ExcelWorkbook = ExcelApp.Workbooks.Open("c:\Test.xls")   ' Adjust path!
  Set ExcelSheet = ExcelWorkbook.Worksheets(1) ' go to Sheet 1
  
  ' Read all rows in the sheet
  Dim Row, Msg, n
  Set Msg = Connections.Transmitmessages.Add
  Row = 2 ' Messages begin on row 2
  
  While ExcelSheet.Cells(Row, 1) <> Empty
	Msg.ID = CInt("&H" & ExcelSheet.Cells(Row, 1))
	Msg.DLC = CInt(ExcelSheet.Cells(Row, 2))
	For n = 0 To Msg.DLC-1
	  Msg.Data(n) = CInt("&H" & ExcelSheet.Cells(Row, 3+n))
	Next
	Set Msg.Connection = Connections(1)
	Msg.Write 0
	Row = Row + 1  ' Go to next row
  Wend

  ExcelApp.Quit
End Sub
Excel Shhet:

Code: Select all

CAN-ID	DLC	Data0	Data1	Data2
100	3	1	2	3
101	2	2	3	
102	3	3	4	5
103	2	4	5	
104	3	5	6	7
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

vbrehier
Posts: 6
Joined: Thu 18. Jul 2013, 17:50

Re: [Visual Basic] modify variables value in transmitMessage

Post by vbrehier » Fri 19. Jul 2013, 13:09

Ok, thanks for the reply.

it's interesting but i don't want send raw data, but i need to use the signals name...

I need also to use an existing transmitList where the operator can change manually the transmit address, and the cycle time. for that i want use an existing list.

il worked on my problem and i found that if the message present in the list add the destinationaddresse = 0xF8, it works fine, else if it had an other address, the script create a new message in the list with the F8h address.

vbrehier
Posts: 6
Joined: Thu 18. Jul 2013, 17:50

Re: [Visual Basic] modify variables value in transmitMessage

Post by vbrehier » Fri 19. Jul 2013, 13:19

i have understand that it's the preferred address associated to the connection... but il's not what i want. I just want modify a signal value in an existing, and periodic frame....

vbrehier
Posts: 6
Joined: Thu 18. Jul 2013, 17:50

Re: [Visual Basic] modify variables value in transmitMessage

Post by vbrehier » Fri 19. Jul 2013, 14:19

i have found a solution, i change the preferred address before update the signal, and il modify the good frame in the transmit list....

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

Re: [Visual Basic] modify variables value in transmitMessage

Post by PEAK-Support » Fri 19. Jul 2013, 15:16

OK - solved
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

vbrehier
Posts: 6
Joined: Thu 18. Jul 2013, 17:50

Re: [Visual Basic] modify variables value in transmitMessage

Post by vbrehier » Thu 17. Apr 2014, 10:20

Hi,

I allow myself to re-open this discussion, because i have another problem with that code.

I use

Code: Select all

message.VariableValue("SuspetParameterNumber") = myValue


to modify a sending J1939 DM01, when i put different value, i obtain another value in the message:

1 give me 65536
10 give 131328
20 give 262656
30 give 393984
524287 give 524287

I think because "SuspetParameterNumber" is in Motorola format, but I don't understand why it's a problem, and how i can avoid that?

K.Wolf
Software Development
Software Development
Posts: 141
Joined: Wed 22. Sep 2010, 15:37

Re: [Visual Basic] modify variables value in transmitMessage

Post by K.Wolf » Thu 17. Apr 2014, 12:13

Hi,

this has to do with the SPN Conversion Method that is selected for the DTC, which determines how the SuspectParameterNumber bits are interpreted. This whole topic is very ugly, because if the default value for SPNConversionMethod is used (0 = SPN conversion method version 4), the bit layout of SuspectParameterNumber is in fact a combination of Intel and Motorola format. The original Motorola layout specified in the J1939 database can only be applied if the SPNConversionMethod bit is set to 1.

When you change the SuspectParameterNumber variable in the Edit Variables dialog box, PCAN-Explorer applies a special function to correct the bit layout before storing it in the message data. But when the VariableValue property is used to set the data, this is not done, which is a bug.

Please write to support@peak-system.com about this forum entry and tell us your PCAN-Explorer License ID. I can send you a fixed PCAN-Explorer EXE as a preliminary version.

vbrehier
Posts: 6
Joined: Thu 18. Jul 2013, 17:50

Re: [Visual Basic] modify variables value in transmitMessage

Post by vbrehier » Thu 17. Apr 2014, 15:38

Ok thanks,

i'm interested by a fixed version for test.

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

Re: [Visual Basic] modify variables value in transmitMessage

Post by PEAK-Support » Fri 18. Apr 2014, 15:15

OK - Problem solved - in the next PE5 Release this fix will be included
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Locked