SerialConnection

Anyone get SerialConnection to work? SC.Connect returns a Boolean? No docs. No errors, just does nothing.

Look at Serial.Open, very similar. It simply opens the serial port and if successful returns true, otherwise false. Set the parameter of the port using the properties prior to opening or connecting.

I haven’t tried in 2019R2 but I use in serial.open in prior versions and it works fine and I assume (I know, I know…) that SerialConnection would be the same.

Hello, there may be some problem with the new SerialConnection (API 2.0) so maybe simply use Serial (API 1.0) like Joseph suggested.
See feedback cases:
<https://xojo.com/issue/57844>
<https://xojo.com/issue/57838>

Unfortunately, I tried to use SerialConnection the same way I was using Serial, but I haven’t been able to connect. So far I’m sticking to old Serial. The Xojo response to bug reports makes me think the way to use serial port changed in an undocumented way (the feedback case where I reported inability to connect was closed as a duplicate of the case where I reported errors in documentation). It would be helpful though if someone simply said “you’re code is wrong, wait until we fix the docs” instead of making me guess.

It’s difficult to know whether it’s your code or a bug unless you can post your code and tell us what exactly trying to do. I think people are willing to help if you can post some code for review. Sometimes a second set of eyes can be enlightening.

I meant the code posted in the mentioned above feedback cases. This works:

Serial1.SerialPort = System.SerialPort(PopupMenu1.ListIndex) If Serial1.Open Then Label1.Value = "Success" Else Label1.Value = "Failure" End If

This doesn’t work:

SerialConnection1.Device = SerialDevice.At(PopupMenu1.SelectedRowIndex) If SerialConnection1.Connect Then Label1.Value = "Success" Else Label1.Value = "Failure" End If

MacOS, Windows, real hardware, virtual port - same difference, Connect method just doesn’t connect, no error or exception.

EDIT: forgot to mention - the PopupMenu1 is populated with available serial ports during the program startup, that part works as expected.

I would look at what is getting returned by your PopupMenu and how you are populating that. It might not be what you are expecting. Also, compare the docs on:

SerialDevice

[code]’ Populate the popup menu with all of the
’ serial devices the system has installed.

For i As Integer = 0 To SerialDevice.LastIndex
PopupMenu1.AddRow(SerialDevice.At(i).Name)
Next[/code]

Versus

Serial

[code]’ Populate the popup menu with all of the
’ serial ports the system has installed.
Dim count As Integer
count = System.SerialPortCount

For i As Integer = 0 To count - 1
PopupMenu1.AddRow(System.SerialPort(i).Name)
Next[/code]

Yes, the old Serial control still works. I may be missing something simple, but SerialConnection.Connect always returns false and doesn’t connect. I’ve tried many parameters, I get no errors or exceptions, it just doesn’t open the connection. If you have got it to work a code sample would be greatly appreciated.

I was populating it with Dim Count As Integer = SerialDevice.Count - 1. In the debugger the SerialConnection1.Device looks OK (it has correct InputDriverName and OutputDriverName).

And I’ve just found out yet another bug in the documentation. An attempt to compile this code (straight from the docs):

For i As Integer = 0 To SerialDevice.LastIndex MessageBox(SerialDevice.At(i).Name) Next

results in “This item does not exist SerialDevice.LastIndex”.

Do you use try…catch e as IOException when you .connect?

I’ve tried that, but it did not raise exception.

For i As Integer = 0 To SerialDevice.LastIndex MessageBox(SerialDevice.At(i).Name) Next

Are you dragging the serial control to the window and naming it SerialDevice? SerialDevice does not exist unless you define it…

From the docs

The following code opens a serial connection. It assumes that a SerialConnection control (named "SerialConnection1 in this example) has been added to a window.

Try SerialConnection1.Connect MessageBox("The serial connection is open.") Catch error as IOException MessageBox("The serial connection could not be opened.") End Try

SerialDevice is not a control, but a replacement for System.SerialPort, it looks like it exists right from the start (see what happens if you create new empty project and add MsgBox(SerialDevice.Count.ToString) to App.Opening).

The docs are wrong here. On the plus side, the relevant feedback case was closed as “fixed”, so the next release should clear some things.

The problem is mostly fixed in the 2.1 release:

  • SerialConnection class can connect to serial port and send/receive data, but SerialConnection.Connect always return False. Replace If SerialConnection.Connect Then ... End If with Dim dummy As Boolean = SerialConnection.Connect,
  • documentation is still incorrect,

[quote=464059:@Krzysztof Mitko]The problem is mostly fixed in the 2.1 release:

  • SerialConnection class can connect to serial port and send/receive data, but SerialConnection.Connect always return False. Replace If SerialConnection.Connect Then ... End If with Dim dummy As Boolean = SerialConnection.Connect,
  • documentation is still incorrect,[/quote]

Make a bugreport plz