Hello,
I want to add virtual serial ports to a macOS VM (host = Sonoma, guest = Sonoma).
Here is what I tried so far:
option 1
I create a VZVirtioConsoleDeviceConfiguration
and I add a port to it, with a VZFileHandleSerialPortAttachment
connected to two pipes:
let consoleDeviceConfiguration = VZVirtioConsoleDeviceConfiguration()
let guestPort = VZVirtioConsolePortConfiguration()
guestPort.isConsole = false
guestPort.name = "myserialport"
let guestToHostPipe = Pipe()
let hostToGuestPipe = Pipe()
guestPort.attachment = VZFileHandleSerialPortAttachment(
fileHandleForReading: hostToGuestPipe.fileHandleForReading,
fileHandleForWriting: guestToHostPipe.fileHandleForWriting
)
consoleDeviceConfiguration.ports[0] = guestPort
// config is my VZVirtualMachineConfiguration
config.consoleDevices = [consoleDeviceConfiguration]
Then after the VZVirtualMachine
is instantiated, I get the runtime VZVirtioConsoleDevice
for my device and I set my service as its delegate.
In the guest system, the device is created with the expected name (/dev/cu.myserialport)
When I open it (e.g. screen /dev/cu.myserialport 9600),
the consoleDevice(_:,didOpen:)
delegate method is called as expected. Then I start sending data to hostToGuestPipe.fileHandleForWriting
, but I get nothing in my guest system.
option 2
Instead of using config.consoleDevices,
I add a VZVirtioConsoleDeviceSerialPortConfiguration
to config.serialPorts
and I use the same scheme as above with a VZFileHandleSerialPortAttachment
and two pipes.
It works, but:
- I can't find a way to rename the devices
(/dev/cu.virtio,
/dev/cu.virtio1,
etc) - I can't detect when the endpoint is opened/closed.
Am I missing something?