Page 1 of 1

How does one send the variables within a multiplexer?

Posted: Wed 13. Nov 2024, 14:47
by apprentice
Greetings,
I have been using the standard macros within PCAN Explorer 6 to run J1939 CAN testing for the last few years, and I decided I wanted to step up to VBS Macros. I am not a programmer by nature but I have been able to figure out some of the basics of using VBS to send symbols and variables using the help contents. I have figured out how to send multiplexed messages as well, but I am at a loss how to send specific variables within the multiplexers. I was unable to find any examples of this in the help documents or within the forum. I was hoping someone could help with guiding in bein able to send specific variables within the multiplexer. I have attached a basic symbols file with the multiplexer I have been practicing with as well as a screen shot of the transmit list entry created. Any help or simple examples to follow along with are greatly appreciated as I am new to this aspect of PCAN Explorer.
This is the script I have so far for sending the multiplexer:

Sub TireProperties()

Dim sym

set TIRE = SymbolsManager(J1939_allsignals).Item("TIRE")

TIRE.Multiplexers(TireLocation_01).Send 1, peSendPeriodic, 10000

End Sub

Re: How does one send the variables within a multiplexer?

Posted: Wed 13. Nov 2024, 15:36
by M.Heidemann
Hello,

I admit, it can take a bit until you find this in the docs of PE6, but let me give you some options:

1) Please note that any Multiplexer-Signal will also be part of the Signals Collection, so if you just wanna access the Signal, you can use the collection, change the value and this change will automatically trigger a transmission:

Code: Select all

Sub SignalsExample()

   Dim objSignal

   For Each objSignal In Signals

      ' Access objSignal here.

      ' For example:

      PrintToOutputWindow objSignal.Name

   Next

End Sub

To access a specific signal you assign it to a dim:

Code: Select all


dim TimeStampSignal

Set TimeStampSignal = Signals("TimeStampSignal")


If you need explicit access from within the multiplexer itself, you can do the following:

Code: Select all


dim Symbol, Message, Signal

Set Symbol = SymbolsManager("YourSymbolFileName").Item("MySymbol")

Set Message = Symbol.Multiplexers("MyMultiplexer").Send(1, peSendWait)

Set Signal = Message.Variables("MySignal")

To change the value of this signal do:

Code: Select all


Signal.Value = 123

You can also send this multiplexer with current values:

Code: Select all

Message.Send 1, peSendPeriodic, 100
Bear in mind that these are examples, you can name the dims however you prefer...

Please use the PCAN-Explorer 6 Help, under "Automating tasks with PCAN-Explorer" you will find "reference" -> "objects"

It is a description of every object in PCAN-Explorer 6 and how to use, i myself use it extensively when creating examples, it's a good reference if you wanna get certain things done.

BR

Marvin

Re: How does one send the variables within a multiplexer?

Posted: Mon 18. Nov 2024, 15:14
by apprentice
Marvin,

Apologies for the delay in my response. Thank you for the examples you provided, they were most helpful. I took some time to try the different methods you provided and this method that you suggested seems to best accomplish what I do for the testing purposes when sending specific variables within multiplexers:

Sub TireProperties_TL0()
Dim Symbol, Message, Variable
set TIRE = SymbolsManager(J1939_allsignals).Item("TIRE")
set Message = TIRE.Multiplexers("TireLocation_0").Send (1, peSendWait)
set Variable = TIRE.Multiplexers("TireLocation_0").Variables("TirePress_00")
Variable.Value = 80
Message.Write 0
End Sub

However, what I am running into is that this creates two transmit list entries for every message that I send in this manner.
I am also struggling with how to create these automated tasks in a way that doesn't clutter up the Macro drop down list PCAN Explorer. I would like to be able to have sub routines for each test step in the test plan but be able to select one "Parent" Macro, and have it run all the subroutines for a test section without having to select the individual subroutines for each test step. My inexperience with coding and Visual Basic is lending itself to my difficulty in making it work how I would like it to. Do I need to create a VBS Macro for each test step and then create one Overall Macro that calls the other VBS Macro files or can they all be contained within one macro file?
I attached copies of the VBS Macro I have with a few subroutines in it as well as a screen shot of the Macro drop down list, and transmit list for reference.

