C/C++ programming & Prolific PL2303
  • Just looking around
    Symbola
    Posts: 16 from 2015/9/22
    From: Plymouth, UK
    I have been trying to get into C/C++ programming for a while on MorphOS, over the last few weeks I have installed the SDK and started to play around.

    To compile the classic “Hello, World!” I use “gcc -o hello hello.c”

    To compile an MUI based app I use “gcc -noixemul -o muicode muicode.c”

    That all compiles OK.

    I would like to use a USB to serial adapter cable (Prolific PL2303) to connect to a microcontroller. I have looked at the example from the SDK (Examples/Device/Serial). What is the correct way to compile this code? And how do I specify I am using the “serialpl2303.device”? I’m not sure about make files, is it just the case to “cd” to the folder and run the “make” command?

    Below shows the output I get: -

    Code:

    System:Development/Examples/Device/Serial> make
    ppc-morphos-gcc '-DDEVNAME="serial.device"' -O2 -mcpu=604e -c -o serial.o serial.c
    In file included from /gg/os-include/proto/exec.h:14,
    from serial.c:27:
    /gg/os-include/clib/exec_protos.h:11: #error "Mixing ixemul and native library calls is not supported. Native application should be built with -noixemul"
    In file included from /gg/os-include/proto/intuition.h:14,
    from serial.c:28:
    /gg/os-include/clib/intuition_protos.h:10: #error "Mixing ixemul and native library calls is not supported. Native application should be built with -noixemul"
    make: *** [Makefile:20: serial.o] Error 1
    System:Development/Examples/Device/Serial>


    I have also tried to compile: -

    http://amigadev.elowar.com/read/ADCD_2.1/Devices_Manual_guide/node0192.html

    gcc -o serial serial.c

    Code:

    Work:Code/SerialTest> gcc -o serial serial.c
    In file included from serial.c:21:
    /System/Development/gg/os-include/clib/exec_protos.h:11:3: error: #error "Mixing ixemul and native library calls is not supported. Native application should be built with -noixemul"
    11 | # error "Mixing ixemul and native library calls is not supported. Native application should be built with -noixemul"
    | ^~~~~
    serial.c: In function 'main':
    serial.c:61:21: warning: passing argument 1 of 'DeleteExtIO' from incompatible pointer type [-Wincompatible-pointer-types]
    61 | DeleteExtIO(SerialIO);
    | ^~~~~~~~
    | |
    | struct IOExtSer *
    In file included from serial.c:22:
    /System/Development/gg/os-include/clib/alib_protos.h:77:37: note: expected 'struct IORequest *' but argument is of type 'struct IOExtSer *'
    77 | VOID DeleteExtIO( struct IORequest *ioReq );
    | ~~~~~~~~~~~~~~~~~~^~~~~
    Work:Code/SerialTest>


    gcc -noixemul -o serial serial.c

    Code:

    Work:Code/SerialTest> gcc -noixemul -o serial serial.c
    serial.c: In function 'main':
    serial.c:61:21: warning: passing argument 1 of 'DeleteExtIO' from incompatible pointer type [-Wincompatible-pointer-types]
    61 | DeleteExtIO(SerialIO);
    | ^~~~~~~~
    | |
    | struct IOExtSer *
    In file included from serial.c:22:
    /System/Development/gg/os-include/clib/alib_protos.h:77:37: note: expected 'struct IORequest *' but argument is of type 'struct IOExtSer *'
    77 | VOID DeleteExtIO( struct IORequest *ioReq );
    | ~~~~~~~~~~~~~~~~~~^~~~~
    Work:Code/SerialTest>


    I have not done much C/C++ programming, just some Arduino/PlatformIO & Python. My main hope is to write a very simple bit of test code (and compile) that will send out and receive over a USB serial port.

    I have used Term to confirm the cable is working.

    MorphOS = 3.14
    gcc = 9.3.0

    Any help will be appreciated, thanks,
    Paul
  • »18.12.20 - 15:13
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 3108 from 2003/3/5
    From: Canada
    The last case (with -noixemul, which is what you should be using) appears to compile correctly, doesn't it? What happens when you run the result? Did you set SERIALNAME to the correct name?
  • »18.12.20 - 18:15
    Profile Visit Website
  • Just looking around
    Symbola
    Posts: 16 from 2015/9/22
    From: Plymouth, UK
    Thanks, I totally missed the fact that the last case was compiling with no errors, just warnings.

    As you also mention I was not defining “SERIALANME”, so added: -

    Code:

    #define SERIALNAME "serialpl2303.device"


    I was not sure on the default baud rate, so set it: -

    Code:

    SerialIO->io_Baud = 19200;
    SerialIO->IOSer.io_Command = SDCMD_SETPARAMS;


    The program compiles and works!

    Thanks for the help :)


    [ Edited by Symbola 18.12.2020 - 20:36 ]
  • »18.12.20 - 20:16
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    polluks
    Posts: 803 from 2007/10/23
    From: Gelsenkirchen,...
    @Symbola

    You may also try in the future
    Code:
    Prompt "RC=%R> "
    Pegasos II G4: MorphOS 3.9, Zalman M220W · iMac G5 12,1 17", MorphOS 3.18
    Power Mac G3: OSX 10.3 · PowerBook 5,8: OSX 10.5, MorphOS 3.18
  • »18.12.20 - 20:30
    Profile
  • Just looking around
    Symbola
    Posts: 16 from 2015/9/22
    From: Plymouth, UK
    Quote:

    polluks wrote:
    @Symbola

    You may also try in the future
    Code:
    Prompt "RC=%R> "



    Where would I use this? What does it do?

    Thanks
  • »18.12.20 - 20:41
    Profile Visit Website
  • Priest of the Order of the Butterfly
    Priest of the Order of the Butterfly
    polluks
    Posts: 803 from 2007/10/23
    From: Gelsenkirchen,...
    It belongs to S:shell-startup.
    Because gcc has no error summary, you should always get the return code.
    Pegasos II G4: MorphOS 3.9, Zalman M220W · iMac G5 12,1 17", MorphOS 3.18
    Power Mac G3: OSX 10.3 · PowerBook 5,8: OSX 10.5, MorphOS 3.18
  • »19.12.20 - 15:54
    Profile
  • Just looking around
    Symbola
    Posts: 16 from 2015/9/22
    From: Plymouth, UK
    Quote:

    polluks wrote:
    It belongs to S:shell-startup.
    Because gcc has no error summary, you should always get the return code.


    Wow, thanks, that's a great tip...

    RC=0>
    is a successful compile.

    RC=1>
    is a failed compile.
  • »19.12.20 - 18:18
    Profile Visit Website