gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

error message list does not support the buffers interfaces

Thu Apr 23, 2015 2:11 pm

hello

I've made a programm to send a table to processing but i'have this error message "list does not support the buffers interfaces"
How can i correct this ?

this is my programm

Code: Select all

import socket
import time
import RPi.GPIO as GPIO

GPIO.setwarnings(False) 
GPIO.setmode(GPIO.BCM)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(6,GPIO.IN)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(19,GPIO.IN)
                                                                                                                                   
UDP_IP = "192.168.43.154"
UDP_PORT= 8080

listled= ["a","b","c"]


etat1=0
etat2=0

sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.sendto(str(listled),(UDP_IP,UDP_PORT))


while True:
            if(GPIO.input(6)==etat1+1 ):   #clignotant
                 etat1=a
                 GPIO.output(5,True)
                 time.sleep(0.5)
                 GPIO.output(5,False)
                 time.sleep(0.5)
            else:
              GPIO.output(5,False)

            if(GPIO.input(19)==etat2+1):  #clignotant
                 etat2=b
                 GPIO.output(13,True)
                 time.sleep(0.5)
                 GPIO.output(13,False)
                 time.sleep(0.5)
            else:
              GPIO.output(13,False)

Last edited by gaetan 22 on Thu Apr 23, 2015 9:45 pm, edited 1 time in total.

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: error message list does not support the buffers interfac

Thu Apr 23, 2015 2:17 pm

Can you post the complete error message (this should include the location, etc)

BTW, there's a possible typo. You're using both 'listled' and 'listeled' and they're not referenced anywhere else.

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Thu Apr 23, 2015 9:44 pm

i have make an error in the code with liste and list i have corrected
here the complete error message

Code: Select all

Traceback (most recent call last):
File "/home/pi/Desktop/LED+boutons.py", line 25, in <module>   
  sock.sendto(str(listled),(UDP_IP,UDP_PORT))
TypeError: 'str' does not support the buffer interface

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: error message list does not support the buffers interfac

Thu Apr 23, 2015 9:59 pm

sendto expects either a string (Python2) or bytes (Python3).

I suppose it doesn't know how to convert a list of strings "a" "b" "c" etc. into a string or bytes.

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 9:24 am

After some hours in internet I have find a programm now i have no error ,but i don't know if i have find the best solution because i used the librairy pickle and i want to see my array into processing how can i do ?

here the programm I have corrected but don't know realy if it's work because for the moment i can't see my array into processing :)

Code: Select all

import socket
import time
import RPi.GPIO as GPIO
import pickle


GPIO.setwarnings(False) 
GPIO.setmode(GPIO.BCM)
GPIO.setup(5,GPIO.OUT)
GPIO.setup(6,GPIO.IN)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(19,GPIO.IN)
                                                                                                                                   
UDP_IP = "192.168.1.52"
UDP_PORT= 8080

arr=(["a","b"])

etat1=0
etat2=0

a=etat1
b=etat2

sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.sendto(pickle.dumps(arr),(UDP_IP,UDP_PORT))

while True:
            if(GPIO.input(6)==etat1+1 ):   #clignotant
                 etat1=a
                 GPIO.output(5,True)
                 time.sleep(0.5)
                 GPIO.output(5,False)
                 time.sleep(0.5)
            else:
              GPIO.output(5,False)

            if(GPIO.input(19)==etat2+1):  #clignotant
                 etat2=b
                 GPIO.output(13,True)
                 time.sleep(0.5)
                 GPIO.output(13,False)
                 time.sleep(0.5)
            else:
              GPIO.output(13,False)

             
*I have forget to say sorry if my english is bad i come from france ;)

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 9:34 am

Why not just sock.sendto("ab",(UDP_IP,UDP_PORT))?

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 10:35 am

I don't know ! i'm maybe confused i want to send the state of my interruptor connect to my raspberry into processing and send the request by UDP

So if i send just a and b can i see if he contain a 1 or a 0

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 11:18 am

gaetan 22 wrote:I don't know ! i'm maybe confused i want to send the state of my interruptor connect to my raspberry into processing and send the request by UDP

So if i send just a and b can i see if he contain a 1 or a 0
What data do you want to send?

sock.sendto "ab" will send bytes 0x61 0x62
sock.sendto "\x01\x02" will send bytes 0x01 0x02
sock.sendto "{:c}{:c}{:c}".format(96, 123, 56) will send bytes 96, 123, 56

a=23
b=11
c=12
sock.sendto "{:c}{:c}{:c}".format(a, b, c) will send bytes 23, 11, 12

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 11:55 am

I think this is the third solution because I want to see the contents of the variable if for example "a" equals 1 .I want to recover this one is processing to make a point flashing on my screen.

can you write for me the lign " sock.sendto ....." I have to write in my programm please

thanks

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 12:04 pm

I think you want

sock.sendto("{:c}{:c}{:c}".format(a, b, c),(UDP_IP,UDP_PORT))

where variables a, b, and c contain the value you want to send.

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 12:33 pm

when i run the code the same error come back

Code: Select all

Traceback (most recent call last):
  File "/home/pi/Desktop/LED+boutons.py", line 31, in <module>
    sock.sendto("{:c}{:c}{:c}".format(a,b,c),(UDP_IP,UDP_PORT))
TypeError: 'str' does not support the buffer interface
is it necessary to import new librairy ?

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 12:45 pm

I do not understand why, but I usually use idle 3 and did a test with idle 2.7 and error have dispear .
Now I go to processing to receive my variable still long hours of work or someone may be an idea of ​​how to do?

just a last question what is the signification of {:c} ? i need to know what i going to read in processing
Last edited by gaetan 22 on Fri Apr 24, 2015 12:48 pm, edited 1 time in total.

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 12:47 pm

Are you using Python 3?

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 12:54 pm

I think i used Python 3 because on my raspberry i have idle3 but whith idle3 i have the error message not with
idle 2.7

User avatar
joan
Posts: 14959
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 1:01 pm

String handling in Python is a mess. There seems to be major changes between versions 2 and 3 but there are also changes within minor versions of 2 and 3 as well.

May I suggest you in future use the struct package and pack/unpack to encode/decode socket messages.

gaetan 22
Posts: 17
Joined: Tue Mar 24, 2015 6:55 pm
Location: France

Re: error message list does not support the buffers interfac

Fri Apr 24, 2015 1:07 pm

OKay thanks you very much joan

Return to “Troubleshooting”