Any way to get this to work with linux versions on a pi?
Announcement
Collapse
No announcement yet.
Linux love?
Collapse
X
-
I am also after this. I know Rien is not a Linux guy, but read with interest how kkkk got Rien's Harmonyadapter plugin to work on linux (http://forums.homeseer.com/showthread.php?t=172174). I thought about trying to go down that path. I expect that there might be an issue with Serial port control?
On a separate note, I saw that Home Assistant has a Caddx plugin with sources up on Github:
https://github.com/kk7ds/pynx584
I haven't played with it yet, but wondered if it could provide any insights.
-
Hi,
The current code I use in the plugin (for windows) is
Code:Public Function ComOpen(ByRef port As String) As Boolean Log("Plugin: " & IFACE_NAME & " Entering Com Open module", LogType.LOG_TYPE_INFO) If port.Trim = "0" Then PluginErrors += "<br />Port 0 is an invalid port" Return False End If opened = False errorCount = 0 Dim BaudRate As String = hs.GetINISetting("Settings", "Baudrate", "9600", INIFILE) Dim strPort As String = "COM" & port serialPort = New SerialPort(strPort, BaudRate, Parity.None, 8, StopBits.One) serialPort.Handshake = Handshake.None serialPort.NewLine = vbCr ''serialPort.ReadTimeout = 10000 serialPort.WriteTimeout = 10000 Try serialPort.Open() If serialPort.IsOpen Then readThread = New Threading.Thread(AddressOf ComRxLine) 'GC.SuppressFinalize(port) 'added because of .NET bug mentioned by HS board opened = True readThread.Start() gComConnected = True Log("Plugin: " & IFACE_NAME & " Com port " & strPort & " Opened", LogType.LOG_TYPE_INFO) Log("Plugin: " & IFACE_NAME & " Finished Com Open module", LogType.LOG_TYPE_INFO) Return opened Else gComConnected = False opened = False End If Catch ex As Exception Log("Plugin: " & IFACE_NAME & "Error in Com Open module" & ex.Message, LogType.LOG_TYPE_ERROR) PluginErrors += "<br /> Failed to open communications port = " & port gComConnected = False ComClose() opened = False Return False End Try Return (0) End Function Public Sub ComClose() Log("Plugin: " & IFACE_NAME & " Entering Com close module", LogType.LOG_TYPE_INFO) If opened = True Then opened = False Try gComConnected = False If readThread.IsAlive Then readThread.Join(8000) Else Log("Plugin: " & IFACE_NAME & " Port thread isn't alive. Closing anyway", LogType.LOG_TYPE_INFO) End If serialPort.Close() Log("Plugin: " & IFACE_NAME & " Closed Com port", LogType.LOG_TYPE_INFO) Catch ex As Exception 'An unexpected exception was thrown Log("Plugin: " & IFACE_NAME & "Error in Com close module" & ex.Message, LogType.LOG_TYPE_ERROR) End Try End If End Sub
Regards,
Rien du Pre
The Netherlands
Using:
Homeseer PRO latest HS4 BETA on a Raspberry
Plugin's:
RFXCOM, mcsMQTT, Z-Wave
Comment
-
I am not the right guy for this, but on initial read I see this:
Port = "COM"+ strPort.
I think on linux, you get ports like "/dev/ttyS0" rather than "COM1". So I think you need to pick up the full port name from the INI file. Enumerating ports doesn't seem to work well (http://stackoverflow.com/questions/4...iple-platforms)
Older documentation suggests there may be issues reading as well (http://www.mono-project.com/archived...#related-links). But I am not sure.
Comment
-
Originally posted by Rien du Pre View PostHi,
The current code I use in the plugin (for windows) is
Code:Public Function ComOpen(ByRef port As String) As Boolean Log("Plugin: " & IFACE_NAME & " Entering Com Open module", LogType.LOG_TYPE_INFO) If port.Trim = "0" Then PluginErrors += "<br />Port 0 is an invalid port" Return False End If opened = False errorCount = 0 Dim BaudRate As String = hs.GetINISetting("Settings", "Baudrate", "9600", INIFILE) Dim strPort As String = "COM" & port serialPort = New SerialPort(strPort, BaudRate, Parity.None, 8, StopBits.One) serialPort.Handshake = Handshake.None serialPort.NewLine = vbCr ''serialPort.ReadTimeout = 10000 serialPort.WriteTimeout = 10000 Try serialPort.Open() If serialPort.IsOpen Then readThread = New Threading.Thread(AddressOf ComRxLine) 'GC.SuppressFinalize(port) 'added because of .NET bug mentioned by HS board opened = True readThread.Start() gComConnected = True Log("Plugin: " & IFACE_NAME & " Com port " & strPort & " Opened", LogType.LOG_TYPE_INFO) Log("Plugin: " & IFACE_NAME & " Finished Com Open module", LogType.LOG_TYPE_INFO) Return opened Else gComConnected = False opened = False End If Catch ex As Exception Log("Plugin: " & IFACE_NAME & "Error in Com Open module" & ex.Message, LogType.LOG_TYPE_ERROR) PluginErrors += "<br /> Failed to open communications port = " & port gComConnected = False ComClose() opened = False Return False End Try Return (0) End Function Public Sub ComClose() Log("Plugin: " & IFACE_NAME & " Entering Com close module", LogType.LOG_TYPE_INFO) If opened = True Then opened = False Try gComConnected = False If readThread.IsAlive Then readThread.Join(8000) Else Log("Plugin: " & IFACE_NAME & " Port thread isn't alive. Closing anyway", LogType.LOG_TYPE_INFO) End If serialPort.Close() Log("Plugin: " & IFACE_NAME & " Closed Com port", LogType.LOG_TYPE_INFO) Catch ex As Exception 'An unexpected exception was thrown Log("Plugin: " & IFACE_NAME & "Error in Com close module" & ex.Message, LogType.LOG_TYPE_ERROR) End Try End If End Sub
For serial comms (IP is different) you need to address the Comport by changing it to a string. I do this by retrieving all of the valid ports "SerialPort.GetPortNames()" and displaying the results in a dropdown box for the user. That way they can't enter a bogus port and on Linux (aka mono) it will retrieve appropriate strings for you to use.
I can send you the Concord code which was originally the Caddx code once upon a time if you want. It also has IP functionality as well as serial ports.
Z
Comment
-
Thank you "askme" and "vasrc" for you help and input on this thread. Hope we can get this this moving in the right direction with everyone's help.
Thanks Again.Last edited by integlikewhoa; October 11, 2016, 01:00 PM.
Comment
-
What you should do is make a call get the available ports, on Linux, this will get the proper port names as they odd like "USB0". Here is our function to get the names. You may not care about the Linux conditional code below as its for Z-Wave so you can just remove it.
Code:Function GetPortNamesWrapper() As String() Dim MyPorts(0) As String Try MyPorts = System.IO.Ports.SerialPort.GetPortNames ' get rid of "ttyS*, not real COM ports, TODO #If Linux Then ' check for /dev/ttyACM0, this is the UZB z-wave stick and MONO does not pick it from GetPortNames (on the SEL) For i As Integer = 0 To 9 Dim pname As String = "/dev/ttyACM" & i.ToString If File.Exists(pname) And Not MyPorts.Contains(pname) Then ReDim Preserve MyPorts(MyPorts.Length) MyPorts(MyPorts.Length - 1) = pname End If Next #End If Catch ex As Exception End Try Return MyPorts End Function
Originally posted by Rien du Pre View PostHi,
The current code I use in the plugin (for windows) is
Code:Public Function ComOpen(ByRef port As String) As Boolean Log("Plugin: " & IFACE_NAME & " Entering Com Open module", LogType.LOG_TYPE_INFO) If port.Trim = "0" Then PluginErrors += "<br />Port 0 is an invalid port" Return False End If opened = False errorCount = 0 Dim BaudRate As String = hs.GetINISetting("Settings", "Baudrate", "9600", INIFILE) Dim strPort As String = "COM" & port serialPort = New SerialPort(strPort, BaudRate, Parity.None, 8, StopBits.One) serialPort.Handshake = Handshake.None serialPort.NewLine = vbCr ''serialPort.ReadTimeout = 10000 serialPort.WriteTimeout = 10000 Try serialPort.Open() If serialPort.IsOpen Then readThread = New Threading.Thread(AddressOf ComRxLine) 'GC.SuppressFinalize(port) 'added because of .NET bug mentioned by HS board opened = True readThread.Start() gComConnected = True Log("Plugin: " & IFACE_NAME & " Com port " & strPort & " Opened", LogType.LOG_TYPE_INFO) Log("Plugin: " & IFACE_NAME & " Finished Com Open module", LogType.LOG_TYPE_INFO) Return opened Else gComConnected = False opened = False End If Catch ex As Exception Log("Plugin: " & IFACE_NAME & "Error in Com Open module" & ex.Message, LogType.LOG_TYPE_ERROR) PluginErrors += "<br /> Failed to open communications port = " & port gComConnected = False ComClose() opened = False Return False End Try Return (0) End Function Public Sub ComClose() Log("Plugin: " & IFACE_NAME & " Entering Com close module", LogType.LOG_TYPE_INFO) If opened = True Then opened = False Try gComConnected = False If readThread.IsAlive Then readThread.Join(8000) Else Log("Plugin: " & IFACE_NAME & " Port thread isn't alive. Closing anyway", LogType.LOG_TYPE_INFO) End If serialPort.Close() Log("Plugin: " & IFACE_NAME & " Closed Com port", LogType.LOG_TYPE_INFO) Catch ex As Exception 'An unexpected exception was thrown Log("Plugin: " & IFACE_NAME & "Error in Com close module" & ex.Message, LogType.LOG_TYPE_ERROR) End Try End If End Sub
Comment
-
I will also post our code that displays a drop list of serial ports in case it helps with your UI:
Code:Dim SPList As New clsJQuery.jqDropList("COMPort_" & ISet.Unique, Me.PageName, True) If Not ISet.API Is Nothing Then If ISet.API.InitCOM Then SPList.enabled = False End If End If SPList.label = "Serial Port:" SPList.AddItem(" ", "", IIf(String.IsNullOrEmpty(ISet.COMPort.Trim), True, False)) For Each s As String In GetPortNamesWrapper() If s Is Nothing Then Continue For If String.IsNullOrEmpty(s.Trim) Then Continue For Sel = False If s.Trim.ToUpper = ISet.COMPort.Trim.ToUpper Then Sel = True SPList.AddItem(s, s, Sel) Next STC.Append(SPList.Build)
Comment
-
Originally posted by vasrc View PostFor Linux you have to address file slashes and Comport names. I use a variable called "isLinux" (If hs.GetOSType() = 1 Then isLinux = True) to trigger the changes.
For serial comms (IP is different) you need to address the Comport by changing it to a string. I do this by retrieving all of the valid ports "SerialPort.GetPortNames()" and displaying the results in a dropdown box for the user. That way they can't enter a bogus port and on Linux (aka mono) it will retrieve appropriate strings for you to use.
I can send you the Concord code which was originally the Caddx code once upon a time if you want. It also has IP functionality as well as serial ports.
Z
With the Concord code starting from the same base, I suspect it will be a wealth of info to double check against for other little gremlins as well. Great offer!
Comment
Comment