Thanks,
apprentice

Re: How does one send the variables within a multiplexer?

Posted: Mon 18. Nov 2024, 15:23
by M.Heidemann
Hello,

Code: Select all

Sub TireProperties_TL0()
Dim Symbol, Message, Variable
set TIRE = SymbolsManager(J1939_allsignals).Item("TIRE")
set Message = TIRE.Multiplexers("TireLocation_0").Send (1, peSendWait)
set Variable = TIRE.Multiplexers("TireLocation_0").Variables("TirePress_00")
Variable.Value = 80
Message.Write 0
End Sub
That's because the message itself is send and another send is triggered by the value change of the signal, you can however prohibit that, just add:

variable.AutoTransmit = False

Code: Select all


Sub TireProperties_TL0()
Dim Symbol, Message, Variable
set TIRE = SymbolsManager(J1939_allsignals).Item("TIRE")
set Message = TIRE.Multiplexers("TireLocation_0").Send (1, peSendWait)
set Variable = TIRE.Multiplexers("TireLocation_0").Variables("TirePress_00")
Variable.AutoTransmit = False
Variable.Value = 80
Message.Write 0
End Sub


One Macro file can contain as many Functions, Subs , etc as you like so you can
use the Main-routine approach.i'd advise you to have a look at functions in VBS too, as they are alot more flexible and can be really useful.

BR

Marvin

Re: How does one send the variables within a multiplexer?

Posted: Thu 16. Jan 2025, 10:45
by dmeir
M.Heidemann wrote:
Wed 13. Nov 2024, 15:36
[...]
Please note that any Multiplexer-Signal will also be part of the Signals Collection, so if you just wanna access the Signal, you can use the collection, change the value and this change will automatically trigger a transmission
[...]
Could you elaborate further on this?
I'm currently looking on sending a Multiplexer signal via a button, but I cannot find said signal in the Signals list (at least in the Project Items list).
I'm looking on sending the multiplexer signal itself, not any of the multiplexed ones.
Reason for this is that at some multiplexer values, the message doesn't have any other signals to work with.

Re: How does one send the variables within a multiplexer?

Posted: Fri 17. Jan 2025, 11:28
by M.Riedl
Hello
M.Heidemann wrote:
Wed 13. Nov 2024, 15:36

1) Please note that any Multiplexer-Signal will also be part of the Signals Collection, so if you just wanna access the Signal, you can use the collection, change the value and this change will automatically trigger a transmission:
That means that all Signals/Variables in all Symbols and Multiplexers are part of the Signals Collection and can be accessed from there. The multiplexers themselves aren't included.
They are part of the Multiplexers Collection and are displayed under ActiveSymbols in the Project Items:
PE6-YourProjectWithMultiplexers-2025-01-17.png
PE6-YourProjectWithMultiplexers-2025-01-17.png (20.35 KiB) Viewed 5760 times

To send a multiplexer itself with or without signals, you can proceed as follows:

Code: Select all

Sub SendMuxWithAButton
    Dim YourSymbolsFile, YourSymbol, YourMuxWithoutSignals, YourMessage
    Set YourSymbolsFile = SymbolsManager("YourSymbolsFile")
    Set YourSymbol = YourSymbolsFile.Item("YourSymbol")
    Set YourMuxWithoutSignals = YourSymbol.Multiplexers("YourMultiplexerWithoutSignals")
    Set YourMessage = YourMuxWithoutSignals.Send(1, peSendWait)
    YourMessage.Write 0
End Sub
Regards
M.Riedl

Re: How does one send the variables within a multiplexer?

Posted: Fri 24. Jan 2025, 15:33
by dmeir
Thank you, this works as intended.