MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / drcSetupSerial

Function drcSetupSerial

wiringPi/drcSerial.c:147–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145 */
146
147int drcSetupSerial (const int pinBase, const int numPins, const char *device, const int baud)
148{
149 int fd ;
150 int ok, tries ;
151 time_t then ;
152 struct wiringPiNodeStruct *node ;
153
154 if ((fd = serialOpen (device, baud)) < 0)
155 return false ;
156
157 delay (10) ; // May need longer if it's an Uno that reboots on the open...
158
159// Flush any pending input
160
161 while (serialDataAvail (fd))
162 (void)serialGetchar (fd) ;
163
164 ok = false ;
165 for (tries = 1 ; (tries < 5) && (!ok) ; ++tries)
166 {
167 serialPutchar (fd, '@') ; // Ping
168 then = time (NULL) + 2 ;
169 while (time (NULL) < then)
170 if (serialDataAvail (fd))
171 {
172 if (serialGetchar (fd) == '@')
173 {
174 ok = true ;
175 break ;
176 }
177 }
178 }
179
180 if (!ok)
181 {
182 serialClose (fd) ;
183 return false ;
184 }
185
186 node = wiringPiNewNode (pinBase, numPins) ;
187
188 node->fd = fd ;
189 node->pinMode = myPinMode ;
190 node->pullUpDnControl = myPullUpDnControl ;
191 node->analogRead = myAnalogRead ;
192 node->digitalRead = myDigitalRead ;
193 node->digitalWrite = myDigitalWrite ;
194 node->pwmWrite = myPwmWrite ;
195
196 return true ;
197}

Callers 3

doExtensionDrcSFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 7

serialOpenFunction · 0.85
serialDataAvailFunction · 0.85
serialGetcharFunction · 0.85
serialPutcharFunction · 0.85
serialCloseFunction · 0.85
wiringPiNewNodeFunction · 0.85
delayFunction · 0.70

Tested by

no test coverage detected