Open a USB stream in julia - julia

How does one open up a stream to a USB port using Julia?
I would like to do something like:
stream = open(bus=6, device=2)
or
stream = open(id="1d6b:0002")
Thank you

Related

Bluez BLE Connections Monitoring using DBUS-Python

I was able to advertise the BLE and setup GATT Services and Characteristics by following the "example_advertisement" and "example-gatt-server" in Bluez Examples. How can I know from DBUS when a BLE client is connected and when it is disconnected, using similar DBUS binding for Python? Which DBUS API do I look into?
There is another example that you can look at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-discovery
When BlueZ/DBus learns of a new remote device, then the InterfacesAdded signal gets sent.
When a remote device goes from disconnected, to connected. Then that is a property change on the device and the PropertiesChanged signal gets sent.
This is why there is the code in the above example they use add_signal_receiver to add callbacks for both signals.
bus.add_signal_receiver(interfaces_added,
dbus_interface = "org.freedesktop.DBus.ObjectManager",
signal_name = "InterfacesAdded")
bus.add_signal_receiver(properties_changed,
dbus_interface = "org.freedesktop.DBus.Properties",
signal_name = "PropertiesChanged",
arg0 = "org.bluez.Device1",
path_keyword = "path")
As a side note, the DBus bindings used in the Buez examples are not the only ones available:
https://www.freedesktop.org/wiki/Software/DBusBindings/

detect end of file in pyserial python3

I have been searching this, but couldn't get a good answer.
i have to send a file through COM port between two PC.
but i dont know how to detect the end of file.
In PC 1 i use teraTerm software to send file.
In PC 2 is use the following python code.
After the file is sent i need to put some message that the file is complete.
import serial
ser = serial.Serial('COM1')
ser.flush_input_buffer()
file = open('file.txt','a') #open empty file for appending
while True:
receivedByte = ser.read() # read 1 byte
file.write(receivedByte)
if (#detect end of file ):
break
print('file received')
Please note : PC is windows 8.1, Pyserial, Python 3.4
Please also suggest for Linux file
There is no EOF for a serial port as such. And what I can gather from the Internet teraTerm doesn't have a protocol for sending files, but just sends them in their raw form.
You could maybe set the read timeout for the serial port, so that the read would raise a SerialTimeoutException when there is no data left.
I tried this solution, although it is not as elegant and rather simple. It does work.
receivedByte = ser.read() # read 1 byte
while receivedByte != b'':
file.write(receivedByte)
receivedByte = ser.read()
print('file received')

Arduino and Processing (PDE) via Ethernet

Arduino: Is it possible to communicate with Arduino through Ethernet, using a Processing (PDE) script?
I've already created a desktop application using Processing, but in this case I communicate with Arduino through the USB.
Yes you can
You could for example create an arduino chat server : http://arduino.cc/en/Tutorial/ChatServer
And create a processing client like this : http://processing.org/reference/libraries/net/Client_write_.html
ofcourse you would need to change the
myClient = new Client(this, "127.0.0.1", 10002);
to
myClient = new Client(this, "IP of Arduino", 23);
If you would then connect with a telnet session to the arduin o you would see output from the prosessing script comming back from the arduino

USB to Serial emulation

I bought this magnetic strip reader writer (MSRE106) and I use USB adapter to connect it to my laptop because I have no serial port in my computer. But now I have a problem since the software of the device recognizes only serial ports on windows. After looking up I found someone that wrote a python script for Linux (found here The Script).
Still even in this python script in the settings file it has this variable
## Com port.
COM = "COM1"
How can I change this to be one of my USB ports instead of a serial one because I have none
This script is made to use serial port as well, which means you can't just modify COM="USB1" or whatever to use your USB adapter. If you have a look at line 264 a serial port is open using function SerialPort().
To fix this issue you must install your USB adapter's driver that will emulate a serial port and create a fake COM1 you can use with this script or the original software of the MSRE106.

Porting a TCP Twisted app to the serial port

I've been using Twisted for a while to connect a computer with some devices over the net. I wrote a custom Protocol and Factory.
factory = TModBusFactory()
reactor.listenTCP(9007, factory)
Now I'd like to connect the devices to the serial port of the server machine. As long as I know, no change in the protocol is needed but I need to switch from sending bytes over TCP to send them over the serial port.
How hard to do is this change? How can I change the code snippet in order to make it work?
Thanks!
Serial port setup looks like this:
from twisted.internet.serialport import SerialPort
from twisted.internet import reactor
factory = TModBusFactory()
protocol = factory.buildProtocol(None)
deviceName = "ttyS0"
port = SerialPort(protocol, deviceName, reactor)

Resources