Search code examples
comcan-buscaplcanoecanalyzer

How to access CAN signals dynamically (by string) in CAPL?


I'm trying to force CAN signals to given values using COM interface of CANalyzer. Since there is no COM method to send CAN messages, I'm implementing a workaround using CAPL:

void SendMySignal(int value) {
  message MyMessage msg;
  msg.MySignal = value;
  output(msg);
}

This works fine, however since MyMessage and MySignal are referenced statically (by name) here, I'll have to implement N functions to be able to send N signals (or an N-way switch statement, etc). Is there a way to avoid the hassle and access signals inside a message by string? Something like this:

void SendSignal(int MessageID, char SignalName, int value)

I'm also open to alternative solutions in case I have missed something in the COM interface. If there is a solution which only works for CANoe, I can ask my boss for a license, but of course I'd prefer to do without.


Solution

  • there is such function, but it is restricted to be used only in test nodes

    long setSignal(char signalName[], double aValue);
    

    you can find details in:

    CAPL Function Overview » Test Feature Set / Signal Access » SetSignal Special Use Case: Signal is not known before Measurement Start

    and take care about not to send for each signal a new message to avoid bus over-flooding. In my opinion it is a better style to set all signals for whole message and to send it on change only when it is not cyclic. Signal updates in cyclic messages mostly have to be sent in next cycle.