Page 1 of 1
[Visual Basic] modify variables value in transmitMessage
Posted: Thu 18. Jul 2013, 18:05
by vbrehier
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
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Fri 19. Jul 2013, 10:07
by PEAK-Support
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
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Fri 19. Jul 2013, 13:09
by vbrehier
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.
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Fri 19. Jul 2013, 13:19
by vbrehier
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....
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Fri 19. Jul 2013, 14:19
by vbrehier
i have found a solution, i change the preferred address before update the signal, and il modify the good frame in the transmit list....
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Fri 19. Jul 2013, 15:16
by PEAK-Support
OK - solved
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Thu 17. Apr 2014, 10:20
by vbrehier
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?
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Thu 17. Apr 2014, 12:13
by K.Wolf
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.
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Thu 17. Apr 2014, 15:38
by vbrehier
Ok thanks,
i'm interested by a fixed version for test.
Re: [Visual Basic] modify variables value in transmitMessage
Posted: Fri 18. Apr 2014, 15:15
by PEAK-Support
OK - Problem solved - in the next PE5 Release this fix will be included