Serial IO - COM Ports

Started by Yeshu777, June 14, 2023, 00:56:55

Previous topic - Next topic

Yeshu777

Hi,

Does anyone have a link to the com port "apiWaitCommEvent" that went with BlitzPlus?
Cymru Am Byth

markcwm


funkheld

Hi good afternoon. I'm looking for a program for blitzmax for the serial interface to send and receive data. Who can please program something like this that works for blitzmax? At 74 years old I can't manage it. Thanks. greeting

Derron

Brucey (the one from BlitzMax NG) wrote a serial-module some years ago. Dunno if this needs adjustments for current NG (or classic "vanilla/legacy/1.50" blitzmax).

https://github.com/maxmods/bah.mod/tree/master/serial.mod

You will have to download the whole "bah.mod" and then copy "serial.mod" into "blitzmax/mods/bah.mod(/serial.mod)".

Examples are provided but I guess you would need to adopt it a bit when running Windows OS (at least "example1.bmx").

PS: Feel free to join the discord server (click on "chat"-text-icon at the bottom of https://blitzmax.org). There you could ask me (or maybe Midimaster) in German too.

bye
Ron

Midimaster

@Derron  I already tested one of the examples for him and got this error message with old BlitzMax:
Building untitled1
Compiling:untitled1.bmx
flat assembler  version 1.69.14  (1572863 kilobytes memory)
3 passes, 3195 bytes.
Linking:untitled1.debug.exe
C:/BlitzMax/bin/ld.exe: cannot find -lsetupapi
Build Error: Failed to link C:/BlitzMax/tmp/untitled1.debug.exe
Process complete

Can you see what gets wrong?
...back from Egypt

Derron

#5
According to https://github.com/msys2/MINGW-packages/pull/4841
one user there mentions a lot of bugs with libserialport (which is utilized here).

The error indicates that it has issues linking "libsetupapi" (might be some windows thing)


I also saw that "wx.mod" (https://github.com/maxmods/wx.mod) has "wxctb.mod" - with some serial functionality.



bye
Ron

funkheld

Hello thanks for the information. I put the bah.mod in the mod folder. 
I have this BlitzMax NG. all bah.mod programs produce compiler errors blitzmax ng. 
The flat-ASM is no longer available at blitzmax ng 

Thanks. greeting

Midimaster

#7
Ok... I now tested on BlitzMax NG and got NO ERRORs!!!

Again... can you please send the error report you see on your machine?

This is the way to use SERIAL.MOD on BlitzMax NG:

1. Do not copy the whole Bah.Mod!

2. You better open the C:/BlitzMax NG/mod/ folder and create a new empty folder Bah.mod

3. Now you copy only this two sub-folders from GitHub-ZIP into the new Bah.mod folder:
  • serial.mod
  • regex.mod

4. Then you open example_02.bmx (is inside Bah.mod/serial.mod/examples)
' List the available serial ports
SuperStrict
Framework BaH.Serial
Import BRL.StandardIO

Local ports:TList = TSerial.listPorts()

For Local port:TSerialPortInfo = EachIn ports
    Print "~nSerial Device"
    Print "~tPort            : " + port.portName
    Print "~tPhysical Name   : " + port.physicalName
    Print "~tProduct Name    : " + port.productName
    Print "~tEnumerator Name : " + port.enumeratorName
    Print "~tVendor Id       : " + port.vendorId
    Print "~tProduct Id      : " + port.productId
Next

5. Run it and send us the compiler report

I got:
Building untitled1
[  3%] Processing:common.bmx
[  5%] Processing:source.bmx
[ 17%] Processing:regex.bmx
[ 24%] Processing:common.bmx
[ 26%] Processing:serial.bmx
[ 28%] Processing:untitled1.bmx
[ 30%] Compiling:pcre2_auto_possess.c
[ 32%] Compiling:pcre2_chartables.c
[ 34%] Compiling:pcre2_compile.c
[ 36%] Compiling:pcre2_config.c
[ 38%] Compiling:pcre2_context.c
[ 40%] Compiling:pcre2_dfa_match.c
[ 42%] Compiling:pcre2_error.c
[ 44%] Compiling:pcre2_extuni.c
[ 46%] Compiling:pcre2_find_bracket.c
[ 48%] Compiling:pcre2_jit_compile.c
[ 49%] Compiling:pcre2_maketables.c
[ 51%] Compiling:pcre2_match.c
[ 53%] Compiling:pcre2_match_data.c
[ 55%] Compiling:pcre2_newline.c
[ 57%] Compiling:pcre2_ord2utf.c
[ 59%] Compiling:pcre2_pattern_info.c
[ 61%] Compiling:pcre2_string_utils.c
[ 63%] Compiling:pcre2_study.c
[ 65%] Compiling:pcre2_substitute.c
[ 67%] Compiling:pcre2_substring.c
[ 69%] Compiling:pcre2_tables.c
[ 71%] Compiling:pcre2_ucd.c
[ 73%] Compiling:pcre2_valid_utf.c
[ 75%] Compiling:pcre2_xclass.c
[ 76%] Compiling:glue.cpp
[ 78%] Compiling:list_win32.cpp
[ 80%] Compiling:win.cc
[ 82%] Compiling:serial.cc
[ 84%] Compiling:common.bmx.debug.win32.x64.c
[ 86%] Compiling:source.bmx.debug.win32.x64.c
[ 88%] Compiling:regex.bmx.debug.win32.x64.c
[ 90%] Compiling:common.bmx.debug.win32.x64.c
[ 92%] Compiling:serial.bmx.debug.win32.x64.c
[ 94%] Compiling:untitled1.bmx.gui.debug.win32.x64.c
[ 96%] Archiving:regex.debug.win32.x64.a
[ 98%] Archiving:serial.debug.win32.x64.a
C:/BlitzMaxNG/MinGW32x64/bin/ar.exe: creating C:/BlitzMaxNG/mod/bah.mod/regex.mod/regex.debug.win32.x64.a
C:/BlitzMaxNG/MinGW32x64/bin/ar.exe: creating C:/BlitzMaxNG/mod/bah.mod/serial.mod/serial.debug.win32.x64.a
[100%] Linking:untitled1.debug.exe
Executing:untitled1.debug.exe

Process complete

No errors, but also no content, because I have no serial port installed.
...back from Egypt

funkheld

#8
See my test from 19:32:30 below.

greeting

funkheld

#9
I did it as you described above.

example_02 with error message.
I have COM1 with me.

Building example_02
[ 28%] Processing:example_02.bmx
[ 76%] Compiling:glue.cpp
[ 78%] Compiling:list_win32.cpp
[ 84%] Compiling:common.bmx.release.win32.x86.c
[ 86%] Compiling:source.bmx.release.win32.x86.c
[ 88%] Compiling:regex.bmx.release.win32.x86.c
D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp: In function 'void bmx_serial_listports(BBObject*)':
D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp:86:80: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  86 |                                        bbProductName = bbStringFromUTF8String((char*)buffer);
      |                                                                                ^~~~~~~~~~~~~
      |                                                                                |
      |                                                                                char*
In file included from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz.h:37,
                from D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp:41:
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp:94:81: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  94 |                                        bbPhysicalName = bbStringFromUTF8String((char*)buffer);
      |                                                                                ^~~~~~~~~~~~~
      |                                                                                |
      |                                                                                char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp:102:83: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  102 |                                        bbEnumeratorName = bbStringFromUTF8String((char*)buffer);
      |                                                                                  ^~~~~~~~~~~~~
      |                                                                                  |
      |                                                                                  char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp:113:85: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  113 |                                                bbPortName = bbStringFromUTF8String((char*)buffer);
      |                                                                                    ^~~~~~~~~~~~~
      |                                                                                    |
      |                                                                                    char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp:125:71: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  125 |                                        hids = bbStringFromUTF8String((char*)buffer);
      |                                                                      ^~~~~~~~~~~~~
      |                                                                      |
      |                                                                      char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
Build Error: failed to compile (1) D:/BlitzMax/mod/bah.mod/serial.mod/list_win32.cpp
Process complete

funkheld

#10
The mod for serial is from 04/04/23

Gruss

funkheld

#11
Modul  :

Building Modules
[ 16%] Compiling:glue.cpp
[ 16%] Compiling:list_win32.cpp
[ 80%] Compiling:regex.bmx.debug.win32.x86.c
[ 80%] Compiling:regex.bmx.debug.win32.x86.c
D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp: In function 'void bmx_serial_listports(BBObject*)':
D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp:86:80: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  86 |                                        bbProductName = bbStringFromUTF8String((char*)buffer);
      |                                                                                ^~~~~~~~~~~~~
      |                                                                                |
      |                                                                                char*
In file included from D:/BlitzMax/mod/brl.mod/blitz.mod/blitz.h:37,
                from D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp:41:
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp:94:81: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  94 |                                        bbPhysicalName = bbStringFromUTF8String((char*)buffer);
      |                                                                                ^~~~~~~~~~~~~
      |                                                                                |
      |                                                                                char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp:102:83: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  102 |                                        bbEnumeratorName = bbStringFromUTF8String((char*)buffer);
      |                                                                                  ^~~~~~~~~~~~~
      |                                                                                  |
      |                                                                                  char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp:113:85: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  113 |                                                bbPortName = bbStringFromUTF8String((char*)buffer);
      |                                                                                    ^~~~~~~~~~~~~
      |                                                                                    |
      |                                                                                    char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp:125:71: error: invalid conversion from 'char*' to 'const unsigned char*' [-fpermissive]
  125 |                                        hids = bbStringFromUTF8String((char*)buffer);
      |                                                                      ^~~~~~~~~~~~~
      |                                                                      |
      |                                                                      char*
D:/BlitzMax/mod/brl.mod/blitz.mod/blitz_string.h:129:55: note:  initializing argument 1 of 'BBString* bbStringFromUTF8String(const unsigned char*)'
  129 | BBString*bbStringFromUTF8String( const unsigned char *p );
      |                                  ~~~~~~~~~~~~~~~~~~~~~^
Build Error: failed to compile (1) D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp
Process complete

Midimaster

#12
Thank you for the deep informations. This brings us closer to the cause of the problems...

I guess this has nothing to do with the serial.mod. I don't understand C++, but I can see that all error message are from the same bug:

D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp: In function 'void bmx_serial_listports(BBObject*)':
D:/BlitzMax/mod/Bah.mod/serial.mod/list_win32.cpp:86:80:
 error: invalid conversion from 'char*' to 'const unsigned char*'
[-fpermissive]
  86 |                                        bbProductName = bbStringFromUTF8String((char*)buffer);
      |                                                                                ^~~~~~~~~~~~~
      |                                                                                |
      |                                                                                char*


It happens when the compiler tries to build a code snipplet which converts string from a buffer. The app has not started, so is has nothing to do with the pysical serial port. Here we need @Derron  or @col which are the experts in BlitzMax compiler.

Please write us, which version of BlitzMax you use.

I used for my tests BBC 0.129 BMK 3.45 Win32-x64 GCC 8.1.0 (see MENU-HELP-ABOUT in BlitzMax NG) and had not such problems.

 
...back from Egypt

funkheld

Hello thanks.
I..have : BlitzMax_win32_x86_mingw_0.136.3.51.7z


I find this on the page:
Win32 x64 (mingw)
BlitzMax_win32_x64_mingw_0.136.3.51.7z
Windows edition, aimed at x64 development, with x64 MinGW-w64 12.2.0. Includes SDL backend, mojo2, Crypto, Audio, Image, Net, Random, Text and Steam.

thanks
greeting


Derron

#14
the issue should be resolveable rather easy - and was required for other modules in the past too.

It needs a "cast" (a type is told to be an other type).


so
x = (unsigned char*)bla
will cast "bla" to "unsigned char*"



Original code uses "bbStringFromUTF8String":
BBString*bbStringFromUTF8String( const unsigned char *p );
(changed 2 yrs ago in https://github.com/bmx-ng/brl.mod/commit/5ed4787ec84846b8279302c2a252765dff2a6bb4 )


so (untested) a solution is to simply cast:
Code (C) Select
//change
bbProductName = bbStringFromUTF8String((char*)buffer);

//to

bbProductName = bbStringFromUTF8String((unsigned char*)buffer);
(same for the other "errors")


bye
Ron