Access serial ports through slicer extension

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Access serial ports through slicer extension

banderie@asu.edu
Hello all,

I was wondering if there was a way to access serial ports using a scripted slicer extension? I would like to be able to interface slicer with an Arduino, but pyserial is not available in the slicer environment. Is it possible to include external python libraries?

Thanks,

Barrett

--
Barrett Anderies
B.S.E. Biomedical Engineering | B.S. Mathematics
Barrett, the Honors College | Arizona State University
Phone: 480-721-9370
           [hidden email]

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Access serial ports through slicer extension

lasso2

We use Plus toolkit (www.plustoolkit.org) and SlicerIGT extension to communicate with Arduino devices in Slicer. It is somewhat more complicated than just directly connecting to the serial port, but Plus and SlicerIGT offers much more: OpenIGTLink protocol is used for connecting to a PlusServer instance anywhere on your network, many Slicer instances can communicate with the same Arduino, command execution is asynchronous (Slicer is not blocked while waiting for a command response but you can specify a callback method), you can control/collect data from many imaging and tracking devices, sensors, etc. are using the same interface.

 

Example usage:

 

# Specify OpenIGTLink connection

# Make sure a PlusServer is running on the computer the Arduino is connected to, with a similar configuration file to this:

# https://app.assembla.com/spaces/plus/subversion/source/HEAD/trunk/PlusLibData/ConfigFiles/PlusDeviceSet_Server_GenericSerial.xml

self.connectorNode = slicer.vtkMRMLIGTLConnectorNode()

self.connectorNode.SetTypeClient('127.0.0.1', 18944)

slicer.mrmlScene.AddNode(self.connectorNode)

self.connectorNode.Start()

 

# Create command

self.arduinoCmd = slicer.vtkSlicerOpenIGTLinkCommand()

self.arduinoCmd.SetCommandName('SendText')

self.arduinoCmd.SetCommandAttribute('DeviceId','SerialDevice')

self.arduinoCmd.SetCommandTimeoutSec(1.0)

 

# Send command

self.arduinoCmd.SetCommandAttribute('Text', "ThisWillBeSentThroughSerialPort")

slicer.modules.openigtlinkremote.logic().SendCommand(self.arduinoCmd, self.connectorNode.GetID())

 

# Optional: Specify a callback function to get command status/response

self.arduinoCmd.AddObserver(self.arduinoCmd.CommandCompletedEvent, self.onArduinoCmdCompleted)

# Callback function

def onArduinoCmdCompleted(self, observer, eventid):

  print(self.arduinoCmd.GetStatus())

  print(self.arduinoCmd.GetResponseMessage())

  print(self.arduinoCmd.GetResponseText())

  print(self.arduinoCmd.GetResponseXML())

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: March 26, 2017 23:48
To: SPL Slicer Devel <[hidden email]>
Subject: [slicer-devel] Access serial ports through slicer extension

 

Hello all,

 

I was wondering if there was a way to access serial ports using a scripted slicer extension? I would like to be able to interface slicer with an Arduino, but pyserial is not available in the slicer environment. Is it possible to include external python libraries?

 

Thanks,

 

Barrett


--

Barrett Anderies

B.S.E. Biomedical Engineering | B.S. Mathematics

Barrett, the Honors College | Arizona State University

Phone: 480-721-9370

           [hidden email]


_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Access serial ports through slicer extension

banderie@asu.edu
In reply to this post by banderie@asu.edu
Perfect, thank you! The interaction I need is quite basic, so this should be sufficient.

--
Barrett Anderies
B.S.E. Biomedical Engineering | B.S. Mathematics
Barrett, the Honors College | Arizona State University
Phone: 480-721-9370
           [hidden email]

On Sun, Mar 26, 2017 at 9:48 PM, Andras Lasso <[hidden email]> wrote:

We use Plus toolkit (www.plustoolkit.org) and SlicerIGT extension to communicate with Arduino devices in Slicer. It is somewhat more complicated than just directly connecting to the serial port, but Plus and SlicerIGT offers much more: OpenIGTLink protocol is used for connecting to a PlusServer instance anywhere on your network, many Slicer instances can communicate with the same Arduino, command execution is asynchronous (Slicer is not blocked while waiting for a command response but you can specify a callback method), you can control/collect data from many imaging and tracking devices, sensors, etc. are using the same interface.

 

Example usage:

 

# Specify OpenIGTLink connection

# Make sure a PlusServer is running on the computer the Arduino is connected to, with a similar configuration file to this:

# https://app.assembla.com/spaces/plus/subversion/source/HEAD/trunk/PlusLibData/ConfigFiles/PlusDeviceSet_Server_GenericSerial.xml

self.connectorNode = slicer.vtkMRMLIGTLConnectorNode()

self.connectorNode.SetTypeClient('127.0.0.1', 18944)

slicer.mrmlScene.AddNode(self.connectorNode)

self.connectorNode.Start()

 

# Create command

self.arduinoCmd = slicer.vtkSlicerOpenIGTLinkCommand()

self.arduinoCmd.SetCommandName('SendText')

self.arduinoCmd.SetCommandAttribute('DeviceId','SerialDevice')

self.arduinoCmd.SetCommandTimeoutSec(1.0)

 

# Send command

self.arduinoCmd.SetCommandAttribute('Text', "ThisWillBeSentThroughSerialPort")

slicer.modules.openigtlinkremote.logic().SendCommand(self.arduinoCmd, self.connectorNode.GetID())

 

# Optional: Specify a callback function to get command status/response

self.arduinoCmd.AddObserver(self.arduinoCmd.CommandCompletedEvent, self.onArduinoCmdCompleted)

# Callback function

def onArduinoCmdCompleted(self, observer, eventid):

  print(self.arduinoCmd.GetStatus())

  print(self.arduinoCmd.GetResponseMessage())

  print(self.arduinoCmd.GetResponseText())

  print(self.arduinoCmd.GetResponseXML())

 

Andras

 

From: slicer-devel [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: March 26, 2017 23:48
To: SPL Slicer Devel <[hidden email]>
Subject: [slicer-devel] Access serial ports through slicer extension

 

Hello all,

 

I was wondering if there was a way to access serial ports using a scripted slicer extension? I would like to be able to interface slicer with an Arduino, but pyserial is not available in the slicer environment. Is it possible to include external python libraries?

 

Thanks,

 

Barrett


--

Barrett Anderies

B.S.E. Biomedical Engineering | B.S. Mathematics

Barrett, the Honors College | Arizona State University

Phone: <a href="tel:(480)%20721-9370" value="&#43;14807219370" target="_blank"> 480-721-9370

           [hidden email]



_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