void SerialWindow::MenusBeginning() { // remove all items from the menu while(fConnectionMenu->RemoveItem(0L)); // fill it with the (updated) serial port list BSerialPort serialPort; int deviceCount = serialPort.CountDevices(); for(int i = 0; i < deviceCount; i++) { char buffer[256]; serialPort.GetDeviceName(i, buffer, 256); BMessage* message = new BMessage(kMsgOpenPort); message->AddString("port name", buffer); BMenuItem* portItem = new BMenuItem(buffer, message); portItem->SetTarget(be_app); fConnectionMenu->AddItem(portItem); } if (deviceCount > 0) { fConnectionMenu->AddSeparatorItem(); BMenuItem* disconnect = new BMenuItem("Disconnect", new BMessage(kMsgOpenPort), 'Z', B_OPTION_KEY); fConnectionMenu->AddItem(disconnect); } else { BMenuItem* noDevices = new BMenuItem("<no serial port available>", NULL); noDevices->SetEnabled(false); fConnectionMenu->AddItem(noDevices); } }
/* static */ status_t MonitorControl::_InitControl(SamsungBroadcastControl& control) { BSerialPort serial; uint32 count = serial.CountDevices(); for (uint32 i = 0; i < count; i++) { char name[B_FILE_NAME_LENGTH]; if (serial.GetDeviceName(i, name, sizeof(name)) != B_OK) continue; if (control.SetTo(name) == B_OK) return B_OK; } return B_ENTRY_NOT_FOUND; }
void PrefsWindow::add_serial_names(BPopUpMenu *menu, uint32 msg) { BSerialPort *port = new BSerialPort; char name[B_PATH_NAME_LENGTH]; for (int i=0; i<port->CountDevices(); i++) { port->GetDeviceName(i, name); menu->AddItem(new BMenuItem(name, new BMessage(msg))); } if (sys_info.platform_type == B_BEBOX_PLATFORM) { BDirectory dir; BEntry entry; dir.SetTo("/dev/parallel"); if (dir.InitCheck() == B_NO_ERROR) { dir.Rewind(); while (dir.GetNextEntry(&entry) >= 0) { if (!entry.IsDirectory()) { entry.GetName(name); menu->AddItem(new BMenuItem(name, new BMessage(msg))); } } } } delete port; }