]> sigrok.org Git - libsigrok.git/blobdiff - hardware/common/scpi_tcp.c
Add udev rule for Agilent DSO1000 series.
[libsigrok.git] / hardware / common / scpi_tcp.c
index d84c7e8fa7f4dde1620d95a9a271a57bdfd7583e..af2db140661ce99c04d77f79f92872723c4de8c5 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0501
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif
+
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 
 #include <glib.h>
 #include <string.h>
 #include <unistd.h>
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#endif
 #include <errno.h>
 
-/* Message logging helpers with subsystem-specific prefix string. */
-#define LOG_PREFIX "scpi_tcp: "
-#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
-#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
-#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
-#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
-#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
+#define LOG_PREFIX "scpi_tcp"
 
 struct scpi_tcp {
        char *address;
@@ -105,9 +107,12 @@ SR_PRIV int scpi_tcp_send(void *priv, const char *command)
 {
        struct scpi_tcp *tcp = priv;
        int len, out;
+       char *terminated_command;
 
-       len = strlen(command);
-       out = send(tcp->socket, command, len, 0);
+       terminated_command = g_strdup_printf("%s\r\n", command);
+       len = strlen(terminated_command);
+       out = send(tcp->socket, terminated_command, len, 0);
+       g_free(terminated_command);
 
        if (out < 0) {
                sr_err("Send error: %s", strerror(errno));
@@ -141,7 +146,7 @@ SR_PRIV int scpi_tcp_receive(void *priv, char **scpi_response)
                return SR_ERR;
        }
 
-       response = g_string_append_len(response, buf, len);
+       response = g_string_append_len(response, buf + 4, len - 4);
 
        *scpi_response = response->str;