Hi:
1.
it just binding rule... if want to implements some OOB feature, it
should be write a gobject base class
you can see https://wiki.gnome.org/Projects/Vala/LegacyBindings for
details...
2.
i will maintain the binding...
because of i have written a enumerator interface that need the
library support...
there have two choices..
1) i delete the interface
2) as the suggestion by Peter, the library add new function to
slove this
when these finish, i will publish the binding to vala's team...
you can just add a promptfor library's users that there is a vala's
binding for it :)
在 2014/11/3 7:12, Martin Ling 写道:
> Hi,
>
> See my previous mail regarding the libserialport patch.
>
> About the Vala binding:
>
> I'm not very familiar with the language or with vapi files - I know of
> Vala and I like the idea of it, but have yet to use it for a project. So
> excuse my ignorance in the following comments:
>
> Firstly one comment reading through is that I note you have all methods
> returning a Return enum. Is it possible to implement these as exceptions
> instead, by declaring Return as an errordomain rather than an enum? By
> my understanding of the documentation, this would allow writing
> libserialport calls within a try/catch block rather than having to check
> the result of each one.
>
> Secondly, what should be done with this file? Should we integrate it
> into the libserialport repository or is there somewhere else that makes
> sense for it to be maintained?
>
> Regards,
>
>
> Martin
>
> On Fri, Oct 31, 2014 at 06:01:57PM +0800, Matrix wrote:
>> Hi:
>>
>> the attatchment is vala's bingding vapi file and a patch which
>> make the library support vala's iterator for ports list...
>>
>> best regards...
>> using GLib;
>>
>> [CCode (lower_case_cprefix = "", cheader_filename = "libserialport.h")]
>> namespace LibSerialPort
>> {
>> [CCode (cname = "int", cprefix = "SP_", has_type_id = "false")]
>> public enum Return
>> {
>> OK,
>> ERR_ARG,
>> ERR_FAIL,
>> ERR_MEM,
>> ERR_SUPP
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_PARITY_", has_type_id = "false")]
>> public enum Parity
>> {
>> INVALID,
>> NONE,
>> ODD,
>> EVEN,
>> MARK,
>> SPACE
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_RTS_", has_type_id = "false")]
>> public enum Rts
>> {
>> INVALID,
>> OFF,
>> ON,
>> FLOW_CONTROL
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_CTS_", has_type_id = "false")]
>> public enum Cts
>> {
>> INVALID,
>> IGNORE,
>> FLOW_CONTROL
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_DTR_", has_type_id = "false")]
>> public enum Dtr
>> {
>> INVALID,
>> OFF,
>> ON,
>> FLOW_CONTROL
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_DSR_", has_type_id = "false")]
>> public enum Dsr
>> {
>> INVALID,
>> IGNORE,
>> FLOW_CONTROL
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_XONXOFF_", has_type_id = "false")]
>> public enum XonXoff
>> {
>> INVALID,
>> DISABLED,
>> IN,
>> OUT,
>> INOUT
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_FLOWCONTROL_", has_type_id =
>> "false")]
>> public enum FlowControl
>> {
>> NONE,
>> XONXOFF,
>> RTSCTS,
>> DTRDSR
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_MODE_", has_type_id = "false")]
>> public enum OpenMode
>> {
>> READ,
>> WRITE,
>> READ_WRITE
>> }
>>
>> [CCode (cname = "int", cprefix = "SP_EVENT_", has_type_id = "false")]
>> public enum EventMask
>> {
>> RX_READY,
>> TX_READY,
>> ERROR
>> }
>>
>> [CCode (cname = "enum sp_signal", cprefix = "SP_SIG_", has_type_id =
>> "false")]
>> public enum Signal
>> {
>> CTS,
>> DSR,
>> DCD,
>> RI
>> }
>>
>> [CCode (cname = "enum sp_transport", cprefix = "SP_TRANSPORT_",
>> has_type_id = "false")]
>> public enum Transport
>> {
>> NATIVE,
>> USB,
>> BLUETOOTH
>> }
>>
>> [CCode (cname = "struct sp_port_config", free_function =
>> "sp_free_config", has_type_id = "false")]
>> [Compact]
>> public class Config
>> {
>> [CCode (cname = "sp_new_config", has_type_id = "false")]
>> public static Return @new(out Config? config);
>> [CCode (cname = "sp_get_config_baudrate", has_type_id = "false")]
>> public Return get_baudrate(out int baudrate);
>> [CCode (cname = "sp_set_config_baudrate", has_type_id = "false")]
>> public Return set_baudrate(int baudrate);
>> [CCode (cname = "sp_get_config_bits", has_type_id = "false")]
>> public Return get_bits(out int bits);
>> [CCode (cname = "sp_set_config_bits", has_type_id = "false")]
>> public Return set_bits(int bits);
>> [CCode (cname = "sp_get_config_stopbits", has_type_id = "false")]
>> public Return get_stopbits(out int stopbits);
>> [CCode (cname = "sp_set_config_stopbits", has_type_id = "false")]
>> public Return set_stopbits(int stopbits);
>> [CCode (cname = "sp_get_config_parity", has_type_id = "false")]
>> public Return get_parity(out Parity parity);
>> [CCode (cname = "sp_set_config_parity", has_type_id = "false")]
>> public Return set_parity(Parity parity);
>> [CCode (cname = "sp_get_config_rts", has_type_id = "false")]
>> public Return get_rts(out Rts rts);
>> [CCode (cname = "sp_set_config_rts", has_type_id = "false")]
>> public Return set_rts(Rts rts);
>> [CCode (cname = "sp_get_config_cts", has_type_id = "false")]
>> public Return get_cts(out Cts cts);
>> [CCode (cname = "sp_set_config_cts", has_type_id = "false")]
>> public Return set_cts(Cts cts);
>> [CCode (cname = "sp_get_config_dtr", has_type_id = "false")]
>> public Return get_dtr(out Dtr dtr);
>> [CCode (cname = "sp_set_config_dtr", has_type_id = "false")]
>> public Return set_dtr(Dtr dtr);
>> [CCode (cname = "sp_get_config_dsr", has_type_id = "false")]
>> public Return get_dsr(out Dsr dsr);
>> [CCode (cname = "sp_set_config_dsr", has_type_id = "false")]
>> public Return set_dsr(Dsr xonxoff);
>> [CCode (cname = "sp_get_config_xon_xoff", has_type_id = "false")]
>> public Return get_xonxoff(out XonXoff xonxoff);
>> [CCode (cname = "sp_set_config_xon_xoff", has_type_id = "false")]
>> public Return set_xonxoff(XonXoff xonxoff);
>> [CCode (cname = "sp_set_config_flowcontrol", has_type_id = "false")]
>> public Return set_flowcontrol(FlowControl flowcontrol);
>> }
>>
>> [CCode (cname = "struct sp_event_set", free_function =
>> "sp_free_event_set", has_type_id = "false")]
>> [Compact]
>> public class EventSet
>> {
>> [CCode (cname = "sp_new_event_set", has_type_id = "false")]
>> public static Return @new(out EventSet? event_set);
>> [CCode (cname = "sp_add_port_events", has_type_id = "false")]
>> public Return add_port(Port port, EventMask mask);
>> [CCode (cname = "sp_wait", has_type_id = "false")]
>> public Return wait(uint timeout = 0);
>> }
>>
>> [CCode (cname = "struct sp_port", free_function = "sp_free_port",
>> has_type_id = "false")]
>> [Compact]
>> public class Port
>> {
>> [CCode (cname = "sp_get_port_by_name", has_type_id = "false")]
>> public static Return new_by_name(string name, out Port? port);
>> [CCode (cname = "sp_list_ports", has_type_id = "false")]
>> public static int _enum ([CCode (array_length = false)] out Port[]
>> a);
>> public static Port[] @enum ()
>> {
>> Port[] temp;
>> var len = _enum (out temp);
>> temp.length = len;
>> return (owned) temp;
>> }
>> [CCode (cname = "sp_open", has_type_id = "false")]
>> public Return open(OpenMode mode);
>> [CCode (cname = "sp_close", has_type_id = "false")]
>> public Return close();
>> [CCode (cname = "sp_get_port_transport", has_type_id = "false")]
>> public Transport get_transport();
>> [CCode (cname = "sp_get_port_usb_bus_address", has_type_id =
>> "false")]
>> public Return get_usb_bus_address(out int usb_bus, out int
>> usb_address);
>> [CCode (cname = "sp_get_port_usb_vid_pid", has_type_id = "false")]
>> public Return get_usb_vid_pid(out int usb_vid, out int usb_pid);
>> [CCode (cname = "sp_get_port_usb_manufacturer", has_type_id =
>> "false")]
>> public unowned string get_usb_manufacturer();
>> [CCode (cname = "sp_get_port_usb_product", has_type_id = "false")]
>> public unowned string get_usb_product();
>> [CCode (cname = "sp_get_port_usb_serial", has_type_id = "false")]
>> public unowned string get_usb_serial();
>> [CCode (cname = "sp_get_port_bluetooth_address", has_type_id =
>> "false")]
>> public unowned string get_bluetooth_address();
>> [CCode (cname = "sp_get_port_handle", has_type_id = "false")]
>> public Return get_fd(out int fd);
>> [CCode (cname = "sp_get_port_name", has_type_id = "false")]
>> public unowned string name();
>> [CCode (cname = "sp_get_config", has_type_id = "false")]
>> public Return get_config(Config config);
>> [CCode (cname = "sp_set_config", has_type_id = "false")]
>> public Return set_config(Config config);
>> [CCode (cname = "sp_set_baudrate", has_type_id = "false")]
>> public Return set_baudrate(int baudrate);
>> [CCode (cname = "sp_set_bits", has_type_id = "false")]
>> public Return set_bits(int bits);
>> [CCode (cname = "sp_set_parity", has_type_id = "false")]
>> public Return set_parity(Parity parity);
>> [CCode (cname = "sp_set_stopbits", has_type_id = "false")]
>> public Return set_stopbits(int stopbits);
>> [CCode (cname = "sp_set_rts", has_type_id = "false")]
>> public Return set_rts(Rts rts);
>> [CCode (cname = "sp_set_cts", has_type_id = "false")]
>> public Return set_cts(Cts cts);
>> [CCode (cname = "sp_set_dtr", has_type_id = "false")]
>> public Return set_dtr(Dtr dtr);
>> [CCode (cname = "sp_set_dsr", has_type_id = "false")]
>> public Return set_dsr(Dsr dsr);
>> [CCode (cname = "sp_set_xon_xoff", has_type_id = "false")]
>> public Return set_xon_xoff(XonXoff xon_xoff);
>> [CCode (cname = "sp_set_flowcontrol", has_type_id = "false")]
>> public Return set_flowcontrol(FlowControl flowControl);
>> [CCode (cname = "sp_blocking_read", has_type_id = "false")]
>> public Return blocking_read(uint8[] buffer, uint timeout);
>> [CCode (cname = "sp_nonblocking_read", has_type_id = "false")]
>> public Return nonblocking_read(uint8[] buffer);
>> [CCode (cname = "sp_blocking_write", has_type_id = "false")]
>> public Return blocking_write(uint8[] buffer, uint timeout);
>> [CCode (cname = "sp_nonblocking_write", has_type_id = "false")]
>> public Return nonblocking_write(uint8[] buffer);
>> [CCode (cname = "sp_input_waiting", has_type_id = "false")]
>> public Return input_waiting();
>> [CCode (cname = "sp_output_waiting", has_type_id = "false")]
>> public Return output_waiting();
>> [CCode (cname = "sp_get_signals", has_type_id = "false")]
>> public Return get_signal(out Signal signals);
>> [CCode (cname = "sp_flush", has_type_id = "false")]
>> public Return flush(int mode);
>> [CCode (cname = "sp_drain", has_type_id = "false")]
>> public Return drain();
>> [CCode (cname = "sp_start_break", has_type_id = "false")]
>> public Return start_break();
>> [CCode (cname = "sp_end_break", has_type_id = "false")]
>> public Return end_break();
>> }
>> }
>> diff -rupN libserialport/linux.c libserialport_new/linux.c
>> --- libserialport/linux.c 2014-10-31 15:25:43.261039272 +0800
>> +++ libserialport_new/linux.c 2014-10-31 16:28:34.493049124 +0800
>> @@ -169,6 +169,7 @@ SP_PRIV enum sp_return list_ports(struct
>> int len, fd;
>> DIR *dir;
>> int ret = SP_OK;
>> + int count = 0;
>>
>> DEBUG("Enumerating tty devices");
>> if (!(dir = opendir("/sys/class/tty")))
>> @@ -215,8 +216,11 @@ SP_PRIV enum sp_return list_ports(struct
>> SET_ERROR(ret, SP_ERR_MEM, "list append failed");
>> break;
>> }
>> +
>> + count++;
>> }
>> +
>> closedir(dir);
>>
>> - return ret;
>> + return (count > 0 ? count : ret);
>> }
>> diff -rupN libserialport/serialport.c libserialport_new/serialport.c
>> --- libserialport/serialport.c 2014-10-31 15:25:43.261039272 +0800
>> +++ libserialport_new/serialport.c 2014-10-31 16:34:58.553050127 +0800
>> @@ -337,15 +337,15 @@ SP_API enum sp_return sp_list_ports(stru
>> #endif
>>
>> switch (ret) {
>> - case SP_OK:
>> - *list_ptr = list;
>> - RETURN_OK();
>> case SP_ERR_SUPP:
>> DEBUG_ERROR(SP_ERR_SUPP, "Enumeration not supported on this
>> platform");
>> default:
>> - if (list)
>> + if(ret > 0) {
>> + *list_ptr = list;
>> + } else if (list) {
>> sp_free_port_list(list);
>> - *list_ptr = NULL;
>> + *list_ptr = NULL;
>> + }
>> return ret;
>> }
>> }
>> diff -rupN libserialport/windows.c libserialport_new/windows.c
>> --- libserialport/windows.c 2014-10-31 15:25:43.261039272 +0800
>> +++ libserialport_new/windows.c 2014-10-31 17:08:50.953055437 +0800
>> @@ -533,5 +533,5 @@ out_close:
>> RegCloseKey(key);
>> out_done:
>>
>> - return ret;
>> + return (index > 0 ? index : ret);
>> }
>> ------------------------------------------------------------------------------
>> _______________________________________________
>> sigrok-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/sigrok-devel
>
>
------------------------------------------------------------------------------
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel