Changeset 6682
- Timestamp:
- 10/22/07 18:33:38
- Files:
-
- grc/trunk/src/SignalBlockDefs/Misc.py (modified) (1 diff)
- grc/trunk/src/SignalBlockDefs/SignalBlockTree.py (modified) (3 diffs)
- grc/trunk/src/SignalBlockDefs/Sinks.py (modified) (1 diff)
- grc/trunk/src/SignalBlockDefs/Sources.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
grc/trunk/src/SignalBlockDefs/Misc.py
r6659 r6682 162 162 return sb, make 163 163 164 class SerialHelper(gr.hier_block2):165 """Make the serial hier2 block."""166 def __init__(self, item_size, fd):167 """!168 SerialHelper constructor.169 @param item_size the size in bytes of the IO data stream170 @param fd the file descriptor for the serial device171 """172 #create hier block173 gr.hier_block2.__init__(174 self, 'serial',175 gr.io_signature(1, 1, item_size),176 gr.io_signature(1, 1, item_size)177 )178 #I/O blocks179 sink = gr.file_descriptor_sink(item_size, fd)180 source = gr.file_descriptor_source(item_size, fd)181 #connect182 self.connect(self, sink)183 self.connect(source, self)184 185 def Serial(sb):186 import serial, os, fcntl187 type = Enum(all_choices, 1)188 sb.add_input_socket('in', Variable(type))189 sb.add_output_socket('out', Variable(type))190 sb.add_param('Type', type, False, type=True)191 sb.add_param('Port', String('/dev/ttyS0'))192 sb.add_param('Baud Rate', Int(9600, min=0))193 sb.add_param('Byte Size', Enum([194 ('8 bits', serial.EIGHTBITS),195 ('7 bits', serial.SEVENBITS),196 ('6 bits', serial.SIXBITS),197 ('5 bits', serial.FIVEBITS),198 ]199 )200 )201 sb.add_param('Parity', Enum([202 ('None', serial.PARITY_NONE),203 ('Even', serial.PARITY_EVEN),204 ('Odd', serial.PARITY_ODD),205 ]206 )207 )208 sb.add_param('Stop Bits', Enum([209 ('1 bit', serial.STOPBITS_ONE),210 ('2 bits', serial.STOPBITS_TWO),211 ]212 )213 )214 sb.add_param('Soft Flow Control', Enum([215 ('Off', serial.XOFF),216 ('On', serial.XON),217 ]218 )219 )220 def make(fg, type, port, baudrate, bytesize, parity, stopbits, xonxoff):221 ser = serial.Serial(222 port = port.parse(),223 baudrate = baudrate.parse(),224 bytesize = bytesize.parse(),225 parity = parity.parse(),226 stopbits = stopbits.parse(),227 timeout = None,228 xonxoff = xonxoff.parse(),229 )230 fd = ser.fileno()231 fcntl.fcntl(fd, fcntl.F_SETFL, os.O_SYNC | os.O_RDWR | os.O_NOCTTY) #set blocking232 return SerialHelper(type.parse().get_num_bytes(), fd)233 return sb, make234 235 grc/trunk/src/SignalBlockDefs/SignalBlockTree.py
r6625 r6682 50 50 ('USRP Source', USRP.USRPSource), 51 51 ('USRP Dual Source', USRP.USRPDualSource), 52 ('RS232 Source', Sources.RS232Source), 52 53 ]), 53 54 ('Sinks', [ … … 59 60 ('USRP Sink', USRP.USRPSink), 60 61 ('USRP Dual Sink', USRP.USRPDualSink), 62 ('RS232 Sink', Sinks.RS232Sink), 61 63 ]), 62 64 ('Graphical Sinks', [ … … 188 190 ('Copy', Misc.Copy), 189 191 ('Tun Tap', Packet.TunTap), 190 ('Serial', Misc.Serial),191 192 ('RMS', Misc.RMS), 192 193 ('About', Misc.About), grc/trunk/src/SignalBlockDefs/Sinks.py
r6476 r6682 142 142 return sb, make 143 143 144 def RS232Sink(sb): 145 import serial, os, fcntl 146 type = Enum(all_choices, 1) 147 sb.add_input_socket('in', Variable(type)) 148 sb.add_param('Type', type, False, type=True) 149 sb.add_param('Port', String('/dev/ttyS0')) 150 sb.add_param('Baud Rate', Int(9600, min=0)) 151 sb.add_param('Byte Size', Enum([ 152 ('8 bits', serial.EIGHTBITS), 153 ('7 bits', serial.SEVENBITS), 154 ('6 bits', serial.SIXBITS), 155 ('5 bits', serial.FIVEBITS), 156 ] 157 ) 158 ) 159 sb.add_param('Parity', Enum([ 160 ('None', serial.PARITY_NONE), 161 ('Even', serial.PARITY_EVEN), 162 ('Odd', serial.PARITY_ODD), 163 ] 164 ) 165 ) 166 sb.add_param('Stop Bits', Enum([ 167 ('1 bit', serial.STOPBITS_ONE), 168 ('2 bits', serial.STOPBITS_TWO), 169 ] 170 ) 171 ) 172 sb.add_param('Soft Flow Control', Enum([ 173 ('Off', serial.XOFF), 174 ('On', serial.XON), 175 ] 176 ) 177 ) 178 def make(fg, type, port, baudrate, bytesize, parity, stopbits, xonxoff): 179 ser = serial.Serial( 180 port = port.parse(), 181 baudrate = baudrate.parse(), 182 bytesize = bytesize.parse(), 183 parity = parity.parse(), 184 stopbits = stopbits.parse(), 185 timeout = None, 186 xonxoff = xonxoff.parse(), 187 ) 188 fd = ser.fileno() 189 fcntl.fcntl(fd, fcntl.F_SETFL, os.O_SYNC | os.O_WRONLY) #set blocking, and write only 190 return gr.file_descriptor_sink(type.parse().get_num_bytes(), fd) 191 return sb, make 144 192 193 grc/trunk/src/SignalBlockDefs/Sources.py
r5992 r6682 158 158 sb.add_param('Vector Length', vlen) 159 159 return sb, lambda fg, type, addr, port, size, vlen: fcn(type.parse().get_num_bytes()*vlen.parse(), addr.parse(), port.parse(), size.parse()) 160 160 161 def RS232Source(sb): 162 import serial, os, fcntl 163 type = Enum(all_choices, 1) 164 sb.add_output_socket('out', Variable(type)) 165 sb.add_param('Type', type, False, type=True) 166 sb.add_param('Port', String('/dev/ttyS0')) 167 sb.add_param('Baud Rate', Int(9600, min=0)) 168 sb.add_param('Byte Size', Enum([ 169 ('8 bits', serial.EIGHTBITS), 170 ('7 bits', serial.SEVENBITS), 171 ('6 bits', serial.SIXBITS), 172 ('5 bits', serial.FIVEBITS), 173 ] 174 ) 175 ) 176 sb.add_param('Parity', Enum([ 177 ('None', serial.PARITY_NONE), 178 ('Even', serial.PARITY_EVEN), 179 ('Odd', serial.PARITY_ODD), 180 ] 181 ) 182 ) 183 sb.add_param('Stop Bits', Enum([ 184 ('1 bit', serial.STOPBITS_ONE), 185 ('2 bits', serial.STOPBITS_TWO), 186 ] 187 ) 188 ) 189 sb.add_param('Soft Flow Control', Enum([ 190 ('Off', serial.XOFF), 191 ('On', serial.XON), 192 ] 193 ) 194 ) 195 def make(fg, type, port, baudrate, bytesize, parity, stopbits, xonxoff): 196 ser = serial.Serial( 197 port = port.parse(), 198 baudrate = baudrate.parse(), 199 bytesize = bytesize.parse(), 200 parity = parity.parse(), 201 stopbits = stopbits.parse(), 202 timeout = None, 203 xonxoff = xonxoff.parse(), 204 ) 205 fd = ser.fileno() 206 fcntl.fcntl(fd, fcntl.F_SETFL, os.O_SYNC | os.O_RDONLY) #set blocking, and read only 207 return gr.file_descriptor_source(type.parse().get_num_bytes(), fd) 208 return sb, make 209 210
