Xtralien Scientific Python: Communicating With The X100
You can communicate with the Xtralien X100 via either USB or Ethernet connections. This tutorial will show you how to use the Xtralien Scientific Python software to talk to your X100.
Manually Setting a COM Port
When an X100 is connected to a PC, it is assigned a specific 'COM' port. This can be found using the 'Plug In and Switch On' guide.
Once you know the correct COM port, you can connect to an X100 via the following command:
Device1 = X100.USB('COM1')
We name the connection
Device1, though this can be named anything you like. This example uses
COM1 as the port name.
In order to test this connection, we can send a simple command to the board:
Device1 = X100.USB('COM1') print(Device1.cloi.hello())
cloi hello command should return a 'Hello World' string if there is a working connection.
Automatically Setting a COM Port
serial_ports()function, which returns a list of open COM ports. As discussed in our list tutorial, using a
returns the first item in a list. This code will therefore return the first open COM port.
COM = serial_ports() Device1 = X100.USB(COM) print(Device1.cloi.hello())
Manually Setting An IP address
As with the USB connection, we need to find the board's address in order to connect to it. To determine the IP address of an X100, please use the 'Plug In and Switch On' guide.
Once you know what the address is, you can use the following code to connect:
Device1 = X100.Network('192.168.2.150') print(Device1.cloi.hello())
where '192.168.2.150' is an example address.
Automatically Setting An IP Address
As with the COM ports in the previous section, you can search for X100 IP addresses automatically. The
X100.discover() function searches the network for boards and returns their addresses in a list format. This can be used instead of the
Network() function to connect to a board like this:
Device1 = X100.discover() print(Device1.cloi.hello())
Here we use the first address in the list by using
If a board becomes disconnected, the program will error and the COM port will not close as it should. To solve this problem, we use the
#For USB COM=serial_ports() with X100.USB(COM) as Device1: print(Device1.cloi.hello())
#For Ethernet with X100.discover() as Device1: print(Device1.cloi.hello())
Notice that the
with. The indented code will run until it completes, or the connection is lost. The program will then close the connection and continue running.