Đang chuẩn bị liên kết để tải về tài liệu:
programming LEGO MINDSTORMS phần 3
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Điều này là khá hữu ích, nhưng cung cấp cho bạn hầu như không có sự linh hoạt trong cách thức hoạt động của vòng lặp. Mặc dù bạn có thể thay đổi giá trị thặng dư, hoặc thậm chí làm tăng tiêu cực, bằng cách sử dụng cơ sở Bước, vòng lặp luôn luôn hoạt động bằng cách đếm, và các kiểm tra cho dù thoát khỏi | 72 Chapter 2 The Java Communications API public CommPort getCommPort String portName int portType Win32USBPort port new Win32USBPort try if port.open portName 0 port null catch java.io.IOException ioexception port null return port In initialize above one can populate the port list IDs. Its counterpart Win32Driver added the lists for both serial and parallel ports to CommPortldentifier. Here I added the possibility of having two towers. It s a meager attempt because we don t have access to a native method that will enumerate all the towers present. Again this is not a full-fledged USB driver we re wrapping some access to the LEGO Company s native USB driver.The specific port names listed above were as provided by LEGO s SDK documentation. In theory we have all the parts in place and we add an entry to the properties file Windows Serial Driver Driver com.sun.comm.Win32Driver Windows USB Driver for Lego Mindstorms Driver rcx.comm.Win32USBDriver This should work but it doesn t. In fact Win32USBPort won t compile.Why It s because CommPort s initializer is package private all of its subclasses must reside inside the javax.comm package.This is a serious limitation because we can t just drop in a new type of port without breaking package rules.You can t deliver javax.comm. classes outside of the comm.jar because the extension would then cease to be standard. What did com.sun.comm.Win32SerialPort do to get around this limitation Technically the way around it was to have an additional abstraction between it and www.syngress.com The Java Communications API Chapter 2 73 CommPort. In that case it was able to extend javax.comm.SerialPort without a problem.That s because Java Comm supports serial and parallel ports out of the box.We would still run into the problem of having to create a javax.comm.USBPort we weren t intending to introduce generic USB port support we just want to add our customized USB port into the mix. Adding generic USB support would require changing the core .