Error when reopening the Generic ANT Channel

I modified the MO2Sensor code to allow repairing to a different MO2 sensor. I get the following error when I try to reopen the channel.

Failed invoking <symbol>
System Error
in open (C:\Users\Rog\Documents\Eclipse\workspace\MCyc11\source\MO2Sensor.mc:202)
in open (C:\Users\Rog\Documents\Eclipse\workspace\MCyc11\source\MO2Sensor.mc:202)
in onMenuItem (C:\Users\Rog\Documents\Eclipse\workspace\MCyc11\source\MCycMenuDelegate.mc:94)
System Error


The setPair function is called from the MenuDelegate to put the system back into wildcard searching in Proximity Pairing Mode.

//This function was added to put the system back into pairing mode
function setPair()
{
closeSensor();
pairing = true;

deviceCfg = new Ant.DeviceConfig( {
:deviceNumber => 0, //Wildcard our search for pairing
:deviceType => DEVICE_TYPE,
:transmissionType => 0,
:messagePeriod => PERIOD,
:radioFrequency => 57, //Ant+ Frequency
:searchTimeoutLowPriority => 10, //Timeout in 25s
:searchTimeoutHighPriority => 2, //Timeout in 5s
:searchThreshold => 1} ); //Turn on Proximity Pairing
GenericChannel.setDeviceConfig(deviceCfg);

data = new MO2Data();
searching = true;
}


After the setPair, it tries to reopen the channel and that is when the error occurs. This is the code in the Menu Delegate.

else if (item == :item_4_5)
{
mSensor.setPair();
mSensor.open();
Ui.pushView(new MCycViewPair(mSensor), new MCycPairDelegate(mSensor), Ui.SLIDE_UP );
}


The error is occurring in the line 202 which is just the GenericChannel.open() function that was in the MO2Sensor sample code.

function open()
{
// Open the channel
GenericChannel.open();

data = new MO2Data();
pastEventCount = 0;
searching = true;
}



This code worked in SDK 0.1.1 but it produced this error only occasionally (maybe 1 in 25 times) so I thought it was just a simulator issue. Now in SDK 0.2.4 it produces the error every time.
  • Former Member
    Former Member over 10 years ago
    Thanks for the report. We will look into this issue.
  • Did you receive the channel close event before you attempted to re-open the channel?

    If not, when you send the initial close command the channel will be in "Closing" state. The channel will not be considered "Closed" (and hence, openable), until you receive the event "MSG_CODE_EVENT_CHANNEL_CLOSED".
  • I checked version 0.1.1 and 0.2.4 of the SDK by adding the following if statement and println to look for the message after the GenericChannel.close() function was called. The "channel got closed" text never gets printed to the console in either SDK version although the 0.1.1 version allows the channel to be reopened and the 0.2.4 version crashes.

    function onMessage(msg)
    {

    // Parse the payload
    var payload = msg.getPayload();

    if( Ant.MSG_CODE_EVENT_CHANNEL_CLOSED == (payload[1].toNumber() & 0xFF) )
    {
    System.println("channel got closed");
    }
  • Hi beckettc,

    I added some more debug code to help see what's going on. I added the following println's to the OnMsg function to see exactly what was coming back for messages. I never seem to get the channel closed message, but the messages are different between SDK 0.1.1 where the code works and SDK 0.2.4 where it does not work.

    function onMessage(msg)
    {
    // Parse the payload
    var payload = msg.getPayload();
    System.println(msg.messageId.toNumber());

    if (payload.size() > 0)
    {
    System.print((payload[0] & 0xFF).toNumber());
    System.print(", ");
    }
    if (payload.size() > 1)
    {
    System.print((payload[1] & 0xFF).toNumber());
    System.print(", ");
    }
    if (payload.size() > 2)
    {
    System.print((payload[2] & 0xFF).toNumber());
    System.print(", ");
    }
    if (payload.size() > 3)
    {
    System.print((payload[3] & 0xFF).toNumber());
    System.print(", ");
    }
    if (payload.size() > 4)
    {
    System.print((payload[4] & 0xFF).toNumber());
    System.print(", ");
    }
    if (payload.size() > 5)
    {
    System.print((payload[5] & 0xFF).toNumber());
    System.print(", ");
    }
    if (payload.size() > 6)
    {
    System.print((payload[6] & 0xFF).toNumber());
    System.print(", ");
    }
    if (payload.size() > 7)
    {
    System.print((payload[7] & 0xFF).toNumber());
    System.print(", ");
    }
    System.println(" ");


    Then I ran several tests in both version of the SDK. In one case, GenericChannel.close() was issued followed by a new Ant.DeviceConfig which set the device id to 0 and turned on proximity pairing and then no more comments. The other case was the same sequence followed by the GenericChannel.open(). In both cases the channel was receiving data from a sensor when the commands were sent. The following shows the console output for these 2 cases in both SDK versions.

    Message ID and Payload Data (DECIMAL FORMAT)

    SDK 0.1.1 – Close – Set Proximity Pairing
    78 <-- Message ID
    1, 253, 0, 8, 40, 165, 168, 162, <--Payload
    78
    1, 253, 0, 8, 40, 165, 168, 162,
    78
    1, 253, 0, 8, 40, 165, 168, 162,
    64
    113, 0, 0, <-- This is a Proximity Pairing Message

    SDK 0.1.1 – Close – Set Proximity Pairing - Open
    78 <-- Message ID
    1, 124, 0, 8, 67, 5, 45, 180, <--Payload
    78
    1, 124, 0, 8, 67, 5, 45, 180,
    64
    75, 0, 0, <-- This is a message that the channel is open. We don’t see the proximity pairing message. When it finds the new sensor, it starts running again.

    SDK 0.2.4 – Close – Set Proximity Pairing
    78
    1, 149, 0, 8, 31, 5, 40, 165,
    78
    1, 149, 0, 8, 31, 5, 40, 165,
    78
    1, 149, 0, 8, 31, 5, 40, 165, <--No message after the close

    SDK 0.2.4 – Close – Set Proximity Pairing – Open
    78
    1, 185, 0, 8, 45, 5, 40, 160,
    78
    1, 185, 0, 8, 45, 5, 40, 160,
    Failed invoking <symbol>
    System Error
    in open (C:\Users\Rog\Documents\Eclipse\workspace\MCyc11\source\MO2Sensor.mc:202)
    in open (C:\Users\Rog\Documents\Eclipse\workspace\MCyc11\source\MO2Sensor.mc:202)
    in onMenuItem (C:\Users\Rog\Documents\Eclipse\workspace\MCyc11\source\MCycMenuDelegate.mc:90)
    System Error
  • Former Member
    Former Member over 10 years ago
    FWIW you can restart with the following: release, initialize, set config, open.
  • Thanks SHARKBAIT. That did the trick!!