0

#! /usr/bin/python

import socket
import struct
import sys
import os
import string

#MADDX = '225.100.100.100'
MADDX = '224.0.0.103'
RAW = False


#! /usr/bin/python

import socket
import struct
import sys

MADDX = '224.0.0.103'
ADDR = '' #bind to address? leave blank for any
DATA="414e542d534541524348204d4441502f312e310d0a3436" #the Hello ID request

import binascii
SDATA = binascii.a2b_hex(DATA) #convert to ASCII

##http://mail.python.org/pipermail/python-list/2005-December/358117.html
#bind((outgoing_if, tc_local_port))

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.bind((ADDR,1103)) #bind to any address and local port 1103
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
sock.sendto(SDATA, (MADDX, 3235)) # send to required DEST address and PORT

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('',3235)) #port 3235 is the port the thomson software responds on
mreq = struct.pack('4sl', socket.inet_aton(MADDX), socket.INADDR_ANY)

sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

if RAW == True: #if we want the RAW datastream, we just loop until keyboard interrupt
while True:
print sock.recv(1024)
else:
while True:
Dkilobyte = sock.recv(1024)
if string.find(Dkilobyte,'ANT-ID:') != -1:
for line in string.split(Dkilobyte):
if string.find(line,'ANT-ID:') != -1:
print "serial: CP" + string.strip(line,"ANT-ID:") + "\n\n"
sys.exit(0) #success! we quit

It says there is a syntax error at sock.recv(1024)

Help! using python 3.2 this script must be for 2. versions can anyone fix it and repost it plz?

Edited by daggeras008: correct something

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pyTony
0

I do not know what problem you have, the conversion with 2to3.py script did not succeed? Next time push (CODE) before pasting your code and put your imports (only once) at beginning of the code (moved those)

#! /usr/bin/python

import socket
import struct
import sys
import os
import string
import binascii

#MADDX = '225.100.100.100'
MADDX = '224.0.0.103'
RAW = False
ADDR = '' #bind to address? leave blank for any
DATA="414e542d534541524348204d4441502f312e310d0a3436" #the Hello ID request

SDATA = binascii.a2b_hex(DATA)  #convert to ASCII

##[url]http://mail.python.org/pipermail/python-list/2005-December/358117.html[/url]
#bind((outgoing_if, tc_local_port))

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.bind((ADDR,1103)) #bind to any address and local port 1103
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
sock.sendto(SDATA, (MADDX, 3235)) # send to required DEST address and PORT

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('',3235)) #port 3235 is the port the thomson software responds on
mreq = struct.pack('4sl', socket.inet_aton(MADDX), socket.INADDR_ANY)

sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

if RAW == True:  #if we want the RAW datastream, we just loop until keyboard interrupt
    while True:
        print sock.recv(1024)
else:
    while True:
        Dkilobyte = sock.recv(1024)
        if string.find(Dkilobyte,'ANT-ID:') != -1:
            for line in string.split(Dkilobyte):
                if string.find(line,'ANT-ID:') != -1:
                    print "serial: CP" + string.strip(line,"ANT-ID:") + "\n\n"
                    sys.exit(0) #success! we quit

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.