-1

When using command: (data, addr)=mySocket.recvfrom(SIZE) to receive data that have been sent from matlab via UDP is my wave-generate program not operate while data still received and display on raspberry pi. On the contrary, if I delete it is program operate normally. This is program segment that I use:

   import time
   import pigpio
   import wavePWM
   from socket import*
   import numpy
   import numpy as np
   import pickle
   import operator
   import sys, struct
   GPIO=[2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]

   pi = pigpio.pi()
   ### receive data from simulink
   SIZE = 65535
   hostName = gethostbyname('0.0.0.0')
   mySocket = socket(AF_INET, SOCK_DGRAM)
   mySocket.bind((hostName,5002))
   repeat = True
   while repeat:
      (data, addr)=mySocket.recvfrom(SIZE)
      data1 = struct.unpack('>4d', data)
      x = np.asarray(data1)
      data2 = x.astype(numpy.int64)
      print(data2)
   if not pi.connected:
      exit(0)

   pwm = wavePWM.PWM(pi) # Use default frequency

   pwm.set_frequency(40000)

   # generate pulse with delay time when start
   pwm.set_pulse_start_and_length_in_micros(2, data2[0], 12)
   pwm.set_pulse_start_and_length_in_micros(3, data2[1], 12)
   pwm.set_pulse_start_and_length_in_micros(4, data2[2], 12)
   pwm.set_pulse_start_and_length_in_micros(5, data2[3], 12)

Wherther have a conflict between UDP and pigpio library or not? I have tried to change port and IP address but program still not work. A week ago, I have encountered with this problem but after 2 days it be solved accidentally ( I don't know reason why) and now it's happened to me again. I'm very confused about that. Please help me solve it Thanks

  • You haven't explained what the problem is. What do you expect to happen? What actually happens. I.e. which piece of code is not doing what you expect, what do you expect it to do? – joan Nov 17 '16 at 10:44
  • @joan, I want generate wave square on pins GPIO and delay time is each number in data2 array received from matlab as in code. But I don't know reasons why when I tried to give a normal array as data2=[2,3,4,5] is my program still good generate waves but when I add code segment in order to receive data2 from matlab is waves not be generate while data2 still received normally. I have tried to delete code to know place where effect to waves generation is "(data, addr)=mySocket.recvfrom(SIZE)", it have made my program not work. – Gab Nov 17 '16 at 12:17
  • Are you saying the program stops when it gets to the recvFrom line? Isn't that what you have told the program to do? – joan Nov 17 '16 at 12:21
  • Yes, when I add revfrom line is piscope not dislay waves on GPIO pins but data2 that received from matlab still display on raspberry pi normally – Gab Nov 17 '16 at 12:26
  • If you don't want the program to stop at that line then remove that line or change it to a non-blocking call. You seem to be saying that you do not understand what recvfrom does. If that is the case you need to read the documentation and look for relevant tutorials. – joan Nov 17 '16 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.