Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash Builder 4.6 Native extension Error

i have an error that i dont understand why appear, the most weird is that happens sometimes but lately happens always, the code that i use is the same and i dont have make any changes to it, in fact i dont execute any code in the start of the application, i use buttons , so i dont get a reason with this error please help me, the error is a dialog that say:

Native extension Error: there are packaging errors/warning. Check each native extension in the Flex Build Packaging Page for each target platform. would you like to continue?

And when i click yes the program dont start, the debbuger show me the line:

[SWF] SerialCOMGame.swf - 2,121,630 bytes after decompression

but never start, i am using RS232 library for serial communication, before of get this error this work fine but i dont know what happen, my C code is:

/*
 * NativeSerialComunication.c
 *
 *  Created on: Jan 10, 2012
 *      Author: Diego Fernando
 */
#include "NativeSerialComunication.h"
int comport = 0;
int baudrate = 57600;
int buffsize = 4096;
unsigned char buffer[4096];
uint32_t comportOpened = 0;
FREObject IsSupported(FREContext ctx, void* functionData, uint32_t argc,
        FREObject argv[]) {
    FREObject result;
    uint32_t isSuppoerted = 1;
    FRENewObjectFromBool(isSuppoerted, &result);
    return result;
}

int startCOMListener() {
    if (!OpenComport(comport, baudrate)) {
        comportOpened = 1;
        return 1;
    }
    return 0;
}

void stopCOMListener() {
    CloseComport(comport);
    comportOpened = 0;
}

void COMListener(FREContext ctx) {
    uint8_t compbytes = 0;
    while (comportOpened) {
        compbytes = PollComport(comport, buffer, buffsize);
        FREDispatchStatusEventAsync(ctx, (const uint8_t *) "listening for data",(const uint8_t *)"datalistening");
        if (compbytes) {
            FREDispatchStatusEventAsync(ctx, (const uint8_t *) buffer,
                    (const uint8_t *) "datareceived");
        }
        Sleep(100);
    }
}
FREObject startSerialListener(FREContext ctx, void* functionData, uint32_t argc,
        FREObject argv[]) {
    FREObject result;
    if (startCOMListener()) {
        CreateThread((LPSECURITY_ATTRIBUTES) NULL, 0,(LPTHREAD_START_ROUTINE) COMListener, ctx, 0, NULL);
        FREDispatchStatusEventAsync(ctx, (const uint8_t *) "listener started",
                                    (const uint8_t *) "listenerstarted");
    }
    FRENewObjectFromBool(comportOpened, &result);
    return result;
}

FREObject stopSerialListener(FREContext ctx, void* functionData, uint32_t argc,
        FREObject argv[]) {
    FREObject result;
    stopCOMListener();
    FRENewObjectFromBool(comportOpened, &result);
    return result;
}

FREObject sendDataToSerialPort(FREContext ctx, void* functionData,
        uint32_t argc, FREObject argv[]) {
    FREObject result;
    uint32_t dataSended = 0;
    uint32_t dataToSend = 0;
    FREGetObjectAsUint32(argv[0],&dataToSend);
    printf("data to be sended %d",dataToSend);

    if (comportOpened && !SendByte(comport,dataToSend)) {
        dataSended = 1;
    }
    FRENewObjectFromBool(dataSended, &result);
    return result;
}

void MyContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
        uint32_t* numFunctionsToSet, const FRENamedFunction** functionsToSet) {

    *numFunctionsToSet = 4;

    FRENamedFunction* func = (FRENamedFunction*) malloc(
            sizeof(FRENamedFunction) * 4);
    func[0].name = (const uint8_t*) "isSupported";
    func[0].functionData = 0;
    func[0].function = &IsSupported;

    func[1].name = (const uint8_t*) "sendDataToSerialPort";
    func[1].functionData = 0;
    func[1].function = &sendDataToSerialPort;

    func[2].name = (const uint8_t*) "startSerialListener";
    func[2].functionData = 0;
    func[2].function = &startSerialListener;

    func[3].name = (const uint8_t*) "stopSerialListener";
    func[3].functionData = 0;
    func[3].function = &stopSerialListener;

    /*func[1].name = (const uint8_t*) "sayHelloWorld";
     func[1].functionData = 0;
     func[1].function = &sayHelloWorld;*/

    *functionsToSet = func;
}

void MyContextFinalizer(FREContext ctx) {
    return;
}

void initializer(void** extDataToSet,
        FREContextInitializer* ctxInitializerToSet,
        FREContextFinalizer* ctxFinalizerToSet) {
    extDataToSet = 0; // This example does not use any extension data.
    *ctxInitializerToSet = &MyContextInitializer;
    *ctxFinalizerToSet = &MyContextFinalizer;

}

void finalizer(void** extDataToSet) {
    stopCOMListener();
    return;
}

And this is my ActionScript code that use the native C code:

package com.nativeserialcomunication.driver
{
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;
    import flash.events.StatusEvent;
    import flash.external.ExtensionContext;

    public class NativeSerialComunication extends EventDispatcher
    {
        private var extensionContext:ExtensionContext;
        private var isSerialListenerStarted:Boolean = false;
        public function NativeSerialComunication(target:IEventDispatcher=null)
        {
            super(target);
            extensionContext =ExtensionContext.createExtensionContext("com.nativeserialcomunitacion.driver.NativeSerialComunitation","");
            extensionContext.addEventListener(StatusEvent.STATUS,statusHandle);
        }

        public function init():void{
            if(extensionContext.call("startSerialListener") as Boolean){
                isSerialListenerStarted = true;
                trace("serial listener started");
            }
            else{
                trace("no serial listener started");
            }
        }

        public function statusHandle(event:StatusEvent):void{
            trace("the event ("+event.level+") received, data:"+event.code);
        }

        public function isSupported():Boolean{
            return extensionContext.call("isSupported") as Boolean;
        }

        public function sendDataToSerialPort(data:uint):Boolean{
            return extensionContext.call("sendDataToSerialPort",data) as Boolean;
        }
    }
}
like image 992
Diego Fernando Murillo Valenci Avatar asked Jan 13 '12 14:01

Diego Fernando Murillo Valenci


1 Answers

The native extension package checkbox for your target platform(s) may need to be checked.

Navigate to:

Project Properties -> Flex Build Packaging -> Apple iOS (or Android, etc.)

Select the Native Extensions tab and make sure "Package" is checked.

like image 106
MunkyFoo Avatar answered Sep 22 '22 16:09

MunkyFoo