@@ -59,7 +59,6 @@ def __init__(self, ip, netport, serialport="/dev/ttyAMA0", baudrate="1000000", t
5959 super (MyCobotSocket , self ).__init__ ()
6060 self .calibration_parameters = calibration_parameters
6161 self .SERVER_IP = ip
62- # 端口号
6362 self .SERVER_PORT = 9000
6463 self .sock = self .connect ()
6564 self ._write (serialport , "socket" )
@@ -68,7 +67,7 @@ def __init__(self, ip, netport, serialport="/dev/ttyAMA0", baudrate="1000000", t
6867
6968 def connect (self ):
7069 sock = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
71- sock .connect ((self .SERVER_IP , self .SERVER_PORT )) # 打开链接
70+ sock .connect ((self .SERVER_IP , self .SERVER_PORT ))
7271 return sock
7372
7473 def _mesg (self , genre , * args , ** kwargs ):
@@ -87,7 +86,6 @@ def _mesg(self, genre, *args, **kwargs):
8786 MyCobotSocket , self )._mesg (genre , * args , ** kwargs )
8887 # [254,...,255]
8988 data = self ._write (self ._flatten (real_command ), "socket" )
90-
9189 if data != b'None' :
9290 res = self ._process_received (data , genre )
9391 if genre in [
@@ -168,12 +166,42 @@ def sync_send_coords(self, coords, speed, mode, timeout=7):
168166 time .sleep (0.1 )
169167 return self
170168
171- def pub_pump (self , v ):
172- """Set GPIO output value.
169+ def set_gpio_mode (self , mode ):
170+ """Set GPIO mode
171+ Args:
172+ mode: BCM or BOARD (str)
173+ """
174+ self .calibration_parameters (gpiomode = mode )
175+ if mode == "BCM" :
176+ return self ._mesg (ProtocolCode .SET_GPIO_MODE , 0 )
177+ else :
178+ return self ._mesg (ProtocolCode .SET_GPIO_MODE , 1 )
179+
180+ def set_gpio_out (self , pin_no , mode ):
181+ """Equivalent to: GPIO.setup(pin_no, mode)
182+ Args:
183+ pin_no: (int)
184+ mode: (str) in --> GPIO.IN out --> GPIO.OUT
185+ """
186+ if mode == "in" :
187+ return self ._mesg (ProtocolCode .SET_GPIO_UP , pin_no , 0 )
188+ else :
189+ return self ._mesg (ProtocolCode .SET_GPIO_UP , pin_no , 1 )
190+
191+ def set_gpio_output (self , pin_no , state ):
192+ """Set state of GPIO pin
193+ Args:
194+ pin_no: (int)
195+ state: (int) 0 --> GPIO..HIGH 1 --> GPIO.LOW
196+ """
197+ return self ._mesg (ProtocolCode .SET_GPIO_OUTPUT , pin_no , state )
198+
199+ def get_gpio_in (self , pin_no ):
200+ """Detect state of GPIO pin
173201 Args:
174- v: Output value (int), 1 - pump close, 0 - pump open
202+ pin_no: (int)
175203 """
176- self ._write ( v , "socket" )
204+ return self ._mesg ( ProtocolCode . GET_GPIO_IN , pin_no )
177205
178206 # Other
179207 def wait (self , t ):
0 commit comments