From acb3273b806a3e854f8efa5c573f6f05d873df61 Mon Sep 17 00:00:00 2001 From: Philipp Claves Date: Wed, 6 May 2015 20:47:17 +0200 Subject: [PATCH 01/21] Support baudrate > 1MBit --- ext/native/posix_serialport_impl.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index 4b7329d..fee9723 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -263,7 +263,21 @@ VALUE sp_set_modem_params_impl(argc, argv, self) #ifdef B1000000 case 1000000: data_rate = B1000000; break; #endif - +#ifdef B1500000 + case 1500000: data_rate = B1500000; break; +#endif +#ifdef B2000000 + case 2000000: data_rate = B2000000; break; +#endif +#ifdef B3000000 + case 3000000: data_rate = B3000000; break; +#endif +#ifdef B3500000 + case 3500000: data_rate = B3500000; break; +#endif +#ifdef B4000000 + case 4000000: data_rate = B4000000; break; +#endif default: rb_raise(rb_eArgError, "unknown baud rate"); break; From 8e0cc29a3cb73a87cf9741d154bfcc96a5475b64 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 12 Feb 2025 14:40:12 +0100 Subject: [PATCH 02/21] Fix compatibility with ruby-3.4 This merges the fix and polyfill discussed in: https://bugs.ruby-lang.org/issues/20265#note-7 Fixes #78 --- ext/native/extconf.rb | 2 ++ ext/native/posix_serialport_impl.c | 20 +++----------------- ext/native/serialport.c | 21 +++++++++++++++++++++ ext/native/serialport.h | 5 +++++ ext/native/win_serialport_impl.c | 19 +++---------------- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/ext/native/extconf.rb b/ext/native/extconf.rb index 02a8d8b..3b384af 100644 --- a/ext/native/extconf.rb +++ b/ext/native/extconf.rb @@ -10,4 +10,6 @@ exit(1) if not have_header("termios.h") or not have_header("unistd.h") end +have_func("rb_io_open_descriptor") # ruby-3.3+ + create_makefile('serialport') diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index 2f9325e..a38d29f 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -80,12 +80,6 @@ int get_fd_helper(obj) VALUE sp_create_impl(class, _port) VALUE class, _port; { -#ifdef HAVE_RUBY_IO_H - rb_io_t *fp; -#else - OpenFile *fp; -#endif - int fd; int num_port; char *port; @@ -108,10 +102,7 @@ VALUE sp_create_impl(class, _port) #endif }; struct termios params; - - NEWOBJ(sp, struct RFile); - OBJSETUP(sp, class, T_FILE); - MakeOpenFile((VALUE) sp, fp); + VALUE sp; switch(TYPE(_port)) { @@ -166,14 +157,9 @@ VALUE sp_create_impl(class, _port) rb_sys_fail(sTcsetattr); } -#ifdef HAVE_RUBY_IO_H - fp->fd = fd; -#else - fp->f = rb_fdopen(fd, "r+"); -#endif - fp->mode = FMODE_READWRITE | FMODE_SYNC; + sp = rb_io_open_descriptor(class, fd, FMODE_READWRITE | FMODE_SYNC, Qnil, Qnil, NULL); - return (VALUE) sp; + return sp; } VALUE sp_set_modem_params_impl(argc, argv, self) diff --git a/ext/native/serialport.c b/ext/native/serialport.c index 88ca9a2..0c3f276 100644 --- a/ext/native/serialport.c +++ b/ext/native/serialport.c @@ -20,6 +20,27 @@ VALUE cSerialPort; /* serial port class */ VALUE sBaud, sDataBits, sStopBits, sParity; /* strings */ VALUE sRts, sDtr, sCts, sDsr, sDcd, sRi; + +#ifndef HAVE_RB_IO_OPEN_DESCRIPTOR +VALUE +io_open_descriptor_fallback(VALUE klass, int descriptor, int mode, VALUE path, VALUE timeout, void *encoding) +{ + VALUE arguments[2] = { + (rb_update_max_fd(descriptor), INT2NUM(descriptor)), + INT2FIX(mode), + }; + + VALUE self = rb_class_new_instance(2, arguments, klass); + + rb_io_t *fptr; + GetOpenFile(self, fptr); + fptr->pathv = path; + fptr->mode |= mode; + + return self; +} +#endif + /* * @api private * diff --git a/ext/native/serialport.h b/ext/native/serialport.h index 6aceaf2..166b88a 100644 --- a/ext/native/serialport.h +++ b/ext/native/serialport.h @@ -28,6 +28,11 @@ #include #endif +#ifndef HAVE_RB_IO_OPEN_DESCRIPTOR +VALUE io_open_descriptor_fallback(VALUE klass, int descriptor, int mode, VALUE path, VALUE timeout, void *encoding); +#define rb_io_open_descriptor io_open_descriptor_fallback +#endif + struct modem_params { int data_rate; diff --git a/ext/native/win_serialport_impl.c b/ext/native/win_serialport_impl.c index 7ad3910..465d5f8 100644 --- a/ext/native/win_serialport_impl.c +++ b/ext/native/win_serialport_impl.c @@ -62,23 +62,15 @@ static void _rb_win32_fail(const char *function_call) { VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port) VALUE class, _port; { -#ifdef HAVE_RUBY_IO_H - rb_io_t *fp; -#else - OpenFile *fp; -#endif int fd; HANDLE fh; int num_port; char *str_port; char port[260]; /* Windows XP MAX_PATH. See http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx */ + VALUE sp; DCB dcb; - NEWOBJ(sp, struct RFile); - OBJSETUP(sp, class, T_FILE); - MakeOpenFile((VALUE) sp, fp); - switch(TYPE(_port)) { case T_FIXNUM: @@ -148,13 +140,8 @@ VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port) } errno = 0; - fp->mode = FMODE_READWRITE | FMODE_BINMODE | FMODE_SYNC; -#ifdef HAVE_RUBY_IO_H - fp->fd = fd; -#else - fp->f = fdopen(fd, "rb+"); -#endif - return (VALUE) sp; + sp = rb_io_open_descriptor(class, fd, FMODE_READWRITE | FMODE_BINMODE | FMODE_SYNC, Qnil, Qnil, NULL); + return sp; } VALUE RB_SERIAL_EXPORT sp_set_modem_params_impl(argc, argv, self) From a7083efcfe015f71be8949cfaf952bf97dba8e3a Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 12 Feb 2025 14:46:50 +0100 Subject: [PATCH 03/21] Remove gems.github.com as rubygems source It isn't running any longer for decades. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e5dc77e..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source "https://rubygems.org/" -source "http://gems.github.com/" + gemspec From 1720f06c024e2e642f9d1b19e0924befc21eb551 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 12 Feb 2025 14:56:58 +0100 Subject: [PATCH 04/21] Fix loading of VERSION in gemspec and make it autoload Fixes: LoadError: cannot load such file -- C:/ruby-serialport/(eval at C:/ruby-serialport/lib/serialport/version (LoadError) --- lib/serialport.rb | 5 +++-- lib/serialport/version.rb | 2 +- serialport.gemspec | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/serialport.rb b/lib/serialport.rb index 8062770..4b83349 100644 --- a/lib/serialport.rb +++ b/lib/serialport.rb @@ -1,5 +1,4 @@ require 'serialport.so' -require 'serialport/version' # This class is used for communication over a serial port. @@ -7,7 +6,9 @@ # # @see http://rubydoc.info/stdlib/core/IO Ruby IO class # @see http://www.cmrr.umn.edu/~strupp/serial.html "Serial Programming Guide for POSIX Operating Systems" -class SerialPort +class SerialPort < IO + autoload :VERSION, 'serialport/version' + private_class_method(:create) # Creates a serial port object. diff --git a/lib/serialport/version.rb b/lib/serialport/version.rb index 718c16c..1919056 100644 --- a/lib/serialport/version.rb +++ b/lib/serialport/version.rb @@ -1,3 +1,3 @@ -class SerialPort +class SerialPort < IO VERSION = "1.3.2" end diff --git a/serialport.gemspec b/serialport.gemspec index dc574a9..85cd7ec 100644 --- a/serialport.gemspec +++ b/serialport.gemspec @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/serialport/version', __FILE__) +$: << "lib" +require "serialport/version" Gem::Specification.new do |s| s.name = "serialport" From ed475f1328c8e5e8c6b0c36884cd909e27c2bcaa Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 12 Feb 2025 15:04:59 +0100 Subject: [PATCH 05/21] Remove compatibility to ruby-1.8 --- ext/native/posix_serialport_impl.c | 8 -------- ext/native/serialport.h | 15 ++------------- ext/native/win_serialport_impl.c | 12 ++---------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index a38d29f..fe0fc57 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -64,17 +64,9 @@ static char sIoctl[] = "ioctl"; int get_fd_helper(obj) VALUE obj; { -#ifdef HAVE_RUBY_IO_H rb_io_t *fptr; -#else - OpenFile *fptr; -#endif GetOpenFile(obj, fptr); -#ifdef HAVE_RUBY_IO_H return (fptr->fd); -#else - return (fileno(fptr->f)); -#endif } VALUE sp_create_impl(class, _port) diff --git a/ext/native/serialport.h b/ext/native/serialport.h index 166b88a..8c51412 100644 --- a/ext/native/serialport.h +++ b/ext/native/serialport.h @@ -22,11 +22,7 @@ #define _RUBY_SERIAL_PORT_H_ #include /* ruby inclusion */ -#ifdef HAVE_RUBY_IO_H /* ruby io inclusion */ - #include -#else - #include -#endif +#include #ifndef HAVE_RB_IO_OPEN_DESCRIPTOR VALUE io_open_descriptor_fallback(VALUE klass, int descriptor, int mode, VALUE path, VALUE timeout, void *encoding); @@ -61,14 +57,7 @@ struct line_signals #define EVEN EVENPARITY #define ODD ODDPARITY - #ifndef RB_SERIAL_EXPORT - #ifndef HAVE_RUBY_IO_H - #define RB_SERIAL_EXPORT __declspec(dllexport) - #else - #define RB_SERIAL_EXPORT - #endif - #endif - + #define RB_SERIAL_EXPORT #else #define EVEN 1 #define ODD 2 diff --git a/ext/native/win_serialport_impl.c b/ext/native/win_serialport_impl.c index 465d5f8..781bbc1 100644 --- a/ext/native/win_serialport_impl.c +++ b/ext/native/win_serialport_impl.c @@ -36,25 +36,17 @@ static char sSetCommTimeouts[] = "SetCommTimeouts"; static HANDLE get_handle_helper(obj) VALUE obj; { -#ifdef HAVE_RUBY_IO_H rb_io_t *fptr; -#else - OpenFile *fptr; -#endif GetOpenFile(obj, fptr); -#ifdef HAVE_RUBY_IO_H return (HANDLE) _get_osfhandle(fptr->fd); -#else - return (HANDLE) _get_osfhandle(fileno(fptr->f)); -#endif } /* hack to work around the fact that Ruby doesn't use GetLastError? */ static void _rb_win32_fail(const char *function_call) { rb_raise( - rb_eRuntimeError, - "%s failed: GetLastError returns %d", + rb_eRuntimeError, + "%s failed: GetLastError returns %d", function_call, GetLastError( ) ); } From 1786efd3a6d9ed69688e2aed69ec8cc644988828 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 12 Feb 2025 15:13:35 +0100 Subject: [PATCH 06/21] Fix warning about deprecated access to fptr->fd Warning was: warning: 'fd' is deprecated: rb_io_descriptor --- ext/native/extconf.rb | 1 + ext/native/posix_serialport_impl.c | 13 ++++++++----- ext/native/win_serialport_impl.c | 14 ++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ext/native/extconf.rb b/ext/native/extconf.rb index 3b384af..df36284 100644 --- a/ext/native/extconf.rb +++ b/ext/native/extconf.rb @@ -10,6 +10,7 @@ exit(1) if not have_header("termios.h") or not have_header("unistd.h") end +have_func("rb_io_descriptor") # ruby-3.1+ have_func("rb_io_open_descriptor") # ruby-3.3+ create_makefile('serialport') diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index fe0fc57..c096e08 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -61,12 +61,15 @@ static char sTcsetattr[] = "tcsetattr"; static char sIoctl[] = "ioctl"; -int get_fd_helper(obj) - VALUE obj; +int get_fd_helper(VALUE io) { - rb_io_t *fptr; - GetOpenFile(obj, fptr); - return (fptr->fd); +#ifdef HAVE_RB_IO_DESCRIPTOR + return rb_io_descriptor(io); +#else + rb_io_t* fp; + GetOpenFile(io, fp); + return fp->fd; +#endif } VALUE sp_create_impl(class, _port) diff --git a/ext/native/win_serialport_impl.c b/ext/native/win_serialport_impl.c index 781bbc1..26c5499 100644 --- a/ext/native/win_serialport_impl.c +++ b/ext/native/win_serialport_impl.c @@ -33,13 +33,15 @@ static char sGetCommTimeouts[] = "GetCommTimeouts"; static char sSetCommTimeouts[] = "SetCommTimeouts"; -static HANDLE get_handle_helper(obj) - VALUE obj; +static HANDLE get_handle_helper(VALUE io) { - rb_io_t *fptr; - - GetOpenFile(obj, fptr); - return (HANDLE) _get_osfhandle(fptr->fd); +#ifdef HAVE_RB_IO_DESCRIPTOR + return (HANDLE) _get_osfhandle(rb_io_descriptor(io)); +#else + rb_io_t* fp; + GetOpenFile(io, fp); + return (HANDLE) _get_osfhandle(fp->fd); +#endif } /* hack to work around the fact that Ruby doesn't use GetLastError? */ From 3328126acc4194b7ac877d815c38dfe3d2192814 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 13 Feb 2025 09:24:48 +0100 Subject: [PATCH 07/21] Replace ancient K&R function declarations by ANSI style --- ext/native/posix_serialport_impl.c | 58 +++++----------- ext/native/serialport.c | 102 ++++++++++------------------- ext/native/win_serialport_impl.c | 61 ++++++----------- 3 files changed, 71 insertions(+), 150 deletions(-) diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index c096e08..8c0283e 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -72,8 +72,7 @@ int get_fd_helper(VALUE io) #endif } -VALUE sp_create_impl(class, _port) - VALUE class, _port; +VALUE sp_create_impl(VALUE class, VALUE _port) { int fd; int num_port; @@ -157,9 +156,7 @@ VALUE sp_create_impl(class, _port) return sp; } -VALUE sp_set_modem_params_impl(argc, argv, self) - int argc; - VALUE *argv, self; +VALUE sp_set_modem_params_impl(int argc, VALUE *argv, VALUE self) { int fd; struct termios params; @@ -380,9 +377,7 @@ VALUE sp_set_modem_params_impl(argc, argv, self) return argv[0]; } -void get_modem_params_impl(self, mp) - VALUE self; - struct modem_params *mp; +void get_modem_params_impl(VALUE self, struct modem_params *mp) { int fd; struct termios params; @@ -474,8 +469,7 @@ void get_modem_params_impl(self, mp) } } -VALUE sp_set_flow_control_impl(self, val) - VALUE self, val; +VALUE sp_set_flow_control_impl(VALUE self, VALUE val) { int fd; int flowc; @@ -521,8 +515,7 @@ VALUE sp_set_flow_control_impl(self, val) return val; } -VALUE sp_get_flow_control_impl(self) - VALUE self; +VALUE sp_get_flow_control_impl(VALUE self) { int ret; int fd; @@ -551,8 +544,7 @@ VALUE sp_get_flow_control_impl(self) return INT2FIX(ret); } -VALUE sp_set_read_timeout_impl(self, val) - VALUE self, val; +VALUE sp_set_read_timeout_impl(VALUE self, VALUE val) { int timeout; int fd; @@ -591,8 +583,7 @@ VALUE sp_set_read_timeout_impl(self, val) return val; } -VALUE sp_get_read_timeout_impl(self) - VALUE self; +VALUE sp_get_read_timeout_impl(VALUE self) { int fd; struct termios params; @@ -611,22 +602,19 @@ VALUE sp_get_read_timeout_impl(self) return INT2FIX(params.c_cc[VTIME] * 100); } -VALUE sp_set_write_timeout_impl(self, val) - VALUE self, val; +VALUE sp_set_write_timeout_impl(VALUE self, VALUE val) { rb_notimplement(); return self; } -VALUE sp_get_write_timeout_impl(self) - VALUE self; +VALUE sp_get_write_timeout_impl(VALUE self) { rb_notimplement(); return self; } -VALUE sp_break_impl(self, time) - VALUE self, time; +VALUE sp_break_impl(VALUE self, VALUE time) { int fd; @@ -642,9 +630,7 @@ VALUE sp_break_impl(self, time) return Qnil; } -void get_line_signals_helper_impl(obj, ls) - VALUE obj; - struct line_signals *ls; +void get_line_signals_helper_impl(VALUE obj, struct line_signals *ls) { int fd, status; @@ -663,9 +649,7 @@ void get_line_signals_helper_impl(obj, ls) ls->ri = (status & TIOCM_RI ? 1 : 0); } -VALUE set_signal_impl(obj, val, sig) - VALUE obj,val; - int sig; +VALUE set_signal_impl(VALUE obj, VALUE val, int sig) { int status; int fd; @@ -702,20 +686,17 @@ VALUE set_signal_impl(obj, val, sig) return val; } -VALUE sp_set_rts_impl(self, val) - VALUE self, val; +VALUE sp_set_rts_impl(VALUE self, VALUE val) { return set_signal_impl(self, val, TIOCM_RTS); } -VALUE sp_set_dtr_impl(self, val) - VALUE self, val; +VALUE sp_set_dtr_impl(VALUE self, VALUE val) { return set_signal_impl(self, val, TIOCM_DTR); } -VALUE sp_get_rts_impl(self) - VALUE self; +VALUE sp_get_rts_impl(VALUE self) { struct line_signals ls; @@ -723,8 +704,7 @@ VALUE sp_get_rts_impl(self) return INT2FIX(ls.rts); } -VALUE sp_get_dtr_impl(self) - VALUE self; +VALUE sp_get_dtr_impl(VALUE self) { struct line_signals ls; @@ -733,8 +713,7 @@ VALUE sp_get_dtr_impl(self) return INT2FIX(ls.dtr); } -VALUE sp_flush_input_data_impl(self) -VALUE self; +VALUE sp_flush_input_data_impl(VALUE self) { int fd; int ret; @@ -749,8 +728,7 @@ VALUE self; return Qtrue; } -VALUE sp_flush_output_data_impl(self) -VALUE self; +VALUE sp_flush_output_data_impl(VALUE self) { int fd; int ret; diff --git a/ext/native/serialport.c b/ext/native/serialport.c index 0c3f276..a5850ff 100644 --- a/ext/native/serialport.c +++ b/ext/native/serialport.c @@ -47,8 +47,7 @@ io_open_descriptor_fallback(VALUE klass, int descriptor, int mode, VALUE path, V * @see SerialPort#new * @see SerialPort#open */ -static VALUE sp_create(class, _port) - VALUE class, _port; +static VALUE sp_create(VALUE class, VALUE _port) { return sp_create_impl(class, _port); } @@ -68,7 +67,7 @@ static VALUE sp_create(class, _port) * (baud, data_bits = 8, stop_bits = 1, parity = (previous_databits == 8 ? NONE : EVEN)) * A baudrate of nil will keep the old value. * The default parity depends on the number of databits configured before this function call. - * + * * @overload set_modem_params(baud, data_bits, stop_bits, parity) * @param baud [Integer] the baud rate * @param data_bits [Integer] the number of data bits @@ -80,9 +79,7 @@ static VALUE sp_create(class, _port) * @return [Hash] the original paramters * @raise [ArgumentError] if values are invalide or unsupported */ -static VALUE sp_set_modem_params(argc, argv, self) - int argc; - VALUE *argv, self; +static VALUE sp_set_modem_params(int argc, VALUE *argv, VALUE self) { return sp_set_modem_params_impl(argc, argv, self); } @@ -94,20 +91,18 @@ static VALUE sp_set_modem_params(argc, argv, self) * @return [nil] * @note (POSIX) this value is very approximate */ -static VALUE sp_break(self, time) - VALUE self, time; +static VALUE sp_break(VALUE self, VALUE time) { return sp_break_impl(self, time); } /* - * Get the state of the DTR line + * Get the state of the DTR line * * @note (Windows) DTR is not available * @return [Integer] the state of DTR line, 0 or 1 */ -static VALUE sp_get_dtr(self) - VALUE self; +static VALUE sp_get_dtr(VALUE self) { return sp_get_dtr_impl(self); } @@ -118,8 +113,7 @@ static VALUE sp_get_dtr(self) * @return [Integer] the flow control flag * @see SerialPort#set_flow_control */ -static VALUE sp_get_flow_control(self) - VALUE self; +static VALUE sp_get_flow_control(VALUE self) { return sp_get_flow_control_impl(self); } @@ -130,8 +124,7 @@ static VALUE sp_get_flow_control(self) * @return [Integer] the read timeout, in milliseconds * @see SerialPort#set_read_timeout */ -static VALUE sp_get_read_timeout(self) - VALUE self; +static VALUE sp_get_read_timeout(VALUE self) { return sp_get_read_timeout_impl(self); } @@ -142,8 +135,7 @@ static VALUE sp_get_read_timeout(self) * @return [Integer] the state of RTS line, 0 or 1 * @note (Windows) RTS is not available */ -static VALUE sp_get_rts(self) - VALUE self; +static VALUE sp_get_rts(VALUE self) { return sp_get_rts_impl(self); } @@ -154,8 +146,7 @@ static VALUE sp_get_rts(self) * @return [Integer] the write timeout, in milliseconds * @note (POSIX) write timeouts are not implemented */ -static VALUE sp_get_write_timeout(self) - VALUE self; +static VALUE sp_get_write_timeout(VALUE self) { return sp_get_write_timeout_impl(self); } @@ -166,8 +157,7 @@ static VALUE sp_get_write_timeout(self) * @param val [Integer] the desired state of the DTR line, 0 or 1 * @return [Integer] the original +val+ parameter */ -static VALUE sp_set_dtr(self, val) - VALUE self, val; +static VALUE sp_set_dtr(VALUE self, VALUE val) { return sp_set_dtr_impl(self, val); } @@ -182,8 +172,7 @@ static VALUE sp_set_dtr(self, val) * @note SerialPort::HARD uses RTS/CTS handshaking. * DSR/DTR is not supported. */ -static VALUE sp_set_flow_control(self, val) - VALUE self, val; +static VALUE sp_set_flow_control(VALUE self, VALUE val) { return sp_set_flow_control_impl(self, val); } @@ -200,8 +189,7 @@ static VALUE sp_set_flow_control(self, val) * @return [Integer] the original +timeout+ parameter * @note Read timeouts don't mix well with multi-threading */ -static VALUE sp_set_read_timeout(self, val) - VALUE self, val; +static VALUE sp_set_read_timeout(VALUE self, VALUE val) { return sp_set_read_timeout_impl(self, val); } @@ -212,8 +200,7 @@ static VALUE sp_set_read_timeout(self, val) * @param val [Integer] the state of RTS line, 0 or 1 * @return [Integer] the original +val+ parameter */ -static VALUE sp_set_rts(self, val) - VALUE self, val; +static VALUE sp_set_rts(VALUE self, VALUE val) { return sp_set_rts_impl(self, val); } @@ -225,8 +212,7 @@ static VALUE sp_set_rts(self, val) * @return [Integer] the original +val+ parameter * @note (POSIX) write timeouts are not implemented */ -static VALUE sp_set_write_timeout(self, val) - VALUE self, val; +static VALUE sp_set_write_timeout(VALUE self, VALUE val) { return sp_set_write_timeout_impl(self, val); } @@ -234,9 +220,7 @@ static VALUE sp_set_write_timeout(self, val) /* * @private helper */ -static void get_modem_params(self, mp) - VALUE self; - struct modem_params *mp; +static void get_modem_params(VALUE self, struct modem_params *mp) { get_modem_params_impl(self, mp); } @@ -248,8 +232,7 @@ static void get_modem_params(self, mp) * @return [Integer] the original +data_rate+ parameter * @see SerialPort#set_modem_params */ -static VALUE sp_set_data_rate(self, data_rate) - VALUE self, data_rate; +static VALUE sp_set_data_rate(VALUE self, VALUE data_rate) { VALUE argv[4]; @@ -267,8 +250,7 @@ static VALUE sp_set_data_rate(self, data_rate) * @return [Integer] the original +data_bits+ parameter * @see SerialPort#set_modem_params */ -static VALUE sp_set_data_bits(self, data_bits) - VALUE self, data_bits; +static VALUE sp_set_data_bits(VALUE self, VALUE data_bits) { VALUE argv[4]; @@ -286,8 +268,7 @@ static VALUE sp_set_data_bits(self, data_bits) * @return [Integer] the original +stop_bits+ parameter * @see SerialPort#set_modem_params */ -static VALUE sp_set_stop_bits(self, stop_bits) - VALUE self, stop_bits; +static VALUE sp_set_stop_bits(VALUE self, VALUE stop_bits) { VALUE argv[4]; @@ -305,8 +286,7 @@ static VALUE sp_set_stop_bits(self, stop_bits) * @return [Integer] the original +parity+ parameter * @see SerialPort#set_modem_params */ -static VALUE sp_set_parity(self, parity) - VALUE self, parity; +static VALUE sp_set_parity(VALUE self, VALUE parity) { VALUE argv[4]; @@ -323,8 +303,7 @@ static VALUE sp_set_parity(self, parity) * @return [Integer] the current baud rate * @see SerialPort#set_modem_params */ -static VALUE sp_get_data_rate(self) - VALUE self; +static VALUE sp_get_data_rate(VALUE self) { struct modem_params mp; @@ -339,8 +318,7 @@ static VALUE sp_get_data_rate(self) * @return [Integer] the current number of data bits * @see SerialPort#set_modem_params */ -static VALUE sp_get_data_bits(self) - VALUE self; +static VALUE sp_get_data_bits(VALUE self) { struct modem_params mp; @@ -355,8 +333,7 @@ static VALUE sp_get_data_bits(self) * @return [Integer] the current number of stop bits * @see SerialPort#set_modem_params for details */ -static VALUE sp_get_stop_bits(self) - VALUE self; +static VALUE sp_get_stop_bits(VALUE self) { struct modem_params mp; @@ -371,8 +348,7 @@ static VALUE sp_get_stop_bits(self) * @return [Integer] the current parity * @see SerialPort#set_modem_params */ -static VALUE sp_get_parity(self) - VALUE self; +static VALUE sp_get_parity(VALUE self) { struct modem_params mp; @@ -387,8 +363,7 @@ static VALUE sp_get_parity(self) * @return [Hash] the serial port configuration * @see SerialPort#set_modem_params */ -static VALUE sp_get_modem_params(self) - VALUE self; +static VALUE sp_get_modem_params(VALUE self) { struct modem_params mp; VALUE hash; @@ -408,9 +383,7 @@ static VALUE sp_get_modem_params(self) /* * @api private */ -void get_line_signals_helper(obj, ls) - VALUE obj; - struct line_signals *ls; +void get_line_signals_helper(VALUE obj, struct line_signals *ls) { get_line_signals_helper_impl(obj, ls); } @@ -421,8 +394,7 @@ void get_line_signals_helper(obj, ls) * @return [Integer] the state of the CTS line, 0 or 1 * @see SerialPort#get_signals */ -static VALUE sp_get_cts(self) - VALUE self; +static VALUE sp_get_cts(VALUE self) { struct line_signals ls; @@ -437,8 +409,7 @@ static VALUE sp_get_cts(self) * @return [Integer] the state of the DSR line, 0 or 1 * @see SerialPort#get_signals */ -static VALUE sp_get_dsr(self) - VALUE self; +static VALUE sp_get_dsr(VALUE self) { struct line_signals ls; @@ -453,8 +424,7 @@ static VALUE sp_get_dsr(self) * @return [Integer] the state of the DCD line, 0 or 1 * @see SerialPort#get_signals */ -static VALUE sp_get_dcd(self) - VALUE self; +static VALUE sp_get_dcd(VALUE self) { struct line_signals ls; @@ -469,8 +439,7 @@ static VALUE sp_get_dcd(self) * @return [Integer] the state of the RI line, 0 or 1 * @see SerialPort#get_signals */ -static VALUE sp_get_ri(self) - VALUE self; +static VALUE sp_get_ri(VALUE self) { struct line_signals ls; @@ -488,8 +457,7 @@ static VALUE sp_get_ri(self) * @note (Windows) the rts and dtr values are not included * @note This method is implemented as both SerialPort#signals and SerialPort#get_signals */ -static VALUE sp_signals(self) - VALUE self; +static VALUE sp_signals(VALUE self) { struct line_signals ls; VALUE hash; @@ -515,8 +483,7 @@ static VALUE sp_signals(self) * * @return [Boolean] true on success or false if an error occurs. */ -static VALUE sp_flush_input_data(self) - VALUE self; +static VALUE sp_flush_input_data(VALUE self) { return sp_flush_input_data_impl(self); } @@ -526,14 +493,13 @@ static VALUE sp_flush_input_data(self) * * @return [Boolean] true on success or false if an error occurs. */ -static VALUE sp_flush_output_data(self) - VALUE self; +static VALUE sp_flush_output_data(VALUE self) { return sp_flush_output_data_impl(self); } -void Init_serialport() +void Init_serialport(void) { sBaud = rb_str_new2("baud"); sDataBits = rb_str_new2("data_bits"); diff --git a/ext/native/win_serialport_impl.c b/ext/native/win_serialport_impl.c index 26c5499..0cfb77e 100644 --- a/ext/native/win_serialport_impl.c +++ b/ext/native/win_serialport_impl.c @@ -53,8 +53,7 @@ static void _rb_win32_fail(const char *function_call) { ); } -VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port) - VALUE class, _port; +VALUE RB_SERIAL_EXPORT sp_create_impl(VALUE class, VALUE _port) { int fd; HANDLE fh; @@ -138,9 +137,7 @@ VALUE RB_SERIAL_EXPORT sp_create_impl(class, _port) return sp; } -VALUE RB_SERIAL_EXPORT sp_set_modem_params_impl(argc, argv, self) - int argc; - VALUE *argv, self; +VALUE RB_SERIAL_EXPORT sp_set_modem_params_impl(int argc, VALUE *argv, VALUE self) { HANDLE fh; DCB dcb; @@ -275,9 +272,7 @@ VALUE RB_SERIAL_EXPORT sp_set_modem_params_impl(argc, argv, self) return argv[0]; } -void RB_SERIAL_EXPORT get_modem_params_impl(self, mp) - VALUE self; - struct modem_params *mp; +void RB_SERIAL_EXPORT get_modem_params_impl(VALUE self, struct modem_params *mp) { HANDLE fh; DCB dcb; @@ -295,8 +290,7 @@ void RB_SERIAL_EXPORT get_modem_params_impl(self, mp) mp->parity = dcb.Parity; } -VALUE RB_SERIAL_EXPORT sp_set_flow_control_impl(self, val) - VALUE self, val; +VALUE RB_SERIAL_EXPORT sp_set_flow_control_impl(VALUE self, VALUE val) { HANDLE fh; int flowc; @@ -340,8 +334,7 @@ VALUE RB_SERIAL_EXPORT sp_set_flow_control_impl(self, val) return val; } -VALUE RB_SERIAL_EXPORT sp_get_flow_control_impl(self) - VALUE self; +VALUE RB_SERIAL_EXPORT sp_get_flow_control_impl(VALUE self) { HANDLE fh; int ret; @@ -368,8 +361,7 @@ VALUE RB_SERIAL_EXPORT sp_get_flow_control_impl(self) return INT2FIX(ret); } -VALUE RB_SERIAL_EXPORT sp_set_read_timeout_impl(self, val) - VALUE self, val; +VALUE RB_SERIAL_EXPORT sp_set_read_timeout_impl(VALUE self, VALUE val) { int timeout; HANDLE fh; @@ -411,8 +403,7 @@ VALUE RB_SERIAL_EXPORT sp_set_read_timeout_impl(self, val) return val; } -VALUE RB_SERIAL_EXPORT sp_get_read_timeout_impl(self) - VALUE self; +VALUE RB_SERIAL_EXPORT sp_get_read_timeout_impl(VALUE self) { HANDLE fh; COMMTIMEOUTS ctout; @@ -434,8 +425,7 @@ VALUE RB_SERIAL_EXPORT sp_get_read_timeout_impl(self) return INT2FIX(ctout.ReadTotalTimeoutConstant); } -VALUE RB_SERIAL_EXPORT sp_set_write_timeout_impl(self, val) - VALUE self, val; +VALUE RB_SERIAL_EXPORT sp_set_write_timeout_impl(VALUE self, VALUE val) { int timeout; HANDLE fh; @@ -469,8 +459,7 @@ VALUE RB_SERIAL_EXPORT sp_set_write_timeout_impl(self, val) return val; } -VALUE RB_SERIAL_EXPORT sp_get_write_timeout_impl(self) - VALUE self; +VALUE RB_SERIAL_EXPORT sp_get_write_timeout_impl(VALUE self) { HANDLE fh; COMMTIMEOUTS ctout; @@ -484,8 +473,7 @@ VALUE RB_SERIAL_EXPORT sp_get_write_timeout_impl(self) return INT2FIX(ctout.WriteTotalTimeoutMultiplier); } -static void delay_ms(time) - int time; +static void delay_ms(int time) { HANDLE ev; @@ -503,8 +491,7 @@ static void delay_ms(time) CloseHandle(ev); } -VALUE RB_SERIAL_EXPORT sp_break_impl(self, time) - VALUE self, time; +VALUE RB_SERIAL_EXPORT sp_break_impl(VALUE self, VALUE time) { HANDLE fh; @@ -522,9 +509,7 @@ VALUE RB_SERIAL_EXPORT sp_break_impl(self, time) return Qnil; } -void RB_SERIAL_EXPORT get_line_signals_helper_impl(obj, ls) - VALUE obj; - struct line_signals *ls; +void RB_SERIAL_EXPORT get_line_signals_helper_impl(VALUE obj, struct line_signals *ls) { HANDLE fh; unsigned long status; /* DWORD */ @@ -541,9 +526,7 @@ void RB_SERIAL_EXPORT get_line_signals_helper_impl(obj, ls) ls->ri = (status & MS_RING_ON ? 1 : 0); } -static VALUE set_signal(obj, val, sigoff, sigon) - VALUE obj,val; - int sigoff, sigon; +static VALUE set_signal(VALUE obj, VALUE val, int sigoff, int sigon) { HANDLE fh; int set, sig; @@ -573,27 +556,23 @@ static VALUE set_signal(obj, val, sigoff, sigon) return val; } -VALUE RB_SERIAL_EXPORT sp_set_rts_impl(self, val) - VALUE self, val; +VALUE RB_SERIAL_EXPORT sp_set_rts_impl(VALUE self, VALUE val) { return set_signal(self, val, CLRRTS, SETRTS); } -VALUE RB_SERIAL_EXPORT sp_set_dtr_impl(self, val) - VALUE self, val; +VALUE RB_SERIAL_EXPORT sp_set_dtr_impl(VALUE self, VALUE val) { return set_signal(self, val, CLRDTR, SETDTR); } -VALUE RB_SERIAL_EXPORT sp_get_rts_impl(self) - VALUE self; +VALUE RB_SERIAL_EXPORT sp_get_rts_impl(VALUE self) { rb_notimplement(); return self; } -VALUE RB_SERIAL_EXPORT sp_get_dtr_impl(self) - VALUE self; +VALUE RB_SERIAL_EXPORT sp_get_dtr_impl(VALUE self) { rb_notimplement(); return self; @@ -601,8 +580,7 @@ VALUE RB_SERIAL_EXPORT sp_get_dtr_impl(self) #define PURGE_RXABORT 0x02 #define PURGE_RXCLEAR 0x08 -VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(self) - VALUE self; +VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(VALUE self) { BOOL ret; HANDLE fh; @@ -618,8 +596,7 @@ VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(self) #define PURGE_TXABORT 0x01 #define PURGE_TXCLEAR 0x04 -VALUE RB_SERIAL_EXPORT sp_flush_output_data_impl(self) - VALUE self; +VALUE RB_SERIAL_EXPORT sp_flush_output_data_impl(VALUE self) { BOOL ret; HANDLE fh; From d1a988c6a6853b41b19aef221d32ac7f76435050 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 13 Feb 2025 09:28:18 +0100 Subject: [PATCH 08/21] Avoid compiler warning warning: initialization discards "const" qualifier from pointer target type [-Wdiscarded-qualifiers] "/dev/ttyS0" --- ext/native/posix_serialport_impl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index 8c0283e..3d40232 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -76,8 +76,8 @@ VALUE sp_create_impl(VALUE class, VALUE _port) { int fd; int num_port; - char *port; - char *ports[] = { + const char *port; + const char *ports[] = { #if defined(OS_LINUX) || defined(OS_CYGWIN) "/dev/ttyS0", "/dev/ttyS1", "/dev/ttyS2", "/dev/ttyS3", "/dev/ttyS4", "/dev/ttyS5", "/dev/ttyS6", "/dev/ttyS7" From 9d513fe3480fdaf0c3ec4bd89ed2eb66f96cd957 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 13 Feb 2025 10:13:11 +0100 Subject: [PATCH 09/21] Avoid compiler warning: warning: comparison of integer expressions of different signedness: "int" and "long unsigned int" [-Wsign-compare] if (num_port < 0 || num_port > sizeof(ports) / sizeof(ports[0])) --- ext/native/posix_serialport_impl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index 3d40232..0681131 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -75,7 +75,7 @@ int get_fd_helper(VALUE io) VALUE sp_create_impl(VALUE class, VALUE _port) { int fd; - int num_port; + long num_port; const char *port; const char *ports[] = { #if defined(OS_LINUX) || defined(OS_CYGWIN) @@ -101,8 +101,8 @@ VALUE sp_create_impl(VALUE class, VALUE _port) switch(TYPE(_port)) { case T_FIXNUM: - num_port = FIX2INT(_port); - if (num_port < 0 || num_port > sizeof(ports) / sizeof(ports[0])) + num_port = FIX2LONG(_port); + if (num_port < 0 || num_port > (long)(sizeof(ports) / sizeof(ports[0]))) { rb_raise(rb_eArgError, "illegal port number"); } From 743d2712848cb4bf8985905f9420fb73c6167ff0 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 13 Feb 2025 10:16:26 +0100 Subject: [PATCH 10/21] Avoid compiler warning: warning: function might be candidate for attribute "noreturn" [-Wsuggest-attribute=noreturn] --- ext/native/posix_serialport_impl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/native/posix_serialport_impl.c b/ext/native/posix_serialport_impl.c index 0681131..f4309cd 100644 --- a/ext/native/posix_serialport_impl.c +++ b/ext/native/posix_serialport_impl.c @@ -602,16 +602,14 @@ VALUE sp_get_read_timeout_impl(VALUE self) return INT2FIX(params.c_cc[VTIME] * 100); } -VALUE sp_set_write_timeout_impl(VALUE self, VALUE val) +NORETURN(VALUE sp_set_write_timeout_impl(VALUE self, VALUE val)) { rb_notimplement(); - return self; } -VALUE sp_get_write_timeout_impl(VALUE self) +NORETURN(VALUE sp_get_write_timeout_impl(VALUE self)) { rb_notimplement(); - return self; } VALUE sp_break_impl(VALUE self, VALUE time) From d2d85654ce53d0e2050c1fc15892694d7cd7e3a6 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Thu, 13 Feb 2025 10:19:11 +0100 Subject: [PATCH 11/21] Avoid compiler waring about redefinition: warning: "PURGE_RXABORT" redefined 581 | #define PURGE_RXABORT 0x02 | ^~~~~~~~~~~~~ In file included from C:/msys64/ucrt64/include/windows.h:70, --- ext/native/win_serialport_impl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/native/win_serialport_impl.c b/ext/native/win_serialport_impl.c index 0cfb77e..2b7abe6 100644 --- a/ext/native/win_serialport_impl.c +++ b/ext/native/win_serialport_impl.c @@ -578,8 +578,12 @@ VALUE RB_SERIAL_EXPORT sp_get_dtr_impl(VALUE self) return self; } +#ifndef PURGE_RXABORT #define PURGE_RXABORT 0x02 +#endif +#ifndef PURGE_RXCLEAR #define PURGE_RXCLEAR 0x08 +#endif VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(VALUE self) { BOOL ret; @@ -594,8 +598,12 @@ VALUE RB_SERIAL_EXPORT sp_flush_input_data_impl(VALUE self) return Qtrue; } +#ifndef PURGE_TXABORT #define PURGE_TXABORT 0x01 +#endif +#ifndef PURGE_TXCLEAR #define PURGE_TXCLEAR 0x04 +#endif VALUE RB_SERIAL_EXPORT sp_flush_output_data_impl(VALUE self) { BOOL ret; From 5380259a25315560d0db717c24257ebc80d021c8 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 09:13:32 +0200 Subject: [PATCH 12/21] New repository link and add Lars as new author --- README.md | 1 + serialport.gemspec | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ee29a40..de4209e 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,4 @@ GPL * Tobin Richard * Hector Parra * Ryan C. Payne +* Lars Kanis diff --git a/serialport.gemspec b/serialport.gemspec index 85cd7ec..d032580 100644 --- a/serialport.gemspec +++ b/serialport.gemspec @@ -6,11 +6,11 @@ Gem::Specification.new do |s| s.name = "serialport" s.license = "GPL-2" s.version = SerialPort::VERSION - s.authors = ["Guillaume Pierronnet", "Alan Stern", "Daniel E. Shipton", "Tobin Richard", "Hector Parra", "Ryan C. Payne"] + s.authors = ["Guillaume Pierronnet", "Alan Stern", "Daniel E. Shipton", "Tobin Richard", "Hector Parra", "Ryan C. Payne", "Lars Kanis"] s.summary = "Library for using RS-232 serial ports." s.description = "Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports." - s.email = "hector@hectorparra.com" - s.homepage = "http://github.com/hparra/ruby-serialport/" + s.email = "lars@greiz-reinsdorf.de" + s.homepage = "http://github.com/larskanis/ruby-serialport/" s.add_development_dependency "bundler" s.add_development_dependency "rake" From 7e1d8c90bde15e2c325ba5b79811bc08ce44130c Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 09:15:52 +0200 Subject: [PATCH 13/21] Remove outdated comment about precompiled versions --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index de4209e..ede1115 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ Ruby/SerialPort is a Ruby library that provides a class for using RS-232 serial ports. This class also contains low-level functions to check and set the current state of the signals on the line. -The native Windows version of this library supports the Microsoft Visual C++, Borland C++, and MinGW compilers. - There is an alternative gem with MRI, JRuby, and Rubinius support. See below. ## Installation From 8bb32c45d965b0fd054f57c9f92a5e95d39393f8 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 09:16:09 +0200 Subject: [PATCH 14/21] Bump VERSION to 1.4.0 --- lib/serialport/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/serialport/version.rb b/lib/serialport/version.rb index 1919056..ab5d5e1 100644 --- a/lib/serialport/version.rb +++ b/lib/serialport/version.rb @@ -1,3 +1,3 @@ class SerialPort < IO - VERSION = "1.3.2" + VERSION = "1.4.0" end From daa72d4f94edfece2828cd3b1372c5d8d0950b3d Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 09:24:39 +0200 Subject: [PATCH 15/21] Move CI from Travis to Github --- .github/workflows/ci.yml | 99 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 12 ----- 2 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..823f4f9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,99 @@ +name: CI +on: + workflow_dispatch: + schedule: + - cron: "0 5 * * 3" # At 05:00 on Wednesday # https://crontab.guru/#0_5_*_*_3 + push: + branches: + - master + tags: + - "*.*.*" + pull_request: + types: [opened, synchronize] + branches: + - "*" +permissions: + contents: read + +jobs: + rcd_build: + name: build gem + + runs-on: ubuntu-latest + env: + PLATFORM: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.4" + + - name: Build ffi.gem + run: | + bundle install + bundle exec rake gem + + - name: Upload binary gem + uses: actions/upload-artifact@v4 + with: + name: gem-${{ matrix.platform }} + path: pkg/*-*.gem + + job_test_native: + name: native test + needs: rcd_build + strategy: + fail-fast: false + matrix: + os: + - windows-latest + - macos-13 + - macos-latest + - ubuntu-latest + - windows-11-arm + ruby: + - "head" + - "3.4" + - "3.3" + - "3.2" + - "3.1" + - "3.0" + - "2.7" + - "2.6" + - "2.5" + exclude: + - os: macos-latest + ruby: "2.5" + - os: windows-11-arm + ruby: "3.3" + - os: windows-11-arm + ruby: "3.2" + - os: windows-11-arm + ruby: "3.1" + - os: windows-11-arm + ruby: "3.0" + - os: windows-11-arm + ruby: "2.7" + - os: windows-11-arm + ruby: "2.6" + - os: windows-11-arm + ruby: "2.5" + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - run: ruby --version + - name: Download gem-${{matrix.platform}} + uses: actions/download-artifact@v4 + with: + name: gem-${{ matrix.platform }} + - name: Install gem-${{matrix.platform}} + run: gem install --local *.gem --verbose + - name: Run tests + run: | + bundle install + ruby -rserialport -S rake test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 00f7828..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: ruby -script: "bundle exec rake test" -rvm: - - 1.8.7 - - 1.9.2 - - 1.9.3 - - 2.0.0 -compiler: - - clang - - gcc -before_script: - - rake compile From a14cf77b64c355b0be222fb211dcd1b41fc8e624 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 09:35:56 +0200 Subject: [PATCH 16/21] Set minimum Ruby version to 2.5 Olders are not tested. --- serialport.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/serialport.gemspec b/serialport.gemspec index d032580..0addaba 100644 --- a/serialport.gemspec +++ b/serialport.gemspec @@ -12,6 +12,7 @@ Gem::Specification.new do |s| s.email = "lars@greiz-reinsdorf.de" s.homepage = "http://github.com/larskanis/ruby-serialport/" + s.required_ruby_version = '>= 2.5' s.add_development_dependency "bundler" s.add_development_dependency "rake" s.add_development_dependency "rake-compiler", ">= 0.4.1" From 8e6a8bc2683b40587ff7b07d79a4e68a822e1b33 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 09:40:42 +0200 Subject: [PATCH 17/21] Fix clang warnings in Win32 impl. win_serialport_impl.c:52:20: warning: format specifies type 'int' but the argument has type 'DWORD' (aka 'unsigned long') [-Wformat] 51 | "%s failed: GetLastError returns %d", | ~~ | %lu 52 | function_call, GetLastError( ) | ^~~~~~~~~~~~~~~ win_serialport_impl.c:48:55: warning: function '_rb_win32_fail' could be declared with attribute 'noreturn' [-Wmissing-noreturn] 48 | static void _rb_win32_fail(const char *function_call) { | ^ --- ext/native/win_serialport_impl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/native/win_serialport_impl.c b/ext/native/win_serialport_impl.c index 2b7abe6..1f1037d 100644 --- a/ext/native/win_serialport_impl.c +++ b/ext/native/win_serialport_impl.c @@ -45,13 +45,13 @@ static HANDLE get_handle_helper(VALUE io) } /* hack to work around the fact that Ruby doesn't use GetLastError? */ -static void _rb_win32_fail(const char *function_call) { +static NORETURN( void _rb_win32_fail(const char *function_call) { rb_raise( rb_eRuntimeError, - "%s failed: GetLastError returns %d", + "%s failed: GetLastError returns %lu", function_call, GetLastError( ) ); -} +}) VALUE RB_SERIAL_EXPORT sp_create_impl(VALUE class, VALUE _port) { From 2fe38c17140d0c055eae698f23dc886076c60d07 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 09:56:57 +0200 Subject: [PATCH 18/21] CI: remove copy'n'paste mistake --- .github/workflows/ci.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 823f4f9..3f8dbc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,8 +20,6 @@ jobs: name: build gem runs-on: ubuntu-latest - env: - PLATFORM: ${{ matrix.platform }} steps: - uses: actions/checkout@v4 @@ -37,7 +35,7 @@ jobs: - name: Upload binary gem uses: actions/upload-artifact@v4 with: - name: gem-${{ matrix.platform }} + name: gem path: pkg/*-*.gem job_test_native: @@ -87,11 +85,11 @@ jobs: with: ruby-version: ${{ matrix.ruby }} - run: ruby --version - - name: Download gem-${{matrix.platform}} + - name: Download gem uses: actions/download-artifact@v4 with: - name: gem-${{ matrix.platform }} - - name: Install gem-${{matrix.platform}} + name: gem + - name: Install gem run: gem install --local *.gem --verbose - name: Run tests run: | From 6dead1d1dc2f4233181b6221f73cc24cdba49bf2 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 10:01:04 +0200 Subject: [PATCH 19/21] Update CI badge icon to Github --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ede1115..f5f8bfc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ruby/SerialPort -[![Build Status](https://travis-ci.org/hparra/ruby-serialport.png?branch=v1.2.2)](https://travis-ci.org/hparra/ruby-serialport) +[![CI](https://github.com/larskanis/ruby-serialport/actions/workflows/ci.yml/badge.svg)](https://github.com/larskanis/ruby-serialport/actions/workflows/ci.yml) ## Description From db0329eec1502983afaa639bc173e634564e8b75 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 10:08:39 +0200 Subject: [PATCH 20/21] Remove unused MANIFEST file --- MANIFEST | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 MANIFEST diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 2566ee1..0000000 --- a/MANIFEST +++ /dev/null @@ -1,12 +0,0 @@ -CHANGELOG -MANIFEST -README.md -Rakefile -serialport.gemspec -ext/native/extconf.rb -ext/native/posix_serialport_impl.c -ext/native/serialport.c -ext/native/serialport.h -ext/native/win_serialport_impl.c -lib/serialport.rb -test/miniterm.rb \ No newline at end of file From cf408f9a30893ab167d2e3d58cfaecf91c515521 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 16 Jun 2025 10:45:56 +0200 Subject: [PATCH 21/21] Add CHANGELOG entries for 1.3.2 and 1.4.0 --- CHANGELOG | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index cc7cc6b..44e499e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,14 @@ +1.4.0 => 16-06-2025: [FIXED] Fix compatibility with ruby-3.4. [#79](https://github.com/hparra/ruby-serialport/pull/79) + [FIXED] Replace ancient K&R function declarations by ANSI style. + [FIXED] Fixed various compiler warnings. + [FIXED] Avoid deprecated access to fptr->fd + [CHANGED] New repository link and add Lars Kanis as new author. + [CHANGED] Move CI from Travis to Github + [CHANGED] Use autoload for SerialPort::VERSION + [REMOVED] Remove compatibility to ruby < 2.5 + +1.3.2 => 29-09-2021: [FIXED] Remove calls to rb_secure because it is deprecated and removed in Ruby 3. + 1.3.1 => 07/26/2014: [FIXED] Ruby 2.2 support [NEW] UNIX MARK/SPACE parity (CMSPAR) support