I have a device that connects to a USB port. I installed this 10 years ago and used Ruby 2.3.3. I used SerialPort to read from the device. I need to open the device, then send a string to the device and read the response. I’ve updated the system and installed the latest Ruby 3.4.4. When I try to install the SerialPort gem I get errors. What is the problem or is there a better solution for SerialPort?
I’ve tried to install 2.3.3 but I can’t get it installed properly. And it’d be better to update to a newer version of Ruby.
Searching the forum I find several topics for SerialPort but they are years old.
Thanks for help in advance.
The error messages follow:
C:\Windows\System32>gem install serialport
Building native extensions. This could take a while...
ERROR: Error installing serialport:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby34-x64/lib/ruby/gems/3.4.0/gems/serialport-1.3.2/ext/native
C:/Ruby34-x64/bin/ruby.exe extconf.rb
checking for OS... mingw
creating Makefile
current directory: C:/Ruby34-x64/lib/ruby/gems/3.4.0/gems/serialport-1.3.2/ext/native
make DESTDIR\= sitearchdir\=./.gem.20250526-16280-cw5hfk sitelibdir\=./.gem.20250526-16280-cw5hfk clean
current directory: C:/Ruby34-x64/lib/ruby/gems/3.4.0/gems/serialport-1.3.2/ext/native
make DESTDIR\= sitearchdir\=./.gem.20250526-16280-cw5hfk sitelibdir\=./.gem.20250526-16280-cw5hfk
generating serialport-x64-mingw-ucrt.def
compiling posix_serialport_impl.c
compiling serialport.c
serialport.c: In function 'sp_create':
serialport.c:29:14: warning: old-style function definition [-Wold-style-definition]
29 | static VALUE sp_create(class, _port)
| ^~~~~~~~~
serialport.c: In function 'sp_set_modem_params':
serialport.c:62:14: warning: old-style function definition [-Wold-style-definition]
62 | static VALUE sp_set_modem_params(argc, argv, self)
| ^~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_break':
serialport.c:76:14: warning: old-style function definition [-Wold-style-definition]
76 | static VALUE sp_break(self, time)
| ^~~~~~~~
serialport.c: In function 'sp_get_dtr':
serialport.c:88:14: warning: old-style function definition [-Wold-style-definition]
88 | static VALUE sp_get_dtr(self)
| ^~~~~~~~~~
serialport.c: In function 'sp_get_flow_control':
serialport.c:100:14: warning: old-style function definition [-Wold-style-definition]
100 | static VALUE sp_get_flow_control(self)
| ^~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_get_read_timeout':
serialport.c:112:14: warning: old-style function definition [-Wold-style-definition]
112 | static VALUE sp_get_read_timeout(self)
| ^~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_get_rts':
serialport.c:124:14: warning: old-style function definition [-Wold-style-definition]
124 | static VALUE sp_get_rts(self)
| ^~~~~~~~~~
serialport.c: In function 'sp_get_write_timeout':
serialport.c:136:14: warning: old-style function definition [-Wold-style-definition]
136 | static VALUE sp_get_write_timeout(self)
| ^~~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_set_dtr':
serialport.c:148:14: warning: old-style function definition [-Wold-style-definition]
148 | static VALUE sp_set_dtr(self, val)
| ^~~~~~~~~~
serialport.c: In function 'sp_set_flow_control':
serialport.c:164:14: warning: old-style function definition [-Wold-style-definition]
164 | static VALUE sp_set_flow_control(self, val)
| ^~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_set_read_timeout':
serialport.c:182:14: warning: old-style function definition [-Wold-style-definition]
182 | static VALUE sp_set_read_timeout(self, val)
| ^~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_set_rts':
serialport.c:194:14: warning: old-style function definition [-Wold-style-definition]
194 | static VALUE sp_set_rts(self, val)
| ^~~~~~~~~~
serialport.c: In function 'sp_set_write_timeout':
serialport.c:207:14: warning: old-style function definition [-Wold-style-definition]
207 | static VALUE sp_set_write_timeout(self, val)
| ^~~~~~~~~~~~~~~~~~~~
serialport.c: In function 'get_modem_params':
serialport.c:216:13: warning: old-style function definition [-Wold-style-definition]
216 | static void get_modem_params(self, mp)
| ^~~~~~~~~~~~~~~~
serialport.c: In function 'sp_set_data_rate':
serialport.c:230:14: warning: old-style function definition [-Wold-style-definition]
230 | static VALUE sp_set_data_rate(self, data_rate)
| ^~~~~~~~~~~~~~~~
serialport.c: In function 'sp_set_data_bits':
serialport.c:249:14: warning: old-style function definition [-Wold-style-definition]
249 | static VALUE sp_set_data_bits(self, data_bits)
| ^~~~~~~~~~~~~~~~
serialport.c: In function 'sp_set_stop_bits':
serialport.c:268:14: warning: old-style function definition [-Wold-style-definition]
268 | static VALUE sp_set_stop_bits(self, stop_bits)
| ^~~~~~~~~~~~~~~~
serialport.c: In function 'sp_set_parity':
serialport.c:287:14: warning: old-style function definition [-Wold-style-definition]
287 | static VALUE sp_set_parity(self, parity)
| ^~~~~~~~~~~~~
serialport.c: In function 'sp_get_data_rate':
serialport.c:305:14: warning: old-style function definition [-Wold-style-definition]
305 | static VALUE sp_get_data_rate(self)
| ^~~~~~~~~~~~~~~~
serialport.c: In function 'sp_get_data_bits':
serialport.c:321:14: warning: old-style function definition [-Wold-style-definition]
321 | static VALUE sp_get_data_bits(self)
| ^~~~~~~~~~~~~~~~
serialport.c: In function 'sp_get_stop_bits':
serialport.c:337:14: warning: old-style function definition [-Wold-style-definition]
337 | static VALUE sp_get_stop_bits(self)
| ^~~~~~~~~~~~~~~~
serialport.c: In function 'sp_get_parity':
serialport.c:353:14: warning: old-style function definition [-Wold-style-definition]
353 | static VALUE sp_get_parity(self)
| ^~~~~~~~~~~~~
serialport.c: In function 'sp_get_modem_params':
serialport.c:369:14: warning: old-style function definition [-Wold-style-definition]
369 | static VALUE sp_get_modem_params(self)
| ^~~~~~~~~~~~~~~~~~~
serialport.c: In function 'get_line_signals_helper':
serialport.c:390:6: warning: old-style function definition [-Wold-style-definition]
390 | void get_line_signals_helper(obj, ls)
| ^~~~~~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_get_cts':
serialport.c:403:14: warning: old-style function definition [-Wold-style-definition]
403 | static VALUE sp_get_cts(self)
| ^~~~~~~~~~
serialport.c: In function 'sp_get_dsr':
serialport.c:419:14: warning: old-style function definition [-Wold-style-definition]
419 | static VALUE sp_get_dsr(self)
| ^~~~~~~~~~
serialport.c: In function 'sp_get_dcd':
serialport.c:435:14: warning: old-style function definition [-Wold-style-definition]
435 | static VALUE sp_get_dcd(self)
| ^~~~~~~~~~
serialport.c: In function 'sp_get_ri':
serialport.c:451:14: warning: old-style function definition [-Wold-style-definition]
451 | static VALUE sp_get_ri(self)
| ^~~~~~~~~
serialport.c: In function 'sp_signals':
serialport.c:470:14: warning: old-style function definition [-Wold-style-definition]
470 | static VALUE sp_signals(self)
| ^~~~~~~~~~
serialport.c: In function 'sp_flush_input_data':
serialport.c:497:14: warning: old-style function definition [-Wold-style-definition]
497 | static VALUE sp_flush_input_data(self)
| ^~~~~~~~~~~~~~~~~~~
serialport.c: In function 'sp_flush_output_data':
serialport.c:508:14: warning: old-style function definition [-Wold-style-definition]
508 | static VALUE sp_flush_output_data(self)
| ^~~~~~~~~~~~~~~~~~~~
compiling win_serialport_impl.c
win_serialport_impl.c: In function 'get_handle_helper':
win_serialport_impl.c:36:15: warning: old-style function definition [-Wold-style-definition]
36 | static HANDLE get_handle_helper(obj)
| ^~~~~~~~~~~~~~~~~
win_serialport_impl.c:47:4: warning: 'fd' is deprecated: rb_io_descriptor [-Wdeprecated-declarations]
47 | return (HANDLE) _get_osfhandle(fptr->fd);
| ^~~~~~
In file included from serialport.h:26,
from win_serialport_impl.c:20:
C:/Ruby34-x64/include/ruby-3.4.0/ruby/io.h:154:9: note: declared here
154 | int fd;
| ^~
win_serialport_impl.c: In function 'sp_create_impl':
win_serialport_impl.c:62:24: warning: old-style function definition [-Wold-style-definition]
62 | VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port)
| ^~~~~~~~~~~~~~
win_serialport_impl.c:78:4: error: implicit declaration of function 'NEWOBJ' [-Wimplicit-function-declaration]
78 | NEWOBJ(sp, struct RFile);
| ^~~~~~
win_serialport_impl.c:78:11: error: 'sp' undeclared (first use in this function); did you mean 'fp'?
78 | NEWOBJ(sp, struct RFile);
| ^~
| fp
win_serialport_impl.c:78:11: note: each undeclared identifier is reported only once for each function it appears in
win_serialport_impl.c:78:15: error: expected expression before 'struct'
78 | NEWOBJ(sp, struct RFile);
| ^~~~~~
win_serialport_impl.c:151:4: warning: 'mode' is deprecated: rb_io_mode [-Wdeprecated-declarations]
151 | fp->mode = FMODE_READWRITE | FMODE_BINMODE | FMODE_SYNC;
| ^~
C:/Ruby34-x64/include/ruby-3.4.0/ruby/io.h:158:9: note: declared here
158 | int mode;
| ^~~~
win_serialport_impl.c:153:4: warning: 'fd' is deprecated: rb_io_descriptor [-Wdeprecated-declarations]
153 | fp->fd = fd;
| ^~
C:/Ruby34-x64/include/ruby-3.4.0/ruby/io.h:154:9: note: declared here
154 | int fd;
| ^~
win_serialport_impl.c: In function 'sp_set_modem_params_impl':
win_serialport_impl.c:160:24: warning: old-style function definition [-Wold-style-definition]
160 | VALUE RB_SERIAL_EXPORT sp_set_modem_params_impl(argc, argv, self)
| ^~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'get_modem_params_impl':
win_serialport_impl.c:297:23: warning: old-style function definition [-Wold-style-definition]
297 | void RB_SERIAL_EXPORT get_modem_params_impl(self, mp)
| ^~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_set_flow_control_impl':
win_serialport_impl.c:317:24: warning: old-style function definition [-Wold-style-definition]
317 | VALUE RB_SERIAL_EXPORT sp_set_flow_control_impl(self, val)
| ^~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_get_flow_control_impl':
win_serialport_impl.c:362:24: warning: old-style function definition [-Wold-style-definition]
362 | VALUE RB_SERIAL_EXPORT sp_get_flow_control_impl(self)
| ^~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_set_read_timeout_impl':
win_serialport_impl.c:390:24: warning: old-style function definition [-Wold-style-definition]
390 | VALUE RB_SERIAL_EXPORT sp_set_read_timeout_impl(self, val)
| ^~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_get_read_timeout_impl':
win_serialport_impl.c:433:24: warning: old-style function definition [-Wold-style-definition]
433 | VALUE RB_SERIAL_EXPORT sp_get_read_timeout_impl(self)
| ^~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_set_write_timeout_impl':
win_serialport_impl.c:456:24: warning: old-style function definition [-Wold-style-definition]
456 | VALUE RB_SERIAL_EXPORT sp_set_write_timeout_impl(self, val)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_get_write_timeout_impl':
win_serialport_impl.c:491:24: warning: old-style function definition [-Wold-style-definition]
491 | VALUE RB_SERIAL_EXPORT sp_get_write_timeout_impl(self)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'delay_ms':
win_serialport_impl.c:506:13: warning: old-style function definition [-Wold-style-definition]
506 | static void delay_ms(time)
| ^~~~~~~~
win_serialport_impl.c: In function 'sp_break_impl':
win_serialport_impl.c:525:24: warning: old-style function definition [-Wold-style-definition]
525 | VALUE RB_SERIAL_EXPORT sp_break_impl(self, time)
| ^~~~~~~~~~~~~
win_serialport_impl.c: In function 'get_line_signals_helper_impl':
win_serialport_impl.c:544:23: warning: old-style function definition [-Wold-style-definition]
544 | void RB_SERIAL_EXPORT get_line_signals_helper_impl(obj, ls)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'set_signal':
win_serialport_impl.c:563:14: warning: old-style function definition [-Wold-style-definition]
563 | static VALUE set_signal(obj, val, sigoff, sigon)
| ^~~~~~~~~~
win_serialport_impl.c: In function 'sp_set_rts_impl':
win_serialport_impl.c:595:24: warning: old-style function definition [-Wold-style-definition]
595 | VALUE RB_SERIAL_EXPORT sp_set_rts_impl(self, val)
| ^~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_set_dtr_impl':
win_serialport_impl.c:601:24: warning: old-style function definition [-Wold-style-definition]
601 | VALUE RB_SERIAL_EXPORT sp_set_dtr_impl(self, val)
| ^~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_get_rts_impl':
win_serialport_impl.c:607:24: warning: old-style function definition [-Wold-style-definition]
607 | VALUE RB_SERIAL_EXPORT sp_get_rts_impl(self)
| ^~~~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_get_dtr_impl':
win_serialport_impl.c:614:24: warning: old-style function definition [-Wold-style-definition]
614 | VALUE RB_SERIAL_EXPORT sp_get_dtr_impl(self)
| ^~~~~~~~~~~~~~~
win_serialport_impl.c: At top level:
win_serialport_impl.c:621:9: warning: 'PURGE_RXABORT' redefined
621 | #define PURGE_RXABORT 0x02
| ^~~~~~~~~~~~~
In file included from C:/Ruby34-x64/msys64/ucrt64/include/windows.h:70,
from C:/Ruby34-x64/msys64/ucrt64/include/winsock2.h:23,
from C:/Ruby34-x64/include/ruby-3.4.0/ruby/win32.h:36,
from C:/Ruby34-x64/include/ruby-3.4.0/ruby/internal/dosish.h:38,
from C:/Ruby34-x64/include/ruby-3.4.0/ruby/defines.h:78,
from C:/Ruby34-x64/include/ruby-3.4.0/ruby/ruby.h:25,
from C:/Ruby34-x64/include/ruby-3.4.0/ruby.h:38,
from serialport.h:24:
C:/Ruby34-x64/msys64/ucrt64/include/winbase.h:582:9: note: this is the location of the previous definition
582 | #define PURGE_RXABORT 0x2
| ^~~~~~~~~~~~~
win_serialport_impl.c:622:9: warning: 'PURGE_RXCLEAR' redefined
622 | #define PURGE_RXCLEAR 0x08
| ^~~~~~~~~~~~~
C:/Ruby34-x64/msys64/ucrt64/include/winbase.h:584:9: note: this is the location of the previous definition
584 | #define PURGE_RXCLEAR 0x8
| ^~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_flush_input_data_impl':
win_serialport_impl.c:623:24: warning: old-style function definition [-Wold-style-definition]
623 | VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(self)
| ^~~~~~~~~~~~~~~~~~~~~~~~
win_serialport_impl.c: At top level:
win_serialport_impl.c:638:9: warning: 'PURGE_TXABORT' redefined
638 | #define PURGE_TXABORT 0x01
| ^~~~~~~~~~~~~
C:/Ruby34-x64/msys64/ucrt64/include/winbase.h:581:9: note: this is the location of the previous definition
581 | #define PURGE_TXABORT 0x1
| ^~~~~~~~~~~~~
win_serialport_impl.c:639:9: warning: 'PURGE_TXCLEAR' redefined
639 | #define PURGE_TXCLEAR 0x04
| ^~~~~~~~~~~~~
C:/Ruby34-x64/msys64/ucrt64/include/winbase.h:583:9: note: this is the location of the previous definition
583 | #define PURGE_TXCLEAR 0x4
| ^~~~~~~~~~~~~
win_serialport_impl.c: In function 'sp_flush_output_data_impl':
win_serialport_impl.c:640:24: warning: old-style function definition [-Wold-style-definition]
640 | VALUE RB_SERIAL_EXPORT sp_flush_output_data_impl(self)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:251: win_serialport_impl.o] Error 1
make failed, exit code 2
Gem files will remain installed in C:/Ruby34-x64/lib/ruby/gems/3.4.0/gems/serialport-1.3.2 for inspection.
Results logged to C:/Ruby34-x64/lib/ruby/gems/3.4.0/extensions/x64-mingw-ucrt/3.4.0/serialport-1.3.2/gem_make.out