Sharapie tool does not generate C# code properly.

Hi Folks,

I want to print receipts using EPSON TM-T88V thermal POS printer through mobile on Android and iOS platform.
For Android, I downloaded EPSON SDK from here.
For iOS, I downloaded it from here.

Epson SDK for android contains two .jar files named ePOS2.jar and ePOSEasySelect.jar and two libraries with extension .so named libepos2.so and libeposeasyselect.so which were referenced to Xamarin.Android project successfully, printing receipts on android went well.

For iOS, I refereed this walk-through on Xamarin documentation.

I used the following command to generate the c# files where my header and binary files were located:

sharpie bind --output=ePOS --namespace=ePOS --sdk=iphoneos12.0 *.h -scope ePOS

The generated files have too many syntax errors, which I don't know how to resolve at the moment. Below is the Structs.cs file with errors like "Identifier expected".

public struct
{
    [FieldOffset(0)]
    public long double __f;

    [FieldOffset(0)]
    public ulong __u;
}

Kindly help, and suggest whether I'm going in right direction.

Best Answer

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Can you post all the code line which causing the syntax errors?

    It's better to provide ApiDefinition amd Structs files here , so that we can look into it .

    Refer these thread :

    https://stackoverflow.com/questions/52064285/objective-sharpie-apidefinition-contains-overloaded-methods/52067970#52067970

    https://stackoverflow.com/questions/51996644/error-when-i-bind-an-objective-c-package/51998180#51998180

  • Hi @ColeX,

    My apologies for replying this late.

    Thank you for the reply, I tried the steps mentioned in the StackOverflow answer but was not able to solve the errors.

    I've attached the required files here(was not able to upload the .cs file, so renamed it to .txt).
    Kindly help.

  • ColeXColeX Member, Xamarin Team Xamurai

    @ShaggyPanchal said:
    Hi @ColeX,

    My apologies for replying this late.

    Thank you for the reply, I tried the steps mentioned in the StackOverflow answer but was not able to solve the errors.

    I've attached the required files here(was not able to upload the .cs file, so renamed it to .txt).
    Kindly help.

    Can you also provide the .a file ?

  • Please find the attached .h and .a files.

  • Hi @ColeX ,

    Any luck with this?

  • @ColeX said:
    I see the huge ApiDefinition and Structs file , normally it caused by that you didn't limit the scope of the binding .

    Try this method :https://forums.xamarin.com/discussion/comment/314049/#Comment_314049

    I tried using the scope as mentioned in the above link. Sharpie generated large files, but this time after following the instructions, I finally got the compilation error solved.

    Thanks :smile:

  • ShaggyPanchalShaggyPanchal Member ✭✭

    Hi again,

    After solving compilation errors I added the project reference in my Xamarin.iOS native project, after a successful build I was unable to get a reference for printer classes in iOS such as Epos2Printer etc.

    Any ideas about this?

  • ShaggyPanchalShaggyPanchal Member ✭✭

    @ShaggyPanchal said:
    Hi again,

    After solving compilation errors I added the project reference in my Xamarin.iOS native project, after a successful build I was unable to get a reference for printer classes in iOS such as Epos2Printer etc.

    Any ideas about this?

    Hi @ColeX,

    Can you please suggest me what could have gone wrong?
    I got no compilation errors, but after adding the reference of the project, I cannot import any classes using the namespace.

    I checked in the object explorer too, there's no sign of namespace in the dll file.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 7

    @ShaggyPanchal It is weird, Can you look into the ApiDefinition file to see if the classes are declared as Public?

    Check this thread , maybe it will be helpful.

  • ShaggyPanchalShaggyPanchal Member ✭✭

    @ColeX said:
    @ShaggyPanchal It is weird, Can you look into the ApiDefinition file to see if the classes are declared as Public?

    Check this thread , maybe it will be helpful.

    @ColeX,

    Thank you for the link above.
    I've attached my ApiDefinitions and Structs file. Even though the library builds successfully, the reference does not show the namespace in the ObjectExplorer of Visual Studio.

    It also gives me the following error while I compile the iOS project for Simulator - Debug configuration.

    * Native linking failed, undefined Objective-C class: EAAccessoryManager. The symbol '_OBJC_CLASS_$_EAAccessoryManager' could not be found in any of the libraries or frameworks linked with your application.
    * Native linking error: Target: i386-apple-darwin17.7.0
    * Native linking failed, undefined symbol: _EAAccessoryKey. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
    * Native linking error: Thread model: posix
    * Native linking error: InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    * Native linking error: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch i386 -all_load -dead_strip -force_load /Users/ravindrasonone/Library/Caches/Xamarin/mtbs/builds/CashManagerPOS.iOS/fad6492a2903a06b808760fde0589f34/obj/iPhoneSimulator/Debug/mtouch-cache/libepos2.a -force_load /Users/ravindrasonone/Library/Caches/Xamarin/mtbs/builds/CashManagerPOS.iOS/fad6492a2903a06b808760fde0589f34/obj/iPhoneSimulator/Debug/mtouch-cache/libeposeasyselect.a -force_load /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.11/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libapp.a -ios_simulator_version_min 8.0.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.1.sdk -u _xamarin_timezone_get_data -u _xamarin_GetFolderPath -u _xamarin_log -u _xamarin_start_wwan -u _CreateZStream -u _CloseZStream -u _Flush -u _ReadZStream -u _WriteZStream -u _xamarin_find_protocol_wrapper_type -u _xamarin_release_block_on_main_thread -u _xamarin_get_block_descriptor -u _xamarin_IntPtr_objc_msgSend_IntPtr -u _xamarin_IntPtr_objc_msgSendSuper_IntPtr -u _UIApplicationMain -u _mono_pmip -u _xamarin_dyn_objc_msgSend -u _xamarin_dyn_objc_msgSendSuper -u _xamarin_dyn_objc_msgSend_stret -u _xamarin_dyn_objc_msgSendSuper_stret -o /Users/ravindrasonone/Library/Caches/Xamarin/mtbs/builds/CashManagerPOS.iOS/fad6492a2903a06b808760fde0589f34/bin/iPhoneSimulator/Debug/CashManagerPOSiOS.app/.monotouch-32/CashManagerPOSiOS -framework Security -framework CoreVideo -framework OpenGLES -framework QuickLook -framework SystemConfiguration -framework GLKit -framework CoreMedia -framework CoreLocation -framework CoreGraphics -framework CoreData -framework QuartzCore -framework CloudKit -framework UIKit -framework Foundation -framework AVFoundation -weak_framework Intents -weak_framework CoreSpotlight -weak_framework CoreFoundation -weak_framework CFNetwork -weak_framework Contacts -weak_framework CoreNFC /Users/ravindrasonone/Library/Caches/Xamarin/mtbs/builds/CashManagerPOS.iOS/fad6492a2903a06b808760fde0589f34/obj/iPhoneSimulator/Debug/mtouch-cache/i386/main.o /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.11/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libmonosgen-2.0.a /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.11/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libxamarin-debug.a -lsqlite3 -lxml2 -pie -lz -liconv -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.ios.a
    * Native linking failed, undefined symbol: _EAAccessoryDidConnectNotification. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
    * Native linking failed, undefined Objective-C class: EASession. The symbol '_OBJC_CLASS_$_EASession' could not be found in any of the libraries or frameworks linked with your application.
    * Native linking failed. Please review the build log.
    * Native linking error: Apple LLVM version 10.0.0 (clang-1000.11.45.5)
    

    My LinkWith files are as following:

    libeposeasyselect.linkwith.cs

    using System;
    using ObjCRuntime;
    
    [assembly: LinkWith
        (
            "libeposeasyselect.a",
            LinkTarget.ArmV7s | LinkTarget.ArmV7 | LinkTarget.Simulator,
            ForceLoad = true,
            SmartLink = true,
            Frameworks = "Contacts CoreFoundation CoreLocation CoreNFC Foundation Security UIKit",
            //LinkerFlags = "-v -all_load -lc++ -ObjC -lxml2",
            LinkerFlags = "-v -lxml2 -all_load",
            IsCxx = true
        )
    ]
    

    libepos2.linkwith.cs

    using System;
    using ObjCRuntime;
    
    [assembly: LinkWith
        (
            "libepos2.a",
            LinkTarget.ArmV7s | LinkTarget.ArmV7 | LinkTarget.Simulator,
            ForceLoad = true,
            Frameworks = "Contacts CoreFoundation CoreLocation CoreNFC Foundation Security UIKit",
            SmartLink = true,
            //LinkerFlags = "-v -all_load -lc++ -ObjC -lxml2",
            LinkerFlags = "-v -lxml2 -all_load",
            IsCxx = true
        )
    ]
    

    The mtouch arguments in iOS Project are as follows:

    iPhoneSimulator - Debug
    -v -v -v -v --registrar:dynamic

    iPhone - Debug
    -v -v -v -v --registrar:static

    iPhone - Ad-Hoc
    -v -v -v -v --registrar:static

    And added support for external protocols in the info.plist file:

    <key>UISupportedExternalAccessoryProtocols</key>
    <array>
        <string>com.epson.escpos</string>
    </array>
    

    Please let me know where I'm wrong.

Sign In or Register to comment.