@@ -133,6 +133,18 @@ func (p *Port) Flush() error {
133133 return purgeComm (p .fd )
134134}
135135
136+ // SendBreak sends a break (bus low value) for a given duration.
137+ // In POSIX and linux implementations the default behavior on zero duration
138+ // is to send at least 0.25 seconds and not more than 0.5 seconds.
139+ // To be compatible to linux and unix behavior we use 0.25 seconds
140+ // as duration if a duration of zero is given.
141+ func (p * Port ) SendBreak (d time.Duration ) error {
142+ if d .Milliseconds () == 0 {
143+ d = 250 * time .Millisecond
144+ }
145+ return sendCommBread (p .fd , d )
146+ }
147+
136148var (
137149 nSetCommState ,
138150 nSetCommTimeouts ,
@@ -142,6 +154,8 @@ var (
142154 nCreateEvent ,
143155 nResetEvent ,
144156 nPurgeComm ,
157+ nSetCommBreak ,
158+ nClearCommBreak ,
145159 nFlushFileBuffers uintptr
146160)
147161
@@ -160,6 +174,8 @@ func init() {
160174 nCreateEvent = getProcAddr (k32 , "CreateEventW" )
161175 nResetEvent = getProcAddr (k32 , "ResetEvent" )
162176 nPurgeComm = getProcAddr (k32 , "PurgeComm" )
177+ nSetCommBreak = getProcAddr (k32 , "SetCommBreak" )
178+ nClearCommBreak = getProcAddr (k32 , "ClearCommBreak" )
163179 nFlushFileBuffers = getProcAddr (k32 , "FlushFileBuffers" )
164180}
165181
@@ -303,6 +319,19 @@ func purgeComm(h syscall.Handle) error {
303319 return nil
304320}
305321
322+ func sendCommBreak (h syscall.Hande , d time.duration ) error {
323+ r , _ , err := syscall .Syscall (nSetCommBreak , 1 , uintptr (h ), 0 , 0 )
324+ if r == 0 {
325+ return err
326+ }
327+ time .Sleep (d )
328+ r , _ , err = syscall .Syscall (nClearCommBreak , 1 , uintptr (h ), 0 , 0 )
329+ if r == 0 {
330+ return err
331+ }
332+ return nil
333+ }
334+
306335func newOverlapped () (* syscall.Overlapped , error ) {
307336 var overlapped syscall.Overlapped
308337 r , _ , err := syscall .Syscall6 (nCreateEvent , 4 , 0 , 1 , 0 , 0 , 0 , 0 )
0 commit comments